aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bridge_auth_show.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/bridge_auth_show.go')
-rw-r--r--commands/bridge_auth_show.go52
1 files changed, 24 insertions, 28 deletions
diff --git a/commands/bridge_auth_show.go b/commands/bridge_auth_show.go
index fbbf60a7..408a6cf1 100644
--- a/commands/bridge_auth_show.go
+++ b/commands/bridge_auth_show.go
@@ -9,34 +9,42 @@ import (
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/bridge/core/auth"
- "github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/util/interrupt"
)
-func runBridgeAuthShow(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
- if err != nil {
- return err
+func newBridgeAuthShow() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "show",
+ Short: "Display an authentication credential.",
+ PreRunE: loadBackend(env),
+ PostRunE: closeBackend(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runBridgeAuthShow(env, args)
+ },
+ Args: cobra.ExactArgs(1),
}
- defer backend.Close()
- interrupt.RegisterCleaner(backend.Close)
- cred, err := auth.LoadWithPrefix(repo, args[0])
+ return cmd
+}
+
+func runBridgeAuthShow(env *Env, args []string) error {
+ 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 +52,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)
-}