From 0bddfe1d9d737dfbd5c818ac32d79f578129d5d8 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Tue, 17 Jan 2023 20:18:56 -0500 Subject: [PATCH 1/2] 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 +--- commands/bug/bug.go | 21 +++++++++-------- commands/bug/bug_comment.go | 8 +++---- commands/bug/bug_comment_add.go | 3 +-- commands/bug/bug_comment_edit.go | 3 +-- commands/bug/bug_deselect.go | 4 +--- commands/bug/bug_label.go | 8 +++---- commands/bug/bug_label_new.go | 4 +--- commands/bug/bug_label_rm.go | 4 +--- commands/bug/bug_new.go | 3 +-- commands/bug/bug_rm.go | 4 +--- commands/bug/bug_select.go | 4 +--- commands/bug/bug_show.go | 3 +-- commands/bug/bug_status.go | 8 +++---- commands/bug/bug_status_close.go | 4 +--- commands/bug/bug_status_open.go | 4 +--- commands/bug/bug_title.go | 6 ++--- commands/bug/bug_title_edit.go | 3 +-- commands/commands.go | 3 +-- commands/label.go | 4 +--- commands/pull.go | 4 +--- commands/push.go | 4 +--- commands/root.go | 30 +++++++++++++------------ commands/termui.go | 4 +--- commands/user/user.go | 9 ++++---- commands/user/user_adopt.go | 4 +--- commands/user/user_new.go | 4 +--- commands/user/user_show.go | 3 +-- commands/version.go | 3 +-- commands/webui.go | 3 +-- commands/wipe.go | 4 +--- 39 files changed, 81 insertions(+), 141 deletions(-) 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", diff --git a/commands/bug/bug.go b/commands/bug/bug.go index a5ce11ed..7004f5c1 100644 --- a/commands/bug/bug.go +++ b/commands/bug/bug.go @@ -33,8 +33,7 @@ type bugOptions struct { outputFormat string } -func NewBugCommand() *cobra.Command { - env := execenv.NewEnv() +func NewBugCommand(env *execenv.Env) *cobra.Command { options := bugOptions{} cmd := &cobra.Command{ @@ -106,16 +105,16 @@ git bug status:open --by creation "foo bar" baz child.GroupID = groupID } - addCmdWithGroup(newBugDeselectCommand(), selectGroup) - addCmdWithGroup(newBugSelectCommand(), selectGroup) + addCmdWithGroup(newBugDeselectCommand(env), selectGroup) + addCmdWithGroup(newBugSelectCommand(env), selectGroup) - cmd.AddCommand(newBugCommentCommand()) - cmd.AddCommand(newBugLabelCommand()) - cmd.AddCommand(newBugNewCommand()) - cmd.AddCommand(newBugRmCommand()) - cmd.AddCommand(newBugShowCommand()) - cmd.AddCommand(newBugStatusCommand()) - cmd.AddCommand(newBugTitleCommand()) + cmd.AddCommand(newBugCommentCommand(env)) + cmd.AddCommand(newBugLabelCommand(env)) + cmd.AddCommand(newBugNewCommand(env)) + cmd.AddCommand(newBugRmCommand(env)) + cmd.AddCommand(newBugShowCommand(env)) + cmd.AddCommand(newBugStatusCommand(env)) + cmd.AddCommand(newBugTitleCommand(env)) return cmd } diff --git a/commands/bug/bug_comment.go b/commands/bug/bug_comment.go index 4dc8dc1f..5cb8ff17 100644 --- a/commands/bug/bug_comment.go +++ b/commands/bug/bug_comment.go @@ -8,9 +8,7 @@ import ( "github.com/MichaelMure/git-bug/util/colors" ) -func newBugCommentCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugCommentCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "comment [BUG_ID]", Short: "List a bug's comments", @@ -21,8 +19,8 @@ func newBugCommentCommand() *cobra.Command { ValidArgsFunction: BugCompletion(env), } - cmd.AddCommand(newBugCommentNewCommand()) - cmd.AddCommand(newBugCommentEditCommand()) + cmd.AddCommand(newBugCommentNewCommand(env)) + cmd.AddCommand(newBugCommentEditCommand(env)) return cmd } diff --git a/commands/bug/bug_comment_add.go b/commands/bug/bug_comment_add.go index ff406b4f..152a1893 100644 --- a/commands/bug/bug_comment_add.go +++ b/commands/bug/bug_comment_add.go @@ -14,8 +14,7 @@ type bugCommentNewOptions struct { nonInteractive bool } -func newBugCommentNewCommand() *cobra.Command { - env := execenv.NewEnv() +func newBugCommentNewCommand(env *execenv.Env) *cobra.Command { options := bugCommentNewOptions{} cmd := &cobra.Command{ diff --git a/commands/bug/bug_comment_edit.go b/commands/bug/bug_comment_edit.go index ded3d82a..e6f8d667 100644 --- a/commands/bug/bug_comment_edit.go +++ b/commands/bug/bug_comment_edit.go @@ -13,8 +13,7 @@ type bugCommentEditOptions struct { nonInteractive bool } -func newBugCommentEditCommand() *cobra.Command { - env := execenv.NewEnv() +func newBugCommentEditCommand(env *execenv.Env) *cobra.Command { options := bugCommentEditOptions{} cmd := &cobra.Command{ diff --git a/commands/bug/bug_deselect.go b/commands/bug/bug_deselect.go index 090a7bf2..5e9acc60 100644 --- a/commands/bug/bug_deselect.go +++ b/commands/bug/bug_deselect.go @@ -8,9 +8,7 @@ import ( "github.com/MichaelMure/git-bug/entities/bug" ) -func newBugDeselectCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugDeselectCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "deselect", Short: "Clear the implicitly selected bug", diff --git a/commands/bug/bug_label.go b/commands/bug/bug_label.go index e6d0e603..554496e3 100644 --- a/commands/bug/bug_label.go +++ b/commands/bug/bug_label.go @@ -6,9 +6,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBugLabelCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugLabelCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "label [BUG_ID]", Short: "Display labels of a bug", @@ -19,8 +17,8 @@ func newBugLabelCommand() *cobra.Command { ValidArgsFunction: BugCompletion(env), } - cmd.AddCommand(newBugLabelNewCommand()) - cmd.AddCommand(newBugLabelRmCommand()) + cmd.AddCommand(newBugLabelNewCommand(env)) + cmd.AddCommand(newBugLabelRmCommand(env)) return cmd } diff --git a/commands/bug/bug_label_new.go b/commands/bug/bug_label_new.go index aa4f9463..1e1f2d4f 100644 --- a/commands/bug/bug_label_new.go +++ b/commands/bug/bug_label_new.go @@ -7,9 +7,7 @@ import ( "github.com/MichaelMure/git-bug/util/text" ) -func newBugLabelNewCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugLabelNewCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "new [BUG_ID] LABEL...", Short: "Add a label to a bug", diff --git a/commands/bug/bug_label_rm.go b/commands/bug/bug_label_rm.go index 18510bbd..6dda007c 100644 --- a/commands/bug/bug_label_rm.go +++ b/commands/bug/bug_label_rm.go @@ -7,9 +7,7 @@ import ( "github.com/MichaelMure/git-bug/util/text" ) -func newBugLabelRmCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugLabelRmCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "rm [BUG_ID] LABEL...", Short: "Remove a label from a bug", diff --git a/commands/bug/bug_new.go b/commands/bug/bug_new.go index 9ef288e9..e66967f9 100644 --- a/commands/bug/bug_new.go +++ b/commands/bug/bug_new.go @@ -15,8 +15,7 @@ type bugNewOptions struct { nonInteractive bool } -func newBugNewCommand() *cobra.Command { - env := execenv.NewEnv() +func newBugNewCommand(env *execenv.Env) *cobra.Command { options := bugNewOptions{} cmd := &cobra.Command{ diff --git a/commands/bug/bug_rm.go b/commands/bug/bug_rm.go index 386c57ec..b9d3d525 100644 --- a/commands/bug/bug_rm.go +++ b/commands/bug/bug_rm.go @@ -8,9 +8,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBugRmCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugRmCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "rm BUG_ID", Short: "Remove an existing bug", diff --git a/commands/bug/bug_select.go b/commands/bug/bug_select.go index bfad899d..652c61ea 100644 --- a/commands/bug/bug_select.go +++ b/commands/bug/bug_select.go @@ -15,9 +15,7 @@ func ResolveSelected(repo *cache.RepoCache, args []string) (*cache.BugCache, []s return _select.Resolve[*cache.BugCache](repo, bug.Typename, bug.Namespace, repo.Bugs(), args) } -func newBugSelectCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugSelectCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "select BUG_ID", Short: "Select a bug for implicit use in future commands", diff --git a/commands/bug/bug_show.go b/commands/bug/bug_show.go index 9f80120c..9a03c9a3 100644 --- a/commands/bug/bug_show.go +++ b/commands/bug/bug_show.go @@ -19,8 +19,7 @@ type bugShowOptions struct { format string } -func newBugShowCommand() *cobra.Command { - env := execenv.NewEnv() +func newBugShowCommand(env *execenv.Env) *cobra.Command { options := bugShowOptions{} cmd := &cobra.Command{ diff --git a/commands/bug/bug_status.go b/commands/bug/bug_status.go index 807a9a60..59bef3fd 100644 --- a/commands/bug/bug_status.go +++ b/commands/bug/bug_status.go @@ -6,9 +6,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBugStatusCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugStatusCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "status [BUG_ID]", Short: "Display the status of a bug", @@ -19,8 +17,8 @@ func newBugStatusCommand() *cobra.Command { ValidArgsFunction: BugCompletion(env), } - cmd.AddCommand(newBugStatusCloseCommand()) - cmd.AddCommand(newBugStatusOpenCommand()) + cmd.AddCommand(newBugStatusCloseCommand(env)) + cmd.AddCommand(newBugStatusOpenCommand(env)) return cmd } diff --git a/commands/bug/bug_status_close.go b/commands/bug/bug_status_close.go index e52959b2..1d06007b 100644 --- a/commands/bug/bug_status_close.go +++ b/commands/bug/bug_status_close.go @@ -6,9 +6,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBugStatusCloseCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugStatusCloseCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "close [BUG_ID]", Short: "Mark a bug as closed", diff --git a/commands/bug/bug_status_open.go b/commands/bug/bug_status_open.go index 74177974..e99d2db0 100644 --- a/commands/bug/bug_status_open.go +++ b/commands/bug/bug_status_open.go @@ -6,9 +6,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBugStatusOpenCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugStatusOpenCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "open [BUG_ID]", Short: "Mark a bug as open", diff --git a/commands/bug/bug_title.go b/commands/bug/bug_title.go index e59a1fdc..47603410 100644 --- a/commands/bug/bug_title.go +++ b/commands/bug/bug_title.go @@ -6,9 +6,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newBugTitleCommand() *cobra.Command { - env := execenv.NewEnv() - +func newBugTitleCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "title [BUG_ID]", Short: "Display the title of a bug", @@ -19,7 +17,7 @@ func newBugTitleCommand() *cobra.Command { ValidArgsFunction: BugCompletion(env), } - cmd.AddCommand(newBugTitleEditCommand()) + cmd.AddCommand(newBugTitleEditCommand(env)) return cmd } diff --git a/commands/bug/bug_title_edit.go b/commands/bug/bug_title_edit.go index 59898530..fc60824f 100644 --- a/commands/bug/bug_title_edit.go +++ b/commands/bug/bug_title_edit.go @@ -13,8 +13,7 @@ type bugTitleEditOptions struct { nonInteractive bool } -func newBugTitleEditCommand() *cobra.Command { - env := execenv.NewEnv() +func newBugTitleEditCommand(env *execenv.Env) *cobra.Command { options := bugTitleEditOptions{} cmd := &cobra.Command{ diff --git a/commands/commands.go b/commands/commands.go index 7d2fc37d..173a0904 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -12,8 +12,7 @@ type commandOptions struct { desc bool } -func newCommandsCommand() *cobra.Command { - env := execenv.NewEnv() +func newCommandsCommand(env *execenv.Env) *cobra.Command { options := commandOptions{} cmd := &cobra.Command{ diff --git a/commands/label.go b/commands/label.go index 08b9e31f..d59479b4 100644 --- a/commands/label.go +++ b/commands/label.go @@ -6,9 +6,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newLabelCommand() *cobra.Command { - env := execenv.NewEnv() - +func newLabelCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "label", Short: "List valid labels", diff --git a/commands/pull.go b/commands/pull.go index 2e2639e1..91eadcf8 100644 --- a/commands/pull.go +++ b/commands/pull.go @@ -10,9 +10,7 @@ import ( "github.com/MichaelMure/git-bug/entity" ) -func newPullCommand() *cobra.Command { - env := execenv.NewEnv() - +func newPullCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "pull [REMOTE]", Short: "Pull updates from a git remote", diff --git a/commands/push.go b/commands/push.go index d45e301a..254bbb27 100644 --- a/commands/push.go +++ b/commands/push.go @@ -9,9 +9,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newPushCommand() *cobra.Command { - env := execenv.NewEnv() - +func newPushCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "push [REMOTE]", Short: "Push updates to a git remote", diff --git a/commands/root.go b/commands/root.go index 0c854739..aace1956 100644 --- a/commands/root.go +++ b/commands/root.go @@ -7,10 +7,10 @@ import ( "github.com/spf13/cobra" - "github.com/MichaelMure/git-bug/commands/bridge" - "github.com/MichaelMure/git-bug/commands/bug" + bridgecmd "github.com/MichaelMure/git-bug/commands/bridge" + bugcmd "github.com/MichaelMure/git-bug/commands/bug" "github.com/MichaelMure/git-bug/commands/execenv" - "github.com/MichaelMure/git-bug/commands/user" + usercmd "github.com/MichaelMure/git-bug/commands/user" ) // These variables are initialized externally during the build. See the Makefile. @@ -68,20 +68,22 @@ the same git remote you are already using to collaborate with other people. child.GroupID = groupID } - addCmdWithGroup(bugcmd.NewBugCommand(), entityGroup) - addCmdWithGroup(usercmd.NewUserCommand(), entityGroup) - addCmdWithGroup(newLabelCommand(), entityGroup) + env := execenv.NewEnv() - addCmdWithGroup(newTermUICommand(), uiGroup) - addCmdWithGroup(newWebUICommand(), uiGroup) + addCmdWithGroup(bugcmd.NewBugCommand(env), entityGroup) + addCmdWithGroup(usercmd.NewUserCommand(env), entityGroup) + addCmdWithGroup(newLabelCommand(env), entityGroup) - addCmdWithGroup(newPullCommand(), remoteGroup) - addCmdWithGroup(newPushCommand(), remoteGroup) - addCmdWithGroup(bridgecmd.NewBridgeCommand(), remoteGroup) + addCmdWithGroup(newTermUICommand(env), uiGroup) + addCmdWithGroup(newWebUICommand(env), uiGroup) - cmd.AddCommand(newCommandsCommand()) - cmd.AddCommand(newVersionCommand()) - cmd.AddCommand(newWipeCommand()) + addCmdWithGroup(newPullCommand(env), remoteGroup) + addCmdWithGroup(newPushCommand(env), remoteGroup) + addCmdWithGroup(bridgecmd.NewBridgeCommand(env), remoteGroup) + + cmd.AddCommand(newCommandsCommand(env)) + cmd.AddCommand(newVersionCommand(env)) + cmd.AddCommand(newWipeCommand(env)) return cmd } diff --git a/commands/termui.go b/commands/termui.go index 1cfdd8f3..08eba1d6 100644 --- a/commands/termui.go +++ b/commands/termui.go @@ -7,9 +7,7 @@ import ( "github.com/MichaelMure/git-bug/termui" ) -func newTermUICommand() *cobra.Command { - env := execenv.NewEnv() - +func newTermUICommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "termui", Aliases: []string{"tui"}, 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{ diff --git a/commands/version.go b/commands/version.go index 0e54bb92..957cc653 100644 --- a/commands/version.go +++ b/commands/version.go @@ -14,8 +14,7 @@ type versionOptions struct { all bool } -func newVersionCommand() *cobra.Command { - env := execenv.NewEnv() +func newVersionCommand(env *execenv.Env) *cobra.Command { options := versionOptions{} cmd := &cobra.Command{ diff --git a/commands/webui.go b/commands/webui.go index 31313146..3129a222 100644 --- a/commands/webui.go +++ b/commands/webui.go @@ -42,8 +42,7 @@ type webUIOptions struct { query string } -func newWebUICommand() *cobra.Command { - env := execenv.NewEnv() +func newWebUICommand(env *execenv.Env) *cobra.Command { options := webUIOptions{} cmd := &cobra.Command{ diff --git a/commands/wipe.go b/commands/wipe.go index 0ec53f49..ce9da032 100644 --- a/commands/wipe.go +++ b/commands/wipe.go @@ -6,9 +6,7 @@ import ( "github.com/MichaelMure/git-bug/commands/execenv" ) -func newWipeCommand() *cobra.Command { - env := execenv.NewEnv() - +func newWipeCommand(env *execenv.Env) *cobra.Command { cmd := &cobra.Command{ Use: "wipe", Short: "Wipe git-bug from the git repository", From 723b3c41470cafd240b0c2f174bc7e1762bc3680 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Tue, 17 Jan 2023 20:35:59 -0500 Subject: [PATCH 2/2] fix(commands): replace missing import --- commands/bug/bug_comment_test.go | 1 + go.mod | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/bug/bug_comment_test.go b/commands/bug/bug_comment_test.go index 5625f1be..ecc1c5f6 100644 --- a/commands/bug/bug_comment_test.go +++ b/commands/bug/bug_comment_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/MichaelMure/git-bug/commands/bug/testenv" + "github.com/MichaelMure/git-bug/commands/cmdtest" "github.com/MichaelMure/git-bug/commands/execenv" ) diff --git a/go.mod b/go.mod index e2425072..0008ef92 100644 --- a/go.mod +++ b/go.mod @@ -114,7 +114,7 @@ require ( go.etcd.io/bbolt v1.3.5 // indirect golang.org/x/mod v0.7.0 // indirect golang.org/x/net v0.5.0 // indirect - golang.org/x/term v0.4.0 // indirect + golang.org/x/term v0.4.0 golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect golang.org/x/tools v0.4.0 // indirect golang.org/x/vuln v0.0.0-20220908155419-5537ad2271a7