spf13 / cobra

A Commander for modern Go CLI interactions
https://cobra.dev
Apache License 2.0
38.41k stars 2.86k forks source link

Fix --version help and output for plugins #2180

Closed nirs closed 1 month ago

nirs commented 3 months ago

When writing a plugin and setting CommandDisplayNameAnnotation you want the display name to be used in help text. This did not work when setting command Version since the help text and version templates used the command Name().

This change makes command DisplayName() public, so it can be used in templates or other code that want to use this value, and fix --version help text and template to use the command DisplayName().

nirs commented 3 months ago

Lint errors are fixed in #2181, go 1.23 tests added in #2182. I rebased on both temporarily to verify all tests and go version with this change.

marckhouzam commented 3 months ago

I’ll let you rebase this one first @nirs

nirs commented 3 months ago

@marckhouzam can be merged now

nirs commented 2 months ago

@marckhouzam can you check gain?

marckhouzam commented 1 month ago

@nirs On the last commit you mention

    This may cause issues for programs processing the output if the program
    assumes that the name of the program never contains spaces, and the
    version string is the third word. Users can use their own template if
    they think that this is an issue.

    If we think that this can break users we can drop this change and let
    users opt in by setting their own template using `{{.DisplayName}}`.

I'm not concerned because this will only affect programs that use the CommandDisplayNameAnnotation annotation, in which case your change is correct.