diff options
36 files changed, 60 insertions, 175 deletions
diff --git a/commands/comment.go b/commands/comment.go index 46267979..9169d7d7 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 <id>", + Use: "comment [<id>]", Short: "Show a bug's comments", RunE: runComment, } diff --git a/commands/comment_add.go b/commands/comment_add.go index 46d0c8b8..c80e9ec5 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 <id>", + Use: "add [<id>]", Short: "Add a new comment to a bug", RunE: runCommentAdd, } diff --git a/commands/label add.go b/commands/label add.go index fccbfaa3..68811dec 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 <id> [<label>...]", + Use: "add [<id>] <label>[...]", Short: "Add a label to a bug", RunE: runLabelAdd, } diff --git a/commands/label rm.go b/commands/label rm.go index 9908094c..8ad89593 100644 --- a/commands/label rm.go +++ b/commands/label rm.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 runLabelRm(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] - remove := args[1:] - - b, err := backend.ResolveBugPrefix(prefix) + b, args, err := _select.ResolveBug(backend, args) if err != nil { return err } - changes, err := b.ChangeLabels(nil, remove) + changes, err := b.ChangeLabels(nil, args) for _, change := range changes { fmt.Println(change) @@ -41,7 +34,7 @@ func runLabelRm(cmd *cobra.Command, args []string) error { } var labelRmCmd = &cobra.Command{ - Use: "rm <id> [<label>...]", + Use: "rm [<id>] <label>[...]", Short: "Remove a label from a bug", RunE: runLabelRm, } diff --git a/commands/label.go b/commands/label.go index c693f82c..d41b6dfb 100644 --- a/commands/label.go +++ b/commands/label.go @@ -1,31 +1,21 @@ package commands import ( - "errors" "fmt" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/spf13/cobra" ) func runLabel(cmd *cobra.Command, args []string) 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 } @@ -40,7 +30,7 @@ func runLabel(cmd *cobra.Command, args []string) error { } var labelCmd = &cobra.Command{ - Use: "label <id>", + Use: "label [<id>]", Short: "Display a bug labels", RunE: runLabel, } diff --git a/commands/select.go b/commands/select.go index c810b85a..2cbb0b2e 100644 --- a/commands/select.go +++ b/commands/select.go @@ -35,7 +35,7 @@ func runSelect(cmd *cobra.Command, args []string) error { } var selectCmd = &cobra.Command{ - Use: "select [<id>]", + Use: "select <id>", Short: "Select a bug for implicit use in future commands", Example: `git bug select 2f15 git bug comment diff --git a/commands/show.go b/commands/show.go index d4d1bb54..b1b7b432 100644 --- a/commands/show.go +++ b/commands/show.go @@ -6,28 +6,19 @@ import ( "strings" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/colors" "github.com/spf13/cobra" ) func runShowBug(cmd *cobra.Command, args []string) error { - if len(args) > 1 { - return errors.New("Only showing one bug at a time 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 } @@ -82,7 +73,7 @@ func runShowBug(cmd *cobra.Command, args []string) error { } var showCmd = &cobra.Command{ - Use: "show <id>", + Use: "show [<id>]", Short: "Display the details of a bug", RunE: runShowBug, } diff --git a/commands/status.go b/commands/status.go index 29646b6e..02ddc481 100644 --- a/commands/status.go +++ b/commands/status.go @@ -4,30 +4,18 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/commands/select" "github.com/spf13/cobra" ) func runStatus(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 } @@ -40,7 +28,7 @@ func runStatus(cmd *cobra.Command, args []string) error { } var statusCmd = &cobra.Command{ - Use: "status <id>", + Use: "status [<id>]", Short: "Show the bug status", RunE: runStatus, } diff --git a/commands/status_close.go b/commands/status_close.go index 55e47c22..de8b990c 100644 --- a/commands/status_close.go +++ b/commands/status_close.go @@ -1,30 +1,19 @@ package commands import ( - "errors" - "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/spf13/cobra" ) func runStatusClose(cmd *cobra.Command, args []string) error { - if len(args) > 1 { - return errors.New("Only closing one bug at a time 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 } @@ -38,7 +27,7 @@ func runStatusClose(cmd *cobra.Command, args []string) error { } var closeCmd = &cobra.Command{ - Use: "close <id>", + Use: "close [<id>]", Short: "Mark the bug as closed", RunE: runStatusClose, } diff --git a/commands/status_open.go b/commands/status_open.go index 15108ddf..6b94b9cb 100644 --- a/commands/status_open.go +++ b/commands/status_open.go @@ -1,30 +1,19 @@ package commands import ( - "errors" - "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/spf13/cobra" ) func runStatusOpen(cmd *cobra.Command, args []string) error { - if len(args) > 1 { - return errors.New("Only opening one bug at a time 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 } @@ -38,7 +27,7 @@ func runStatusOpen(cmd *cobra.Command, args []string) error { } var openCmd = &cobra.Command{ - Use: "open <id>", + Use: "open [<id>]", Short: "Mark the bug as open", RunE: runStatusOpen, } diff --git a/commands/title.go b/commands/title.go index 16cfc342..dd5fbfb1 100644 --- a/commands/title.go +++ b/commands/title.go @@ -4,30 +4,18 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/commands/select" "github.com/spf13/cobra" ) func runTitle(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 } @@ -40,7 +28,7 @@ func runTitle(cmd *cobra.Command, args []string) error { } var titleCmd = &cobra.Command{ - Use: "title <id>", + Use: "title [<id>]", Short: "Display a bug's title", RunE: runTitle, } diff --git a/commands/title_edit.go b/commands/title_edit.go index 111c6325..a62daf6c 100644 --- a/commands/title_edit.go +++ b/commands/title_edit.go @@ -1,10 +1,10 @@ package commands import ( - "errors" "fmt" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/input" "github.com/spf13/cobra" ) @@ -14,25 +14,13 @@ var ( ) func runTitleEdit(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 } @@ -59,7 +47,7 @@ func runTitleEdit(cmd *cobra.Command, args []string) error { } var titleEditCmd = &cobra.Command{ - Use: "edit <id>", + Use: "edit [<id>]", Short: "Edit a bug title", RunE: runTitleEdit, } diff --git a/doc/man/git-bug-comment-add.1 b/doc/man/git-bug-comment-add.1 index 1a2fc2dc..304109cf 100644 --- a/doc/man/git-bug-comment-add.1 +++ b/doc/man/git-bug-comment-add.1 @@ -10,7 +10,7 @@ git\-bug\-comment\-add \- Add a new comment to a bug .SH SYNOPSIS .PP -\fBgit\-bug comment add <id> [flags]\fP +\fBgit\-bug comment add [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-comment.1 b/doc/man/git-bug-comment.1 index 8ad43e5c..bbac0f33 100644 --- a/doc/man/git-bug-comment.1 +++ b/doc/man/git-bug-comment.1 @@ -10,7 +10,7 @@ git\-bug\-comment \- Show a bug's comments .SH SYNOPSIS .PP -\fBgit\-bug comment <id> [flags]\fP +\fBgit\-bug comment [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-label-add.1 b/doc/man/git-bug-label-add.1 index c3413126..f34a6943 100644 --- a/doc/man/git-bug-label-add.1 +++ b/doc/man/git-bug-label-add.1 @@ -10,7 +10,7 @@ git\-bug\-label\-add \- Add a label to a bug .SH SYNOPSIS .PP -\fBgit\-bug label add <id> [<label>\&...] [flags]\fP +\fBgit\-bug label add [<id>] <label>[...] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-label-rm.1 b/doc/man/git-bug-label-rm.1 index c7f308ed..72578bf8 100644 --- a/doc/man/git-bug-label-rm.1 +++ b/doc/man/git-bug-label-rm.1 @@ -10,7 +10,7 @@ git\-bug\-label\-rm \- Remove a label from a bug .SH SYNOPSIS .PP -\fBgit\-bug label rm <id> [<label>\&...] [flags]\fP +\fBgit\-bug label rm [<id>] <label>[...] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-label.1 b/doc/man/git-bug-label.1 index 6621b7a7..eecdc43b 100644 --- a/doc/man/git-bug-label.1 +++ b/doc/man/git-bug-label.1 @@ -10,7 +10,7 @@ git\-bug\-label \- Display a bug labels .SH SYNOPSIS .PP -\fBgit\-bug label <id> [flags]\fP +\fBgit\-bug label [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-select.1 b/doc/man/git-bug-select.1 index f73582fa..52097050 100644 --- a/doc/man/git-bug-select.1 +++ b/doc/man/git-bug-select.1 @@ -10,7 +10,7 @@ git\-bug\-select \- Select a bug for implicit use in future commands .SH SYNOPSIS .PP -\fBgit\-bug select [<id>] [flags]\fP +\fBgit\-bug select <id> [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-show.1 b/doc/man/git-bug-show.1 index ebeee5a3..a20266d4 100644 --- a/doc/man/git-bug-show.1 +++ b/doc/man/git-bug-show.1 @@ -10,7 +10,7 @@ git\-bug\-show \- Display the details of a bug .SH SYNOPSIS .PP -\fBgit\-bug show <id> [flags]\fP +\fBgit\-bug show [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-status-close.1 b/doc/man/git-bug-status-close.1 index 0d45d112..27ab6442 100644 --- a/doc/man/git-bug-status-close.1 +++ b/doc/man/git-bug-status-close.1 @@ -10,7 +10,7 @@ git\-bug\-status\-close \- Mark the bug as closed .SH SYNOPSIS .PP -\fBgit\-bug status close <id> [flags]\fP +\fBgit\-bug status close [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-status-open.1 b/doc/man/git-bug-status-open.1 index 70a23437..d2f4a5cb 100644 --- a/doc/man/git-bug-status-open.1 +++ b/doc/man/git-bug-status-open.1 @@ -10,7 +10,7 @@ git\-bug\-status\-open \- Mark the bug as open .SH SYNOPSIS .PP -\fBgit\-bug status open <id> [flags]\fP +\fBgit\-bug status open [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-status.1 b/doc/man/git-bug-status.1 index 69628f26..7571e77b 100644 --- a/doc/man/git-bug-status.1 +++ b/doc/man/git-bug-status.1 @@ -10,7 +10,7 @@ git\-bug\-status \- Show the bug status .SH SYNOPSIS .PP -\fBgit\-bug status <id> [flags]\fP +\fBgit\-bug status [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-title-edit.1 b/doc/man/git-bug-title-edit.1 index 62895f7e..4deae19a 100644 --- a/doc/man/git-bug-title-edit.1 +++ b/doc/man/git-bug-title-edit.1 @@ -10,7 +10,7 @@ git\-bug\-title\-edit \- Edit a bug title .SH SYNOPSIS .PP -\fBgit\-bug title edit <id> [flags]\fP +\fBgit\-bug title edit [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/man/git-bug-title.1 b/doc/man/git-bug-title.1 index a4493571..3574dfb8 100644 --- a/doc/man/git-bug-title.1 +++ b/doc/man/git-bug-title.1 @@ -10,7 +10,7 @@ git\-bug\-title \- Display a bug's title .SH SYNOPSIS .PP -\fBgit\-bug title <id> [flags]\fP +\fBgit\-bug title [<id>] [flags]\fP .SH DESCRIPTION diff --git a/doc/md/git-bug_comment.md b/doc/md/git-bug_comment.md index 9870e5fe..3e12fbfd 100644 --- a/doc/md/git-bug_comment.md +++ b/doc/md/git-bug_comment.md @@ -7,7 +7,7 @@ Show a bug's comments Show a bug's comments ``` -git-bug comment <id> [flags] +git-bug comment [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_comment_add.md b/doc/md/git-bug_comment_add.md index 412e40d7..678f910e 100644 --- a/doc/md/git-bug_comment_add.md +++ b/doc/md/git-bug_comment_add.md @@ -7,7 +7,7 @@ Add a new comment to a bug Add a new comment to a bug ``` -git-bug comment add <id> [flags] +git-bug comment add [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_label.md b/doc/md/git-bug_label.md index 75f4b843..3f68e067 100644 --- a/doc/md/git-bug_label.md +++ b/doc/md/git-bug_label.md @@ -7,7 +7,7 @@ Display a bug labels Display a bug labels ``` -git-bug label <id> [flags] +git-bug label [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_label_add.md b/doc/md/git-bug_label_add.md index a89a522c..afe3e803 100644 --- a/doc/md/git-bug_label_add.md +++ b/doc/md/git-bug_label_add.md @@ -7,7 +7,7 @@ Add a label to a bug Add a label to a bug ``` -git-bug label add <id> [<label>...] [flags] +git-bug label add [<id>] <label>[...] [flags] ``` ### Options diff --git a/doc/md/git-bug_label_rm.md b/doc/md/git-bug_label_rm.md index 3c740a9f..7721a2ba 100644 --- a/doc/md/git-bug_label_rm.md +++ b/doc/md/git-bug_label_rm.md @@ -7,7 +7,7 @@ Remove a label from a bug Remove a label from a bug ``` -git-bug label rm <id> [<label>...] [flags] +git-bug label rm [<id>] <label>[...] [flags] ``` ### Options diff --git a/doc/md/git-bug_select.md b/doc/md/git-bug_select.md index 014ba512..963cfb24 100644 --- a/doc/md/git-bug_select.md +++ b/doc/md/git-bug_select.md @@ -7,7 +7,7 @@ Select a bug for implicit use in future commands Select a bug for implicit use in future commands ``` -git-bug select [<id>] [flags] +git-bug select <id> [flags] ``` ### Examples diff --git a/doc/md/git-bug_show.md b/doc/md/git-bug_show.md index 6edde61a..4ff7c833 100644 --- a/doc/md/git-bug_show.md +++ b/doc/md/git-bug_show.md @@ -7,7 +7,7 @@ Display the details of a bug Display the details of a bug ``` -git-bug show <id> [flags] +git-bug show [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_status.md b/doc/md/git-bug_status.md index 3814cc85..284c9257 100644 --- a/doc/md/git-bug_status.md +++ b/doc/md/git-bug_status.md @@ -7,7 +7,7 @@ Show the bug status Show the bug status ``` -git-bug status <id> [flags] +git-bug status [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_status_close.md b/doc/md/git-bug_status_close.md index 4660972a..a8e0f47b 100644 --- a/doc/md/git-bug_status_close.md +++ b/doc/md/git-bug_status_close.md @@ -7,7 +7,7 @@ Mark the bug as closed Mark the bug as closed ``` -git-bug status close <id> [flags] +git-bug status close [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_status_open.md b/doc/md/git-bug_status_open.md index 920bf66d..ac44e293 100644 --- a/doc/md/git-bug_status_open.md +++ b/doc/md/git-bug_status_open.md @@ -7,7 +7,7 @@ Mark the bug as open Mark the bug as open ``` -git-bug status open <id> [flags] +git-bug status open [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_title.md b/doc/md/git-bug_title.md index 22b40d65..62419866 100644 --- a/doc/md/git-bug_title.md +++ b/doc/md/git-bug_title.md @@ -7,7 +7,7 @@ Display a bug's title Display a bug's title ``` -git-bug title <id> [flags] +git-bug title [<id>] [flags] ``` ### Options diff --git a/doc/md/git-bug_title_edit.md b/doc/md/git-bug_title_edit.md index ee7fda02..781b0b9b 100644 --- a/doc/md/git-bug_title_edit.md +++ b/doc/md/git-bug_title_edit.md @@ -7,7 +7,7 @@ Edit a bug title Edit a bug title ``` -git-bug title edit <id> [flags] +git-bug title edit [<id>] [flags] ``` ### Options |