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

Closed
marwan-at-work opened this issue Jun 5, 2024 · 10 comments · Fixed by #2000
Closed
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.

@deregtd
Copy link

deregtd commented Oct 29, 2024

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

@dearchap
Copy link
Contributor

dearchap commented Nov 1, 2024

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

@deregtd
Copy link

deregtd commented Nov 1, 2024

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

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

Successfully merging a pull request may close this issue.

6 participants