-
Notifications
You must be signed in to change notification settings - Fork 0
/
targetCommand.go
41 lines (36 loc) · 1014 Bytes
/
targetCommand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"github.com/pgavlin/dawn/label"
"github.com/spf13/cobra"
)
type targetCommand struct {
Use string
Short string
Long string
Run func(label *label.Label, args []string) error
ValidArgsFunction func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective)
}
func newTargetCommand(cmd *targetCommand) *cobra.Command {
run := cmd.Run
cobraCmd := &cobra.Command{
Use: cmd.Use,
Short: cmd.Short,
Long: cmd.Long,
Args: cobra.ArbitraryArgs,
SilenceUsage: true,
RunE: func(_ *cobra.Command, args []string) error {
label, args, err := work.labelArg(args)
if err != nil {
return err
}
return run(label, args)
},
ValidArgsFunction: cmd.ValidArgsFunction,
}
if cobraCmd.ValidArgsFunction == nil {
cobraCmd.ValidArgsFunction = work.validLabels
}
cobraCmd.PersistentFlags().SetInterspersed(false)
cobraCmd.Flags().SetInterspersed(false)
return cobraCmd
}