From 33db14a48bf1893422ba8ee2f0b898760a9d1737 Mon Sep 17 00:00:00 2001 From: Marco Molteni Date: Sun, 19 Jan 2020 19:38:19 +0100 Subject: [PATCH 1/3] parse: fix typo in comment --- parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse.go b/parse.go index 3fcf08a..db9c443 100644 --- a/parse.go +++ b/parse.go @@ -129,7 +129,7 @@ type Parser struct { version string description string - // the following fields change curing processing of command line arguments + // the following field changes during processing of command line arguments lastCmd *command } From cfd894f446f356ed1c0fb37d88aee8c34bb4e40c Mon Sep 17 00:00:00 2001 From: Marco Molteni Date: Sun, 19 Jan 2020 19:40:53 +0100 Subject: [PATCH 2/3] usage: if the program supports subcommands, mention it --- example_test.go | 2 +- usage.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/example_test.go b/example_test.go index ea123e4..be3cd12 100644 --- a/example_test.go +++ b/example_test.go @@ -193,7 +193,7 @@ func Example_helpTextWithSubcommand() { MustParse(&args) // output: - // Usage: example [--verbose] + // Usage: example [--verbose] [] // // Options: // --verbose diff --git a/usage.go b/usage.go index 57935fd..b07280b 100644 --- a/usage.go +++ b/usage.go @@ -88,6 +88,13 @@ func (p *Parser) writeUsageForCommand(w io.Writer, cmd *command) { fmt.Fprint(w, spec.placeholder) } } + + // if the program supports subcommands and the command-line doesn't contain any, + // give a hint to the user about the existence of these subcommands. + if len(p.cmd.subcommands) > 0 && p.cmd == cmd { + fmt.Fprint(w, " []") + } + fmt.Fprint(w, "\n") } From 9f5522668a8d573c5d5dbe6ee0584f395fba3806 Mon Sep 17 00:00:00 2001 From: Marco Molteni Date: Thu, 23 Jan 2020 16:35:45 +0100 Subject: [PATCH 3/3] address review comments --- usage.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/usage.go b/usage.go index b07280b..7ee68da 100644 --- a/usage.go +++ b/usage.go @@ -89,9 +89,8 @@ func (p *Parser) writeUsageForCommand(w io.Writer, cmd *command) { } } - // if the program supports subcommands and the command-line doesn't contain any, - // give a hint to the user about the existence of these subcommands. - if len(p.cmd.subcommands) > 0 && p.cmd == cmd { + // if the program supports subcommands, give a hint to the user about their existence + if len(cmd.subcommands) > 0 { fmt.Fprint(w, " []") }