cli
cli copied to clipboard
Remove [command [command options]] from help text if there are no sub commands
Hi there, I think it would help readability a lot if cli/v3 can check for subcommands first before printing the help of a command.
For example, right now this is the help that I get:
NAME:
app cmd1 cmd2 - does something cool
USAGE:
app cmd1 cmd2 [command [command options]] <myArgUsage>
OPTIONS:
--flag value (default: 1)
--help, -h show help (default: false)
Note that cmd2 has no sub-commands which makes it distracting from reading and understanding the USAGE. So what I'd love to instead see is:
NAME:
app cmd1 cmd2 - does something cool
USAGE:
app cmd1 cmd2 <myArgUsage>
OPTIONS:
--flag value (default: 1)
--help, -h show help (default: false)
@marwan-at-work want to make a PR for me to review for this ?
Noticed this as well, thanks for raising @marwan-at-work. In app cmd1 cmd2 <myArgUsage> what do you expect if your cmd1/cmd2 accepts options? Does it then need to be something along the lines of app cmd1 cmd2 [command options] <myArgUsage>? I'm not sure.
FYI for whoever, the work-around for the time being: override with UsageText.
@dearchap I'm interested in working on this. Do you have any ideas on how we can address this? The help command gets added as a subcommand so we can't simply check for Commands != nil.
You could probably add a helper function in Command to list number of non help commands. That function needs to be exported for use in the template
From my understanding, when I check the help template, the text [command [command options]] is added when there is a command. ie
{{if .Commands}} command [command options]{{end}}
When I print a command help, I get always the help command
COMMANDS:
help, h Shows a list of commands or help for one command
If we could just disable it, the problem would be solved, no? Yeah not easy if we want to use it. May be a
{{if .CommandsWithoutHelp}} command [command options]{{end}}
Note that as quick fix for a leaf command, the HideHelp: true (v3) just get rid of it.
Similarly, if you incorrectly type a command, the generated help for the invalid command has the extra "command" suggestion, whereas the base help does not (correctly). Examples:
$ uc kcat help
NAME:
uc kcat - Wraps the kcat kafka tool
USAGE:
uc kcat [command options] -- [Arguments passed directly to kcat (-L, -P, etc.)]
OPTIONS:
--cluster value, -c value Specify a cluster (Prod, DR, Local, Dev)
--help, -h show help
However, this shows the extra (wrong) "command" text.
$ uc kcat --dsds
Incorrect Usage: flag provided but not defined: -dsds
NAME:
uc kcat - Wraps the kcat kafka tool
USAGE:
uc kcat command [command options] -- [Arguments passed directly to kcat (-L, -P, etc.)]
COMMANDS:
help, h Shows a list of commands or help for one command
OPTIONS:
--cluster value, -c value Specify a cluster (Dev, Prod, DR, Local)
--help, -h show help
@deregtd Would you like to test the PR and report back ?
Ah unfortunately I haven't moved to v3 yet, so I can't. :(