cli icon indicating copy to clipboard operation
cli copied to clipboard

Remove [command [command options]] from help text if there are no sub commands

Open marwan-at-work opened this issue 1 year ago • 7 comments

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 avatar Jun 05 '24 16:06 marwan-at-work

@marwan-at-work want to make a PR for me to review for this ?

dearchap avatar Jun 27 '24 01:06 dearchap

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.

decentral1se avatar Jul 09 '24 14:07 decentral1se

FYI for whoever, the work-around for the time being: override with UsageText.

decentral1se avatar Jul 09 '24 19:07 decentral1se

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

mahadzaryab1 avatar Aug 20 '24 01:08 mahadzaryab1

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

dearchap avatar Aug 20 '24 02:08 dearchap

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

gerardnico avatar Sep 05 '24 13:09 gerardnico

Note that as quick fix for a leaf command, the HideHelp: true (v3) just get rid of it.

gerardnico avatar Sep 05 '24 14:09 gerardnico

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 avatar Oct 29 '24 17:10 deregtd

@deregtd Would you like to test the PR and report back ?

dearchap avatar Nov 01 '24 00:11 dearchap

Ah unfortunately I haven't moved to v3 yet, so I can't. :(

deregtd avatar Nov 01 '24 01:11 deregtd