aboutsummaryrefslogtreecommitdiffstats
path: root/commands/label.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-19 12:30:25 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-19 12:36:01 +0200
commit7f5922f905831a85ffee4c9226b65715899ba758 (patch)
treed18a29a2ec13706efa7f5e9efc9515a92cf4513d /commands/label.go
parent459bb8747d9e84493b8d04a3172e6758452a75b9 (diff)
downloadgit-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.go33
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",
+ )
}