From 271dc1334cf8ce3c798dafeb9ac7113072195c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 9 May 2021 11:33:20 +0200 Subject: [PATCH] commands: proper backend close on RunE error --- commands/add.go | 11 +++++------ commands/bridge.go | 11 +++++------ commands/bridge_auth.go | 11 +++++------ commands/bridge_auth_addtoken.go | 11 +++++------ commands/bridge_auth_show.go | 11 +++++------ commands/bridge_configure.go | 7 +++---- commands/bridge_pull.go | 11 +++++------ commands/bridge_push.go | 11 +++++------ commands/bridge_rm.go | 11 +++++------ commands/comment.go | 11 +++++------ commands/comment_add.go | 11 +++++------ commands/comment_edit.go | 13 ++++++------- commands/deselect.go | 7 +++---- commands/env.go | 12 ++++++++++-- commands/label.go | 11 +++++------ commands/label_add.go | 11 +++++------ commands/label_rm.go | 11 +++++------ commands/ls-id.go | 11 +++++------ commands/ls-labels.go | 7 +++---- commands/ls.go | 7 +++---- commands/pull.go | 11 +++++------ commands/push.go | 11 +++++------ commands/rm.go | 13 ++++++------- commands/select.go | 7 +++---- commands/show.go | 11 +++++------ commands/status.go | 11 +++++------ commands/status_close.go | 11 +++++------ commands/status_open.go | 11 +++++------ commands/termui.go | 13 ++++++------- commands/title.go | 11 +++++------ commands/title_edit.go | 11 +++++------ commands/user.go | 11 +++++------ commands/user_adopt.go | 13 ++++++------- commands/user_create.go | 11 +++++------ commands/user_ls.go | 11 +++++------ 35 files changed, 174 insertions(+), 200 deletions(-) diff --git a/commands/add.go b/commands/add.go index 3a28c424..504207fb 100644 --- a/commands/add.go +++ b/commands/add.go @@ -19,13 +19,12 @@ func newAddCommand() *cobra.Command { options := addOptions{} cmd := &cobra.Command{ - Use: "add", - Short: "Create a new bug.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "add", + Short: "Create a new bug.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runAdd(env, options) - }, + }), } flags := cmd.Flags() diff --git a/commands/bridge.go b/commands/bridge.go index 46b3d9ec..8ce35aa3 100644 --- a/commands/bridge.go +++ b/commands/bridge.go @@ -10,13 +10,12 @@ func newBridgeCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "bridge", - Short: "Configure and use bridges to other bug trackers.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "bridge", + Short: "Configure and use bridges to other bug trackers.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridge(env) - }, + }), Args: cobra.NoArgs, } diff --git a/commands/bridge_auth.go b/commands/bridge_auth.go index db4c5212..50306b8d 100644 --- a/commands/bridge_auth.go +++ b/commands/bridge_auth.go @@ -16,13 +16,12 @@ func newBridgeAuthCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "auth", - Short: "List all known bridge authentication credentials.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "auth", + Short: "List all known bridge authentication credentials.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridgeAuth(env) - }, + }), Args: cobra.NoArgs, } diff --git a/commands/bridge_auth_addtoken.go b/commands/bridge_auth_addtoken.go index 272eab8c..c0458fda 100644 --- a/commands/bridge_auth_addtoken.go +++ b/commands/bridge_auth_addtoken.go @@ -27,13 +27,12 @@ func newBridgeAuthAddTokenCommand() *cobra.Command { options := bridgeAuthAddTokenOptions{} cmd := &cobra.Command{ - Use: "add-token [TOKEN]", - Short: "Store a new token", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "add-token [TOKEN]", + Short: "Store a new token", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridgeAuthAddToken(env, options, args) - }, + }), Args: cobra.MaximumNArgs(1), } diff --git a/commands/bridge_auth_show.go b/commands/bridge_auth_show.go index 408a6cf1..f174cdb7 100644 --- a/commands/bridge_auth_show.go +++ b/commands/bridge_auth_show.go @@ -15,13 +15,12 @@ func newBridgeAuthShow() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "show", - Short: "Display an authentication credential.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "show", + Short: "Display an authentication credential.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridgeAuthShow(env, args) - }, + }), Args: cobra.ExactArgs(1), } diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index c0ce1461..6533e497 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -85,11 +85,10 @@ git bug bridge configure \ --target=github \ --url=https://github.com/michaelmure/git-bug \ --token=$(TOKEN)`, - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridgeConfigure(env, options) - }, + }), } flags := cmd.Flags() diff --git a/commands/bridge_pull.go b/commands/bridge_pull.go index 95eb2fe0..3155ebf4 100644 --- a/commands/bridge_pull.go +++ b/commands/bridge_pull.go @@ -26,13 +26,12 @@ func newBridgePullCommand() *cobra.Command { options := bridgePullOptions{} cmd := &cobra.Command{ - Use: "pull [NAME]", - Short: "Pull updates.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "pull [NAME]", + Short: "Pull updates.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridgePull(env, options, args) - }, + }), Args: cobra.MaximumNArgs(1), } diff --git a/commands/bridge_push.go b/commands/bridge_push.go index 64e3ff4b..a232f0f0 100644 --- a/commands/bridge_push.go +++ b/commands/bridge_push.go @@ -17,13 +17,12 @@ func newBridgePushCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "push [NAME]", - Short: "Push updates.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "push [NAME]", + Short: "Push updates.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridgePush(env, args) - }, + }), Args: cobra.MaximumNArgs(1), } diff --git a/commands/bridge_rm.go b/commands/bridge_rm.go index 9f5c81c7..121a35ad 100644 --- a/commands/bridge_rm.go +++ b/commands/bridge_rm.go @@ -10,13 +10,12 @@ func newBridgeRm() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "rm NAME", - Short: "Delete a configured bridge.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "rm NAME", + Short: "Delete a configured bridge.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runBridgeRm(env, args) - }, + }), Args: cobra.ExactArgs(1), } diff --git a/commands/comment.go b/commands/comment.go index eb90624a..90657e4a 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -12,13 +12,12 @@ func newCommentCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "comment [ID]", - Short: "Display or add comments to a bug.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "comment [ID]", + Short: "Display or add comments to a bug.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runComment(env, args) - }, + }), } cmd.AddCommand(newCommentAddCommand()) diff --git a/commands/comment_add.go b/commands/comment_add.go index 54c75702..11ba5ad3 100644 --- a/commands/comment_add.go +++ b/commands/comment_add.go @@ -19,13 +19,12 @@ func newCommentAddCommand() *cobra.Command { options := commentAddOptions{} cmd := &cobra.Command{ - Use: "add [ID]", - Short: "Add a new comment to a bug.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "add [ID]", + Short: "Add a new comment to a bug.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runCommentAdd(env, options, args) - }, + }), } flags := cmd.Flags() diff --git a/commands/comment_edit.go b/commands/comment_edit.go index 6c93ed8b..759ea194 100644 --- a/commands/comment_edit.go +++ b/commands/comment_edit.go @@ -17,14 +17,13 @@ func newCommentEditCommand() *cobra.Command { options := commentEditOptions{} cmd := &cobra.Command{ - Use: "edit [COMMENT_ID]", - Short: "Edit an existing comment on a bug.", - Args: cobra.ExactArgs(1), - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "edit [COMMENT_ID]", + Short: "Edit an existing comment on a bug.", + Args: cobra.ExactArgs(1), + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runCommentEdit(env, options, args) - }, + }), } flags := cmd.Flags() diff --git a/commands/deselect.go b/commands/deselect.go index 23f77e2d..d8c44dd7 100644 --- a/commands/deselect.go +++ b/commands/deselect.go @@ -17,11 +17,10 @@ git bug comment git bug status git bug deselect `, - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runDeselect(env) - }, + }), } return cmd diff --git a/commands/env.go b/commands/env.go index 8d12c5bf..ac7b789a 100644 --- a/commands/env.go +++ b/commands/env.go @@ -136,15 +136,23 @@ func loadBackendEnsureUser(env *Env) func(*cobra.Command, []string) error { } } -// closeBackend is a post-run function that will close the backend properly +// closeBackend is a wrapper for a RunE function that will close the backend properly // if it has been opened. -func closeBackend(env *Env) func(*cobra.Command, []string) error { +// This wrapper style is necessary because a Cobra PostE function does not run if RunE return an error. +func closeBackend(env *Env, runE func(cmd *cobra.Command, args []string) error) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { + errRun := runE(cmd, args) + if env.backend == nil { return nil } err := env.backend.Close() env.backend = nil + + // prioritize the RunE error + if errRun != nil { + return errRun + } return err } } diff --git a/commands/label.go b/commands/label.go index e3ffdb64..d108b089 100644 --- a/commands/label.go +++ b/commands/label.go @@ -10,13 +10,12 @@ func newLabelCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "label [ID]", - Short: "Display, add or remove labels to/from a bug.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "label [ID]", + Short: "Display, add or remove labels to/from a bug.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runLabel(env, args) - }, + }), } cmd.AddCommand(newLabelAddCommand()) diff --git a/commands/label_add.go b/commands/label_add.go index 30c0d77f..c60ecfeb 100644 --- a/commands/label_add.go +++ b/commands/label_add.go @@ -11,13 +11,12 @@ func newLabelAddCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "add [ID] LABEL...", - Short: "Add a label to a bug.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "add [ID] LABEL...", + Short: "Add a label to a bug.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runLabelAdd(env, args) - }, + }), } return cmd diff --git a/commands/label_rm.go b/commands/label_rm.go index 9fb3e096..1cdcd248 100644 --- a/commands/label_rm.go +++ b/commands/label_rm.go @@ -11,13 +11,12 @@ func newLabelRmCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "rm [ID] LABEL...", - Short: "Remove a label from a bug.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "rm [ID] LABEL...", + Short: "Remove a label from a bug.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runLabelRm(env, args) - }, + }), } return cmd diff --git a/commands/ls-id.go b/commands/ls-id.go index 686f432a..41f017e8 100644 --- a/commands/ls-id.go +++ b/commands/ls-id.go @@ -8,13 +8,12 @@ func newLsIdCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "ls-id [PREFIX]", - Short: "List bug identifiers.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "ls-id [PREFIX]", + Short: "List bug identifiers.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runLsId(env, args) - }, + }), } return cmd diff --git a/commands/ls-labels.go b/commands/ls-labels.go index a7c2fb6f..086943a9 100644 --- a/commands/ls-labels.go +++ b/commands/ls-labels.go @@ -13,11 +13,10 @@ func newLsLabelCommand() *cobra.Command { Long: `List valid labels. Note: in the future, a proper label policy could be implemented where valid labels are defined in a configuration file. Until that, the default behavior is to return the list of labels already used.`, - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runLsLabel(env) - }, + }), } return cmd diff --git a/commands/ls.go b/commands/ls.go index 71c420c6..9134d752 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -52,11 +52,10 @@ git bug ls "foo bar" baz Use queries, flags, and full text search: git bug ls status:open --by creation "foo bar" baz `, - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runLs(env, options, args) - }, + }), } flags := cmd.Flags() diff --git a/commands/pull.go b/commands/pull.go index 3ad4a0c9..f3a31414 100644 --- a/commands/pull.go +++ b/commands/pull.go @@ -12,13 +12,12 @@ func newPullCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "pull [REMOTE]", - Short: "Pull bugs update from a git remote.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "pull [REMOTE]", + Short: "Pull bugs update from a git remote.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runPull(env, args) - }, + }), } return cmd diff --git a/commands/push.go b/commands/push.go index 89385f10..9d6ca7df 100644 --- a/commands/push.go +++ b/commands/push.go @@ -10,13 +10,12 @@ func newPushCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "push [REMOTE]", - Short: "Push bugs update to a git remote.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "push [REMOTE]", + Short: "Push bugs update to a git remote.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runPush(env, args) - }, + }), } return cmd diff --git a/commands/rm.go b/commands/rm.go index 3ad4548d..8205c128 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -10,14 +10,13 @@ func newRmCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "rm ID", - Short: "Remove an existing bug.", - Long: "Remove an existing bug in the local repository. Note removing bugs that were imported from bridges will not remove the bug on the remote, and will only remove the local copy of the bug.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "rm ID", + Short: "Remove an existing bug.", + Long: "Remove an existing bug in the local repository. Note removing bugs that were imported from bridges will not remove the bug on the remote, and will only remove the local copy of the bug.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runRm(env, args) - }, + }), } flags := cmd.Flags() diff --git a/commands/select.go b/commands/select.go index 64e38d9b..34d00a32 100644 --- a/commands/select.go +++ b/commands/select.go @@ -27,11 +27,10 @@ instead of The complementary command is "git bug deselect" performing the opposite operation. `, - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runSelect(env, args) - }, + }), } return cmd diff --git a/commands/show.go b/commands/show.go index 10087f92..55140357 100644 --- a/commands/show.go +++ b/commands/show.go @@ -23,13 +23,12 @@ func newShowCommand() *cobra.Command { options := showOptions{} cmd := &cobra.Command{ - Use: "show [ID]", - Short: "Display the details of a bug.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "show [ID]", + Short: "Display the details of a bug.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runShow(env, options, args) - }, + }), } flags := cmd.Flags() diff --git a/commands/status.go b/commands/status.go index 4dceb51c..c1e45c5f 100644 --- a/commands/status.go +++ b/commands/status.go @@ -9,13 +9,12 @@ func newStatusCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "status [ID]", - Short: "Display or change a bug status.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "status [ID]", + Short: "Display or change a bug status.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runStatus(env, args) - }, + }), } cmd.AddCommand(newStatusCloseCommand()) diff --git a/commands/status_close.go b/commands/status_close.go index 76f2a758..8541aa0b 100644 --- a/commands/status_close.go +++ b/commands/status_close.go @@ -9,13 +9,12 @@ func newStatusCloseCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "close [ID]", - Short: "Mark a bug as closed.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "close [ID]", + Short: "Mark a bug as closed.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runStatusClose(env, args) - }, + }), } return cmd diff --git a/commands/status_open.go b/commands/status_open.go index ff778561..ee6bd27a 100644 --- a/commands/status_open.go +++ b/commands/status_open.go @@ -9,13 +9,12 @@ func newStatusOpenCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "open [ID]", - Short: "Mark a bug as open.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "open [ID]", + Short: "Mark a bug as open.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runStatusOpen(env, args) - }, + }), } return cmd diff --git a/commands/termui.go b/commands/termui.go index 1470790f..4df6cdaf 100644 --- a/commands/termui.go +++ b/commands/termui.go @@ -10,14 +10,13 @@ func newTermUICommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "termui", - Aliases: []string{"tui"}, - Short: "Launch the terminal UI.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "termui", + Aliases: []string{"tui"}, + Short: "Launch the terminal UI.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runTermUI(env) - }, + }), } return cmd diff --git a/commands/title.go b/commands/title.go index 7afa07ce..c4293530 100644 --- a/commands/title.go +++ b/commands/title.go @@ -9,13 +9,12 @@ func newTitleCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "title [ID]", - Short: "Display or change a title of a bug.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "title [ID]", + Short: "Display or change a title of a bug.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runTitle(env, args) - }, + }), } cmd.AddCommand(newTitleEditCommand()) diff --git a/commands/title_edit.go b/commands/title_edit.go index 09415e49..810c5e62 100644 --- a/commands/title_edit.go +++ b/commands/title_edit.go @@ -18,13 +18,12 @@ func newTitleEditCommand() *cobra.Command { options := titleEditOptions{} cmd := &cobra.Command{ - Use: "edit [ID]", - Short: "Edit a title of a bug.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "edit [ID]", + Short: "Edit a title of a bug.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runTitleEdit(env, options, args) - }, + }), } flags := cmd.Flags() diff --git a/commands/user.go b/commands/user.go index 29c4e932..b6a2e485 100644 --- a/commands/user.go +++ b/commands/user.go @@ -18,13 +18,12 @@ func newUserCommand() *cobra.Command { options := userOptions{} cmd := &cobra.Command{ - Use: "user [USER-ID]", - Short: "Display or change the user identity.", - PreRunE: loadBackendEnsureUser(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "user [USER-ID]", + Short: "Display or change the user identity.", + PreRunE: loadBackendEnsureUser(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runUser(env, options, args) - }, + }), } cmd.AddCommand(newUserAdoptCommand()) diff --git a/commands/user_adopt.go b/commands/user_adopt.go index 5ab6e39c..166063ae 100644 --- a/commands/user_adopt.go +++ b/commands/user_adopt.go @@ -8,14 +8,13 @@ func newUserAdoptCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "adopt USER-ID", - Short: "Adopt an existing identity as your own.", - Args: cobra.ExactArgs(1), - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "adopt USER-ID", + Short: "Adopt an existing identity as your own.", + Args: cobra.ExactArgs(1), + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runUserAdopt(env, args) - }, + }), } return cmd diff --git a/commands/user_create.go b/commands/user_create.go index 0dcfa9b3..b5cb0528 100644 --- a/commands/user_create.go +++ b/commands/user_create.go @@ -18,13 +18,12 @@ func newUserCreateCommand() *cobra.Command { options := createUserOptions{} cmd := &cobra.Command{ - Use: "create", - Short: "Create a new identity.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "create", + Short: "Create a new identity.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runUserCreate(env, options) - }, + }), } flags := cmd.Flags() diff --git a/commands/user_ls.go b/commands/user_ls.go index 05d343d6..98800b87 100644 --- a/commands/user_ls.go +++ b/commands/user_ls.go @@ -19,13 +19,12 @@ func newUserLsCommand() *cobra.Command { options := userLsOptions{} cmd := &cobra.Command{ - Use: "ls", - Short: "List identities.", - PreRunE: loadBackend(env), - PostRunE: closeBackend(env), - RunE: func(cmd *cobra.Command, args []string) error { + Use: "ls", + Short: "List identities.", + PreRunE: loadBackend(env), + RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runUserLs(env, options) - }, + }), } flags := cmd.Flags()