Skip to content

Commit

Permalink
doc: Improve the WithUsage example.
Browse files Browse the repository at this point in the history
  • Loading branch information
octo committed Jan 12, 2024
1 parent 4cba342 commit 3997792
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3997792

Please sign in to comment.