From 0bddfe1d9d737dfbd5c818ac32d79f578129d5d8 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Tue, 17 Jan 2023 20:18:56 -0500 Subject: fix(commands): create env.Env once for all Cobra commands Resolves #996 --- commands/user/user.go | 9 ++++----- commands/user/user_adopt.go | 4 +--- commands/user/user_new.go | 4 +--- commands/user/user_show.go | 3 +-- 4 files changed, 7 insertions(+), 13 deletions(-) (limited to 'commands/user') diff --git a/commands/user/user.go b/commands/user/user.go index a9a45726..de5c1ccd 100644 --- a/commands/user/user.go +++ b/commands/user/user.go @@ -16,8 +16,7 @@ type userOptions struct { format string } -func NewUserCommand() *cobra.Command { - env := execenv.NewEnv() +func NewUserCommand(env *execenv.Env) *cobra.Command { options := userOptions{} cmd := &cobra.Command{ @@ -29,9 +28,9 @@ func NewUserCommand() *cobra.Command { }), } - cmd.AddCommand(newUserNewCommand()) - cmd.AddCommand(newUserShowCommand()) - cmd.AddCommand(newUserAdoptCommand()) + cmd.AddCommand(newUserNewCommand(env)) + cmd.AddCommand(newUserShowCommand(env)) + cmd.AddCommand(newUserAdoptCommand(env)) flags := cmd.Flags() flags.SortFlags = false diff --git a/commands/user/user_adopt.go b/commands/user/user_adopt.go index 30fdb442..47f0f04e 100644 --- a/commands/user/user_adopt.go +++ b/commands/user/user_adopt.go @@ -7,9 +7,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newUserAdoptCommand() *cobra.Command { - env := execenv.NewEnv() - +func newUserAdoptCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "adopt USER_ID", Short: "Adopt an existing identity as your own", diff --git a/commands/user/user_new.go b/commands/user/user_new.go index 7b287492..ba4198f8 100644 --- a/commands/user/user_new.go +++ b/commands/user/user_new.go @@ -14,9 +14,7 @@ type userNewOptions struct { nonInteractive bool } -func newUserNewCommand() *cobra.Command { - env := execenv.NewEnv() - +func newUserNewCommand(env *execenv.Env) *cobra.Command { options := userNewOptions{} cmd := &cobra.Command{ Use: "new", diff --git a/commands/user/user_show.go b/commands/user/user_show.go index 225d0ef4..049eee93 100644 --- a/commands/user/user_show.go +++ b/commands/user/user_show.go @@ -16,8 +16,7 @@ type userShowOptions struct { fields string } -func newUserShowCommand() *cobra.Command { - env := execenv.NewEnv() +func newUserShowCommand(env *execenv.Env) *cobra.Command { options := userShowOptions{} cmd := &cobra.Command{ -- cgit