From 399779240ee4fd3565dfc8dd826b160c3e7e5734 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 12 Jan 2024 09:13:41 +0100 Subject: [PATCH] doc: Improve the `WithUsage` example. --- args_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/args_test.go b/args_test.go index 077a2f3f..ec17fdc7 100644 --- a/args_test.go +++ b/args_test.go @@ -560,6 +560,21 @@ func ExampleWithUsage() { cmd := &Command{ Use: "example ", 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 [flags] + // + // Flags: + // -h, --help help for example }