doc: Improve the WithUsage example.

This commit is contained in:
Florian Forster 2024-01-12 09:13:41 +01:00
parent 4cba342aae
commit 399779240e

View file

@ -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
} }