Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marwan-at-work opened this issue Jun 5, 2024 · 7 comments
Labels
area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this

Comments

@marwan-at-work
Copy link
Contributor

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 marwan-at-work added status/triage maintainers still need to look into this area/v3 relates to / is being considered for v3 labels Jun 5, 2024
@dearchap
Copy link
Contributor

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

@decentral1se
Copy link

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
Copy link

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

@mahadzaryab1
Copy link
Contributor

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

@dearchap
Copy link
Contributor

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

@gerardnico
Copy link

gerardnico commented Sep 5, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

5 participants