From 544b9cc0c4cc694cdb688b9cad8f9c8542d111fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Tue, 18 Sep 2018 13:28:01 +0200 Subject: [PATCH] commands: convert compatible commands to the implicit select mechanism --- commands/comment.go | 18 +++--------------- commands/comment_add.go | 18 +++--------------- commands/label add.go | 15 ++++----------- commands/label rm.go | 15 ++++----------- commands/label.go | 16 +++------------- commands/select.go | 2 +- commands/show.go | 15 +++------------ commands/status.go | 18 +++--------------- commands/status_close.go | 17 +++-------------- commands/status_open.go | 17 +++-------------- commands/title.go | 18 +++--------------- commands/title_edit.go | 18 +++--------------- doc/man/git-bug-comment-add.1 | 2 +- doc/man/git-bug-comment.1 | 2 +- doc/man/git-bug-label-add.1 | 2 +- doc/man/git-bug-label-rm.1 | 2 +- doc/man/git-bug-label.1 | 2 +- doc/man/git-bug-select.1 | 2 +- doc/man/git-bug-show.1 | 2 +- doc/man/git-bug-status-close.1 | 2 +- doc/man/git-bug-status-open.1 | 2 +- doc/man/git-bug-status.1 | 2 +- doc/man/git-bug-title-edit.1 | 2 +- doc/man/git-bug-title.1 | 2 +- doc/md/git-bug_comment.md | 2 +- doc/md/git-bug_comment_add.md | 2 +- doc/md/git-bug_label.md | 2 +- doc/md/git-bug_label_add.md | 2 +- doc/md/git-bug_label_rm.md | 2 +- doc/md/git-bug_select.md | 2 +- doc/md/git-bug_show.md | 2 +- doc/md/git-bug_status.md | 2 +- doc/md/git-bug_status_close.md | 2 +- doc/md/git-bug_status_open.md | 2 +- doc/md/git-bug_title.md | 2 +- doc/md/git-bug_title_edit.md | 2 +- 36 files changed, 60 insertions(+), 175 deletions(-) diff --git a/commands/comment.go b/commands/comment.go index 4626797938c836987d993c63718fff204c902c27..9169d7d759765ce12b4ffa9fafc3a8f10de214ba 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -1,36 +1,24 @@ package commands import ( - "errors" "fmt" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/colors" "github.com/MichaelMure/git-bug/util/text" "github.com/spf13/cobra" ) func runComment(cmd *cobra.Command, args []string) error { - var err error - - if len(args) > 1 { - return errors.New("Only one bug id is supported") - } - - if len(args) == 0 { - return errors.New("You must provide a bug id") - } - backend, err := cache.NewRepoCache(repo) if err != nil { return err } defer backend.Close() - prefix := args[0] - - b, err := backend.ResolveBugPrefix(prefix) + b, args, err := _select.ResolveBug(backend, args) if err != nil { return err } @@ -55,7 +43,7 @@ func commentsTextOutput(comments []bug.Comment) { } var commentCmd = &cobra.Command{ - Use: "comment ", + Use: "comment []", Short: "Show a bug's comments", RunE: runComment, } diff --git a/commands/comment_add.go b/commands/comment_add.go index 46d0c8b83a2f160f23e8bd418b20cb1982353e94..c80e9ec5d42c24702844a8bd70a797dc27452045 100644 --- a/commands/comment_add.go +++ b/commands/comment_add.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/input" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -15,24 +15,12 @@ var ( ) func runCommentAdd(cmd *cobra.Command, args []string) error { - var err error - - if len(args) > 1 { - return errors.New("Only one bug id is supported") - } - - if len(args) == 0 { - return errors.New("You must provide a bug id") - } - backend, err := cache.NewRepoCache(repo) if err != nil { return err } defer backend.Close() - prefix := args[0] - if commentAddMessageFile != "" && commentAddMessage == "" { commentAddMessage, err = input.FromFile(commentAddMessageFile) if err != nil { @@ -51,7 +39,7 @@ func runCommentAdd(cmd *cobra.Command, args []string) error { } } - b, err := backend.ResolveBugPrefix(prefix) + b, args, err := _select.ResolveBug(backend, args) if err != nil { return err } @@ -65,7 +53,7 @@ func runCommentAdd(cmd *cobra.Command, args []string) error { } var commentAddCmd = &cobra.Command{ - Use: "add ", + Use: "add []", Short: "Add a new comment to a bug", RunE: runCommentAdd, } diff --git a/commands/label add.go b/commands/label add.go index fccbfaa3726ec3a53e3c2499ff89ba421d44c637..68811deca2f03af372f80a6d5e8ddc61e77a453c 100644 --- a/commands/label add.go +++ b/commands/label add.go @@ -1,33 +1,26 @@ package commands import ( - "errors" "fmt" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/spf13/cobra" ) func runLabelAdd(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errors.New("You must provide a bug id") - } - backend, err := cache.NewRepoCache(repo) if err != nil { return err } defer backend.Close() - prefix := args[0] - add := args[1:] - - b, err := backend.ResolveBugPrefix(prefix) + b, args, err := _select.ResolveBug(backend, args) if err != nil { return err } - changes, err := b.ChangeLabels(add, nil) + changes, err := b.ChangeLabels(args, nil) for _, change := range changes { fmt.Println(change) @@ -41,7 +34,7 @@ func runLabelAdd(cmd *cobra.Command, args []string) error { } var labelAddCmd = &cobra.Command{ - Use: "add [