mirror of
https://github.com/spf13/cobra
synced 2024-11-04 12:57:14 +00:00
doc: Improve the WithUsage
example.
This commit is contained in:
parent
4cba342aae
commit
399779240e
1 changed files with 16 additions and 1 deletions
17
args_test.go
17
args_test.go
|
@ -560,6 +560,21 @@ func ExampleWithUsage() {
|
|||
cmd := &Command{
|
||||
Use: "example <arg>",
|
||||
Args: WithUsage(ExactArgs(1)),
|
||||
Run: func(*Command, []string) {
|
||||
panic("not reached")
|
||||
},
|
||||
}
|
||||
_ = cmd // ignore unused
|
||||
|
||||
cmd.SetArgs([]string{"1", "2"})
|
||||
err := cmd.Execute()
|
||||
fmt.Print(err)
|
||||
|
||||
// Output:
|
||||
// accepts 1 arg(s), received 2
|
||||
//
|
||||
// Usage:
|
||||
// example <arg> [flags]
|
||||
//
|
||||
// Flags:
|
||||
// -h, --help help for example
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue