diff options
-rw-r--r-- | commands/label add.go | 50 | ||||
-rw-r--r-- | commands/label.go | 52 | ||||
-rw-r--r-- | doc/man/git-bug-label.1 | 10 | ||||
-rw-r--r-- | doc/md/git-bug.md | 2 | ||||
-rw-r--r-- | doc/md/git-bug_label.md | 9 | ||||
-rw-r--r-- | misc/bash_completion/git-bug | 3 |
6 files changed, 68 insertions, 58 deletions
diff --git a/commands/label add.go b/commands/label add.go new file mode 100644 index 00000000..6eefa646 --- /dev/null +++ b/commands/label add.go @@ -0,0 +1,50 @@ +package commands + +import ( + "errors" + "fmt" + + "github.com/MichaelMure/git-bug/cache" + "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) + if err != nil { + return err + } + + changes, err := b.ChangeLabels(add, nil) + if err != nil { + return err + } + + for _, change := range changes { + fmt.Println(change) + } + + return b.Commit() +} + +var labelAddCmd = &cobra.Command{ + Use: "add <id> [<label>...]", + Short: "Add a label to a bug", + RunE: runLabelAdd, +} + +func init() { + // labelCmd.AddCommand(labelAddCmd) +} diff --git a/commands/label.go b/commands/label.go index 37013f3f..c693f82c 100644 --- a/commands/label.go +++ b/commands/label.go @@ -5,19 +5,16 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/operations" "github.com/spf13/cobra" ) -var labelRemove bool - func runLabel(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errors.New("You must provide a bug id") + if len(args) > 1 { + return errors.New("Only one bug id is supported") } - if len(args) == 1 { - return errors.New("You must provide a label") + if len(args) == 0 { + return errors.New("You must provide a bug id") } backend, err := cache.NewRepoCache(repo) @@ -28,48 +25,23 @@ func runLabel(cmd *cobra.Command, args []string) error { prefix := args[0] - var add, remove []string - - if labelRemove { - remove = args[1:] - } else { - add = args[1:] - } - b, err := backend.ResolveBugPrefix(prefix) if err != nil { return err } - changes, err := b.ChangeLabels(add, remove) - - for _, change := range changes { - switch change.Status { - case operations.LabelChangeAdded: - fmt.Printf("label %s added\n", change.Label) - case operations.LabelChangeRemoved: - fmt.Printf("label %s removed\n", change.Label) - case operations.LabelChangeDuplicateInOp: - fmt.Printf("label %s is a duplicate\n", change.Label) - case operations.LabelChangeAlreadySet: - fmt.Printf("label %s was already set\n", change.Label) - case operations.LabelChangeDoesntExist: - fmt.Printf("label %s doesn't exist on this bug\n", change.Label) - default: - panic(fmt.Sprintf("unknown label change status %v", change.Status)) - } - } + snap := b.Snapshot() - if err != nil { - return err + for _, l := range snap.Labels { + fmt.Println(l) } - return b.Commit() + return nil } var labelCmd = &cobra.Command{ - Use: "label <id> [<label>...]", - Short: "Manipulate bug's label", + Use: "label <id>", + Short: "Display a bug labels", RunE: runLabel, } @@ -77,8 +49,4 @@ func init() { RootCmd.AddCommand(labelCmd) labelCmd.Flags().SortFlags = false - - labelCmd.Flags().BoolVarP(&labelRemove, "remove", "r", false, - "Remove a label", - ) } diff --git a/doc/man/git-bug-label.1 b/doc/man/git-bug-label.1 index a1b3ea89..520551b8 100644 --- a/doc/man/git-bug-label.1 +++ b/doc/man/git-bug-label.1 @@ -5,25 +5,21 @@ .SH NAME .PP -git\-bug\-label \- Manipulate bug's label +git\-bug\-label \- Display a bug labels .SH SYNOPSIS .PP -\fBgit\-bug label <id> [<label>\&...] [flags]\fP +\fBgit\-bug label <id> [flags]\fP .SH DESCRIPTION .PP -Manipulate bug's label +Display a bug labels .SH OPTIONS .PP -\fB\-r\fP, \fB\-\-remove\fP[=false] - Remove a label - -.PP \fB\-h\fP, \fB\-\-help\fP[=false] help for label diff --git a/doc/md/git-bug.md b/doc/md/git-bug.md index 6a102c20..6825f481 100644 --- a/doc/md/git-bug.md +++ b/doc/md/git-bug.md @@ -23,7 +23,7 @@ git-bug [flags] * [git-bug add](git-bug_add.md) - Create a new bug * [git-bug commands](git-bug_commands.md) - Display available commands * [git-bug comment](git-bug_comment.md) - Show a bug's comments -* [git-bug label](git-bug_label.md) - Manipulate bug's label +* [git-bug label](git-bug_label.md) - Display a bug labels * [git-bug ls](git-bug_ls.md) - List bugs * [git-bug pull](git-bug_pull.md) - Pull bugs update from a git remote * [git-bug push](git-bug_push.md) - Push bugs update to a git remote diff --git a/doc/md/git-bug_label.md b/doc/md/git-bug_label.md index eff99f16..bf100dbc 100644 --- a/doc/md/git-bug_label.md +++ b/doc/md/git-bug_label.md @@ -1,20 +1,19 @@ ## git-bug label -Manipulate bug's label +Display a bug labels ### Synopsis -Manipulate bug's label +Display a bug labels ``` -git-bug label <id> [<label>...] [flags] +git-bug label <id> [flags] ``` ### Options ``` - -r, --remove Remove a label - -h, --help help for label + -h, --help help for label ``` ### SEE ALSO diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 77e2d350..3e1ba26f 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -361,9 +361,6 @@ _git-bug_label() flags_with_completion=() flags_completion=() - flags+=("--remove") - flags+=("-r") - local_nonpersistent_flags+=("--remove") must_have_one_flag=() must_have_one_noun=() |