diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-28 16:10:14 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-28 16:10:14 -0500 |
| commit | b06eba3df09a8fcd777b8fe350c2b184758963d1 (patch) | |
| tree | 0a2ad3aa9537c0457688b7325a3858c1b328bea2 /vendor/github.com/google/subcommands/README.md | |
| parent | Add version cmd to docs (diff) | |
| download | cli-b06eba3df09a8fcd777b8fe350c2b184758963d1.zip | |
Use checkmate for tests
Diffstat (limited to 'vendor/github.com/google/subcommands/README.md')
| -rw-r--r-- | vendor/github.com/google/subcommands/README.md | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/vendor/github.com/google/subcommands/README.md b/vendor/github.com/google/subcommands/README.md deleted file mode 100644 index c769745..0000000 --- a/vendor/github.com/google/subcommands/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# subcommands # - -[](https://godoc.org/github.com/google/subcommands) -Subcommands is a Go package that implements a simple way for a single command to -have many subcommands, each of which takes arguments and so forth. - -This is not an official Google product. - -## Usage ## - -Set up a 'print' subcommand: - -```go -import ( - "context" - "flag" - "fmt" - "os" - "strings" - - "github.com/google/subcommands" -) - -type printCmd struct { - capitalize bool -} - -func (*printCmd) Name() string { return "print" } -func (*printCmd) Synopsis() string { return "Print args to stdout." } -func (*printCmd) Usage() string { - return `print [-capitalize] <some text>: - Print args to stdout. -` -} - -func (p *printCmd) SetFlags(f *flag.FlagSet) { - f.BoolVar(&p.capitalize, "capitalize", false, "capitalize output") -} - -func (p *printCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { - for _, arg := range f.Args() { - if p.capitalize { - arg = strings.ToUpper(arg) - } - fmt.Printf("%s ", arg) - } - fmt.Println() - return subcommands.ExitSuccess -} -``` - -Register using the default Commander, also use some built in subcommands, -finally run Execute using ExitStatus as the exit code: - -```go -func main() { - subcommands.Register(subcommands.HelpCommand(), "") - subcommands.Register(subcommands.FlagsCommand(), "") - subcommands.Register(subcommands.CommandsCommand(), "") - subcommands.Register(&printCmd{}, "") - - flag.Parse() - ctx := context.Background() - os.Exit(int(subcommands.Execute(ctx))) -} -``` - |