Skip to content

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

Merged
mafredri merged 5 commits into
mainfrom
mafredri/fix-cli-help
May 16, 2022
Merged

mafredri merged 5 commits into
mainfrom
mafredri/fix-cli-help

Conversation

@mafredri

@mafredri mafredri commented May 16, 2022 •

Copy link
Copy Markdown
Member

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 a team, ammario and jsjoeio May 16, 2022 08:32

@deansheather deansheather left a comment

Copy link
Copy Markdown
Collaborator

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 👍

Comment thread cli/root.go Resolved

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

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 👍

@kylecarbs kylecarbs left a comment

Copy link
Copy Markdown
Member

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

Emyrk commented May 16, 2022 •

Copy link
Copy Markdown
Member

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

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

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