mirror of https://github.com/spf13/cobra.git
doc: Improve the `WithUsage` example.
This commit is contained in:
parent
4cba342aae
commit
399779240e
17
args_test.go
17
args_test.go
|
@ -560,6 +560,21 @@ func ExampleWithUsage() {
|
||||||
cmd := &Command{
|
cmd := &Command{
|
||||||
Use: "example <arg>",
|
Use: "example <arg>",
|
||||||
Args: WithUsage(ExactArgs(1)),
|
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 New Issue