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/bridge/bridge.go | 14 ++++++-------- commands/bridge/bridge_auth.go | 10 ++++------ commands/bridge/bridge_auth_addtoken.go | 3 +-- commands/bridge/bridge_auth_rm.go | 4 +--- commands/bridge/bridge_auth_show.go | 4 +--- commands/bridge/bridge_new.go | 3 +-- commands/bridge/bridge_pull.go | 3 +-- commands/bridge/bridge_push.go | 4 +--- commands/bridge/bridge_rm.go | 4 +--- 9 files changed, 17 insertions(+), 32 deletions(-) (limited to 'commands/bridge') diff --git a/commands/bridge/bridge.go b/commands/bridge/bridge.go index 980a38e2..9f7c5e50 100644 --- a/commands/bridge/bridge.go +++ b/commands/bridge/bridge.go @@ -7,9 +7,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func NewBridgeCommand() *cobra.Command { - env := execenv.NewEnv() - +func NewBridgeCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "bridge", Short: "List bridges to other bug trackers", @@ -20,11 +18,11 @@ func NewBridgeCommand() *cobra.Command { Args: cobra.NoArgs, } - cmd.AddCommand(newBridgeAuthCommand()) - cmd.AddCommand(newBridgeNewCommand()) - cmd.AddCommand(newBridgePullCommand()) - cmd.AddCommand(newBridgePushCommand()) - cmd.AddCommand(newBridgeRm()) + cmd.AddCommand(newBridgeAuthCommand(env)) + cmd.AddCommand(newBridgeNewCommand(env)) + cmd.AddCommand(newBridgePullCommand(env)) + cmd.AddCommand(newBridgePushCommand(env)) + cmd.AddCommand(newBridgeRm(env)) return cmd } diff --git a/commands/bridge/bridge_auth.go b/commands/bridge/bridge_auth.go index 52e063e6..f27004e0 100644 --- a/commands/bridge/bridge_auth.go +++ b/commands/bridge/bridge_auth.go @@ -12,9 +12,7 @@ import ( "github.com/MichaelMure/git-bug/util/colors" ) -func newBridgeAuthCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBridgeAuthCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "auth", Short: "List all known bridge authentication credentials", @@ -25,9 +23,9 @@ func newBridgeAuthCommand() *cobra.Command { Args: cobra.NoArgs, } - cmd.AddCommand(newBridgeAuthAddTokenCommand()) - cmd.AddCommand(newBridgeAuthRm()) - cmd.AddCommand(newBridgeAuthShow()) + cmd.AddCommand(newBridgeAuthAddTokenCommand(env)) + cmd.AddCommand(newBridgeAuthRm(env)) + cmd.AddCommand(newBridgeAuthShow(env)) return cmd } diff --git a/commands/bridge/bridge_auth_addtoken.go b/commands/bridge/bridge_auth_addtoken.go index 2992fa63..5af27728 100644 --- a/commands/bridge/bridge_auth_addtoken.go +++ b/commands/bridge/bridge_auth_addtoken.go @@ -24,8 +24,7 @@ type bridgeAuthAddTokenOptions struct { user string } -func newBridgeAuthAddTokenCommand() *cobra.Command { - env := execenv.NewEnv() +func newBridgeAuthAddTokenCommand(env *execenv.Env) *cobra.Command { options := bridgeAuthAddTokenOptions{} cmd := &cobra.Command{ diff --git a/commands/bridge/bridge_auth_rm.go b/commands/bridge/bridge_auth_rm.go index d58ca63e..33253e26 100644 --- a/commands/bridge/bridge_auth_rm.go +++ b/commands/bridge/bridge_auth_rm.go @@ -8,9 +8,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBridgeAuthRm() *cobra.Command { - env := execenv.NewEnv() - +func newBridgeAuthRm(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "rm BRIDGE_ID", Short: "Remove a credential", diff --git a/commands/bridge/bridge_auth_show.go b/commands/bridge/bridge_auth_show.go index d373273d..25c517d3 100644 --- a/commands/bridge/bridge_auth_show.go +++ b/commands/bridge/bridge_auth_show.go @@ -13,9 +13,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBridgeAuthShow() *cobra.Command { - env := execenv.NewEnv() - +func newBridgeAuthShow(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "show", Short: "Display an authentication credential", diff --git a/commands/bridge/bridge_new.go b/commands/bridge/bridge_new.go index 2c51d9ef..07a555da 100644 --- a/commands/bridge/bridge_new.go +++ b/commands/bridge/bridge_new.go @@ -26,8 +26,7 @@ type bridgeNewOptions struct { nonInteractive bool } -func newBridgeNewCommand() *cobra.Command { - env := execenv.NewEnv() +func newBridgeNewCommand(env *execenv.Env) *cobra.Command { options := bridgeNewOptions{} cmd := &cobra.Command{ diff --git a/commands/bridge/bridge_pull.go b/commands/bridge/bridge_pull.go index d1fc279a..03f4929a 100644 --- a/commands/bridge/bridge_pull.go +++ b/commands/bridge/bridge_pull.go @@ -23,8 +23,7 @@ type bridgePullOptions struct { noResume bool } -func newBridgePullCommand() *cobra.Command { - env := execenv.NewEnv() +func newBridgePullCommand(env *execenv.Env) *cobra.Command { options := bridgePullOptions{} cmd := &cobra.Command{ diff --git a/commands/bridge/bridge_push.go b/commands/bridge/bridge_push.go index 51baed4d..08f9b872 100644 --- a/commands/bridge/bridge_push.go +++ b/commands/bridge/bridge_push.go @@ -15,9 +15,7 @@ import ( "github.com/MichaelMure/git-bug/util/interrupt" ) -func newBridgePushCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBridgePushCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "push [NAME]", Short: "Push updates to remote bug tracker", diff --git a/commands/bridge/bridge_rm.go b/commands/bridge/bridge_rm.go index 5d8d23c5..f6279ade 100644 --- a/commands/bridge/bridge_rm.go +++ b/commands/bridge/bridge_rm.go @@ -8,9 +8,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBridgeRm() *cobra.Command { - env := execenv.NewEnv() - +func newBridgeRm(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "rm NAME", Short: "Delete a configured bridge", -- cgit