Skip to content

fix: Update cli usage template for cobra feature parity #1463

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

Merged
merged 5 commits into from
May 16, 2022

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented May 16, 2022

This PR updates the custom usage template for feature parity with the default template used in Cobra.

I've restored the custom heading names and colorization.

Changes:

  • We now display Usage properly for subcommands
  • We now display "Global Flags" for all commands
  • We now display "Aliases" for aliased commands
  • Flags moved below Commands as per standard Cobra template

This is partially related to #1233 and #1403, but as suggested by @jsjoeio, split into a separate PR.

Fixes #1423

Example:
image

@mafredri mafredri self-assigned this May 16, 2022
@mafredri mafredri requested review from ammario, jsjoeio and a team May 16, 2022 08:32
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax seems fine but if you could quickly tidy up the template that would be nice 👍

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well, just some cleanup 👍

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. My bad for missing a few of these cases!

@Emyrk
Copy link
Member

Emyrk commented May 16, 2022

How does the template not have excessive newlines when sections are omitted? Is there something cleaning that up?

The Cobra one has to put conditional blocks on the same line to (what I assume) prevent the extra newlines: https://github.com/spf13/cobra/blob/master/command.go#L502-L525

Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh it's the {{- got it

@mafredri mafredri merged commit 6c1ef85 into main May 16, 2022
@mafredri mafredri deleted the mafredri/fix-cli-help branch May 16, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

coder state pull has useless help
5 participants