Skip to content

cli: print full command as aliases in usage output - #3693

Merged
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:cli_usage_aliases
Jun 28, 2022
Merged

cli: print full command as aliases in usage output#3693
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:cli_usage_aliases

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Jun 28, 2022

Copy link
Copy Markdown
Member

The default output for Cobra aliases only shows the subcommand as alias, which
is not very intuitive. This patch changes the output to print the full command
as it would be called by the user.

Note that there's still some improvements to be made; due to how aliases must be
set-up in Cobra, aliases at different "levels" are still not shown. So for example,
docker ps --help will not show docker container ps as alias, and vice-versa.
This will require additional changes, and can possibly be resolved using custom
metadata/annotations.

Before this patch:

docker container ls --help
Usage: docker container ls [OPTIONS]
List containers
Aliases:
ls, ps, list

After this patch:

docker container ls --help
Usage: docker container ls [OPTIONS]
List containers
Aliases:
docker container ls, docker container ps, docker container list

- Description for the changelog

Usage output for command aliases now prints the full name for each alias.

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter

codecov-commenter commented Jun 28, 2022

Copy link
Copy Markdown

Codecov Report

Merging #3693 (4dead11) into master (b496125) will increase coverage by 0.00%.
The diff coverage is 90.90%.

@@ Coverage Diff @@## master #3693 +/- ##
=======================================
Coverage 59.01% 59.02% =======================================
Files 289 289 Lines 24623 24645 +22 =======================================
+ Hits 14532 14546 +14 - Misses 9218 9225 +7 - Partials 873 874 +1 

The default output for Cobra aliases only shows the subcommand as alias, which
is not very intuitive. This patch changes the output to print the full command
as it would be called by the user.
Note that there's still some improvements to be made; due to how aliases must be
set-up in Cobra, aliases at different "levels" are still not shown. So for example,
`docker ps --help` will not show `docker container ps` as alias, and vice-versa.
This will require additional changes, and can possibly be resolved using custom
metadata/annotations.
Before this patch:
docker container ls --help
Usage: docker container ls [OPTIONS]
List containers
Aliases:
ls, ps, list
After this patch:
docker container ls --help
Usage: docker container ls [OPTIONS]
List containers
Aliases:
docker container ls, docker container ps, docker container list
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah marked this pull request as ready for review June 28, 2022 09:22
@thaJeztahthaJeztah added this to the 22.06.0 milestone Jun 28, 2022
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

@crazy-max@ndeloof@rumpl PTAL

(follow-up is in #3694, but also want to make some changes to our YAML generator)

@crazy-maxcrazy-max 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.

SGTM

@thaJeztah
thaJeztah merged commit 05d288e into docker:masterJun 28, 2022
@thaJeztah
thaJeztah deleted the cli_usage_aliases branch June 28, 2022 15:31
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@thaJeztah@codecov-commenter@rumpl@crazy-max