From 26bd1dd11010b4d86cebe2510ad7085a6b316334 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 28 Jun 2020 18:26:29 +0200 Subject: commands: refactor to avoid globals --- commands/user_adopt.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'commands/user_adopt.go') diff --git a/commands/user_adopt.go b/commands/user_adopt.go index 7054f1f7..0eb8b467 100644 --- a/commands/user_adopt.go +++ b/commands/user_adopt.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/util/interrupt" ) -func runUserAdopt(cmd *cobra.Command, args []string) error { - backend, err := cache.NewRepoCache(repo) +func newUserAdoptCommand() *cobra.Command { + env := newEnv() + + cmd := &cobra.Command{ + Use: "adopt ", + Short: "Adopt an existing identity as your own.", + Args: cobra.ExactArgs(1), + PreRunE: loadRepo(env), + RunE: func(cmd *cobra.Command, args []string) error { + return runUserAdopt(env, args) + }, + } + + return cmd +} + +func runUserAdopt(env *Env, args []string) error { + backend, err := cache.NewRepoCache(env.repo) if err != nil { return err } @@ -30,20 +43,7 @@ func runUserAdopt(cmd *cobra.Command, args []string) error { return err } - _, _ = fmt.Fprintf(os.Stderr, "Your identity is now: %s\n", i.DisplayName()) + env.out.Printf("Your identity is now: %s\n", i.DisplayName()) return nil } - -var userAdoptCmd = &cobra.Command{ - Use: "adopt ", - Short: "Adopt an existing identity as your own.", - PreRunE: loadRepo, - RunE: runUserAdopt, - Args: cobra.ExactArgs(1), -} - -func init() { - userCmd.AddCommand(userAdoptCmd) - userAdoptCmd.Flags().SortFlags = false -} -- cgit