diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-17 14:32:33 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-17 14:32:33 +0200 |
commit | cc086ebae99dfeb936d9397f4e3eedf5d37a97b1 (patch) | |
tree | 55978ec18816cd2a0c9cf20242688a880feba2f8 /commands | |
parent | dad61892cea320cd28c23c73fdf65a90404c6099 (diff) | |
download | git-bug-cc086ebae99dfeb936d9397f4e3eedf5d37a97b1.tar.gz |
commands: make "label" display the current labels
Diffstat (limited to 'commands')
-rw-r--r-- | commands/label add.go | 50 | ||||
-rw-r--r-- | commands/label.go | 52 |
2 files changed, 60 insertions, 42 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", - ) } |