diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-19 12:30:25 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-19 12:36:01 +0200 |
commit | 7f5922f905831a85ffee4c9226b65715899ba758 (patch) | |
tree | d18a29a2ec13706efa7f5e9efc9515a92cf4513d /commands/label.go | |
parent | 459bb8747d9e84493b8d04a3172e6758452a75b9 (diff) | |
download | git-bug-7f5922f905831a85ffee4c9226b65715899ba758.tar.gz |
rework all the commands to use cobra as a parser
Diffstat (limited to 'commands/label.go')
-rw-r--r-- | commands/label.go | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/commands/label.go b/commands/label.go index ad3a388b..07dabfe8 100644 --- a/commands/label.go +++ b/commands/label.go @@ -2,23 +2,15 @@ package commands import ( "errors" - "flag" "fmt" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/bug/operations" - "github.com/MichaelMure/git-bug/repository" + "github.com/spf13/cobra" ) -var labelFlagSet = flag.NewFlagSet("label", flag.ExitOnError) - -var ( - labelRemove = newFlagSet.Bool("r", false, "Remove a label") -) - -func runLabel(repo repository.Repo, args []string) error { - labelFlagSet.Parse(args) - args = labelFlagSet.Args() +var labelRemove bool +func runLabel(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("You must provide a bug id") } @@ -46,7 +38,7 @@ func runLabel(repo repository.Repo, args []string) error { for _, arg := range args[1:] { label := bug.Label(arg) - if *labelRemove { + if labelRemove { // check for duplicate if labelExist(removed, label) { fmt.Printf("label \"%s\" is a duplicate\n", arg) @@ -100,9 +92,16 @@ func labelExist(labels []bug.Label, label bug.Label) bool { return false } -var labelCmd = &Command{ - Description: "Manipulate bug's label", - Usage: "<id> [<option>...] [<label>...]", - flagSet: labelFlagSet, - RunMethod: runLabel, +var labelCmd = &cobra.Command{ + Use: "label [<option>...] <id> [<label>...]", + Short: "Manipulate bug's label", + RunE: runLabel, +} + +func init() { + rootCmd.AddCommand(labelCmd) + + labelCmd.Flags().BoolVarP(&labelRemove, "remove", "r", false, + "Remove a label", + ) } |