bug_label_rm.go

 1package bugcmd
 2
 3import (
 4	"github.com/spf13/cobra"
 5
 6	"github.com/MichaelMure/git-bug/commands/execenv"
 7	"github.com/MichaelMure/git-bug/util/text"
 8)
 9
10func newBugLabelRmCommand() *cobra.Command {
11	env := execenv.NewEnv()
12
13	cmd := &cobra.Command{
14		Use:     "rm [BUG_ID] LABEL...",
15		Short:   "Remove a label from a bug",
16		PreRunE: execenv.LoadBackend(env),
17		RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
18			return runBugLabelRm(env, args)
19		}),
20		ValidArgsFunction: BugAndLabelsCompletion(env, false),
21	}
22
23	return cmd
24}
25
26func runBugLabelRm(env *execenv.Env, args []string) error {
27	b, args, err := ResolveSelected(env.Backend, args)
28	if err != nil {
29		return err
30	}
31
32	removed := args
33
34	changes, _, err := b.ChangeLabels(nil, text.CleanupOneLineArray(removed))
35
36	for _, change := range changes {
37		env.Out.Println(change)
38	}
39
40	if err != nil {
41		return err
42	}
43
44	return b.Commit()
45}