aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bridge_auth_show.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
commit26bd1dd11010b4d86cebe2510ad7085a6b316334 (patch)
treef1fe939311c75bd615071e96f3d37822cccd77a7 /commands/bridge_auth_show.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/bridge_auth_show.go')
-rw-r--r--commands/bridge_auth_show.go48
1 files changed, 26 insertions, 22 deletions
diff --git a/commands/bridge_auth_show.go b/commands/bridge_auth_show.go
index fbbf60a7..f8b15c9a 100644
--- a/commands/bridge_auth_show.go
+++ b/commands/bridge_auth_show.go
@@ -13,30 +13,46 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
-func runBridgeAuthShow(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newBridgeAuthShow() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "show",
+ Short: "Display an authentication credential.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runBridgeAuthShow(env, args)
+ },
+ Args: cobra.ExactArgs(1),
+ }
+
+ return cmd
+}
+
+func runBridgeAuthShow(env *Env, args []string) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
defer backend.Close()
interrupt.RegisterCleaner(backend.Close)
- cred, err := auth.LoadWithPrefix(repo, args[0])
+ cred, err := auth.LoadWithPrefix(env.repo, args[0])
if err != nil {
return err
}
- fmt.Printf("Id: %s\n", cred.ID())
- fmt.Printf("Target: %s\n", cred.Target())
- fmt.Printf("Kind: %s\n", cred.Kind())
- fmt.Printf("Creation: %s\n", cred.CreateTime().Format(time.RFC822))
+ env.out.Printf("Id: %s\n", cred.ID())
+ env.out.Printf("Target: %s\n", cred.Target())
+ env.out.Printf("Kind: %s\n", cred.Kind())
+ env.out.Printf("Creation: %s\n", cred.CreateTime().Format(time.RFC822))
switch cred := cred.(type) {
case *auth.Token:
- fmt.Printf("Value: %s\n", cred.Value)
+ env.out.Printf("Value: %s\n", cred.Value)
}
- fmt.Println("Metadata:")
+ env.out.Println("Metadata:")
meta := make([]string, 0, len(cred.Metadata()))
for key, value := range cred.Metadata() {
@@ -44,19 +60,7 @@ func runBridgeAuthShow(cmd *cobra.Command, args []string) error {
}
sort.Strings(meta)
- fmt.Print(strings.Join(meta, ""))
+ env.out.Print(strings.Join(meta, ""))
return nil
}
-
-var bridgeAuthShowCmd = &cobra.Command{
- Use: "show",
- Short: "Display an authentication credential.",
- PreRunE: loadRepo,
- RunE: runBridgeAuthShow,
- Args: cobra.ExactArgs(1),
-}
-
-func init() {
- bridgeAuthCmd.AddCommand(bridgeAuthShowCmd)
-}