aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bridge_auth_rm.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_rm.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/bridge_auth_rm.go')
-rw-r--r--commands/bridge_auth_rm.go38
1 files changed, 20 insertions, 18 deletions
diff --git a/commands/bridge_auth_rm.go b/commands/bridge_auth_rm.go
index 17e70625..b2a44e92 100644
--- a/commands/bridge_auth_rm.go
+++ b/commands/bridge_auth_rm.go
@@ -1,36 +1,38 @@
package commands
import (
- "fmt"
-
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/bridge/core/auth"
)
-func runBridgeAuthRm(cmd *cobra.Command, args []string) error {
- cred, err := auth.LoadWithPrefix(repo, args[0])
+func newBridgeAuthRm() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "rm <id>",
+ Short: "Remove a credential.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runBridgeAuthRm(env, args)
+ },
+ Args: cobra.ExactArgs(1),
+ }
+
+ return cmd
+}
+
+func runBridgeAuthRm(env *Env, args []string) error {
+ cred, err := auth.LoadWithPrefix(env.repo, args[0])
if err != nil {
return err
}
- err = auth.Remove(repo, cred.ID())
+ err = auth.Remove(env.repo, cred.ID())
if err != nil {
return err
}
- fmt.Printf("credential %s removed\n", cred.ID())
+ env.out.Printf("credential %s removed\n", cred.ID())
return nil
}
-
-var bridgeAuthRmCmd = &cobra.Command{
- Use: "rm <id>",
- Short: "Remove a credential.",
- PreRunE: loadRepo,
- RunE: runBridgeAuthRm,
- Args: cobra.ExactArgs(1),
-}
-
-func init() {
- bridgeAuthCmd.AddCommand(bridgeAuthRmCmd)
-}