-
Notifications
You must be signed in to change notification settings - Fork 0
/
subcommand.go
45 lines (36 loc) · 824 Bytes
/
subcommand.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
42
43
44
45
/*
Copyright © 2022 Johnson Shi <Johnson.Shi@microsoft.com>
*/
package main
import (
"io"
"github.com/spf13/cobra"
)
type subcommandOpts struct {
stdin io.Reader
stdout io.Writer
stderr io.Writer
arg1 string
}
func newSubcommandCmd(stdin io.Reader, stdout io.Writer, stderr io.Writer, args []string) *cobra.Command {
opts := &subcommandOpts{
stdin: stdin,
stdout: stdout,
stderr: stderr,
}
cobraCmd := &cobra.Command{
Use: "subcommand",
Short: "TODO command description",
Example: `TODO command example`,
RunE: func(_ *cobra.Command, args []string) error {
return opts.run()
},
}
f := cobraCmd.Flags()
f.StringVar(&opts.arg1, "arg1", "", "TODO arg1 description")
cobraCmd.MarkFlagRequired("arg1")
return cobraCmd
}
func (opts *subcommandOpts) run() error {
return nil
}