aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bridge_auth.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.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/bridge_auth.go')
-rw-r--r--commands/bridge_auth.go40
1 files changed, 23 insertions, 17 deletions
diff --git a/commands/bridge_auth.go b/commands/bridge_auth.go
index 3a0e0c29..e51b9b9d 100644
--- a/commands/bridge_auth.go
+++ b/commands/bridge_auth.go
@@ -1,7 +1,6 @@
package commands
import (
- "fmt"
"sort"
"strings"
@@ -15,8 +14,28 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
-func runBridgeAuth(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newBridgeAuthCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "auth",
+ Short: "List all known bridge authentication credentials.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runBridgeAuth(env)
+ },
+ Args: cobra.NoArgs,
+ }
+
+ cmd.AddCommand(newBridgeAuthAddTokenCommand())
+ cmd.AddCommand(newBridgeAuthRm())
+ cmd.AddCommand(newBridgeAuthShow())
+
+ return cmd
+}
+
+func runBridgeAuth(env *Env) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -44,7 +63,7 @@ func runBridgeAuth(cmd *cobra.Command, args []string) error {
sort.Strings(meta)
metaFmt := strings.Join(meta, ",")
- fmt.Printf("%s %s %s %s %s\n",
+ env.out.Printf("%s %s %s %s %s\n",
colors.Cyan(cred.ID().Human()),
colors.Yellow(targetFmt),
colors.Magenta(cred.Kind()),
@@ -55,16 +74,3 @@ func runBridgeAuth(cmd *cobra.Command, args []string) error {
return nil
}
-
-var bridgeAuthCmd = &cobra.Command{
- Use: "auth",
- Short: "List all known bridge authentication credentials.",
- PreRunE: loadRepo,
- RunE: runBridgeAuth,
- Args: cobra.NoArgs,
-}
-
-func init() {
- bridgeCmd.AddCommand(bridgeAuthCmd)
- bridgeAuthCmd.Flags().SortFlags = false
-}