aboutsummaryrefslogtreecommitdiffstats
path: root/commands/user_create.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/user_create.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/user_create.go')
-rw-r--r--commands/user_create.go39
1 files changed, 20 insertions, 19 deletions
diff --git a/commands/user_create.go b/commands/user_create.go
index df4aa8e9..6433d38e 100644
--- a/commands/user_create.go
+++ b/commands/user_create.go
@@ -1,17 +1,30 @@
package commands
import (
- "fmt"
- "os"
+ "github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/input"
"github.com/MichaelMure/git-bug/util/interrupt"
- "github.com/spf13/cobra"
)
-func runUserCreate(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newUserCreateCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "create",
+ Short: "Create a new identity.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runUserCreate(env)
+ },
+ }
+
+ return cmd
+}
+
+func runUserCreate(env *Env) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -65,20 +78,8 @@ func runUserCreate(cmd *cobra.Command, args []string) error {
}
}
- _, _ = fmt.Fprintln(os.Stderr)
- fmt.Println(id.Id())
+ env.err.Println()
+ env.out.Println(id.Id())
return nil
}
-
-var userCreateCmd = &cobra.Command{
- Use: "create",
- Short: "Create a new identity.",
- PreRunE: loadRepo,
- RunE: runUserCreate,
-}
-
-func init() {
- userCmd.AddCommand(userCreateCmd)
- userCreateCmd.Flags().SortFlags = false
-}