Skip to content

Conversation

@thaJeztah
Copy link
Member

Cobra allows for aliases to be defined for a command, but only allows these
to be defined at the same level (for example, docker image ls as alias for
docker image list). Our CLI has some commands that are available both as a
top-level shorthand as well as docker <object> <verb> subcommands. For example,
docker ps is a shorthand for docker container ps / docker container ls.

This patch introduces a custom "aliases" annotation that can be used to print
all available aliases for a command. While this requires these aliases to be
defined manually, in practice the list of aliases rarely changes, so maintenance
should be minimal.

As a convention, we could consider the first command in this list to be the
canonical command, so that we can use this information to add redirects in
our documentation in future.

@codecov-commenter
Copy link

Codecov Report

Merging #32 (0f38acf) into main (b4dab44) will decrease coverage by 0.48%.
The diff coverage is 60.86%.

@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
- Coverage   64.84%   64.36%   -0.49%     
==========================================
  Files           4        4              
  Lines         532      550      +18     
==========================================
+ Hits          345      354       +9     
- Misses        129      138       +9     
  Partials       58       58              
Impacted Files Coverage Δ
clidocstool.go 51.47% <52.63%> (+0.45%) ⬆️
clidocstool_md.go 76.21% <100.00%> (-0.15%) ⬇️
clidocstool_yaml.go 58.30% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4dab44...0f38acf. Read the comment docs.

Cobra allows for aliases to be defined for a command, but only allows these
to be defined at the same level (for example, `docker image ls` as alias for
`docker image list`). Our CLI has some commands that are available both as a
top-level shorthand as well as `docker <object> <verb>` subcommands. For example,
`docker ps` is a shorthand for `docker container ps` / `docker container ls`.

This patch introduces a custom "aliases" annotation that can be used to print
all available aliases for a command. While this requires these aliases to be
defined manually, in practice the list of aliases rarely changes, so maintenance
should be minimal.

As a convention, we could consider the first command in this list to be the
canonical command, so that we can use this information to add redirects in
our documentation in future.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah marked this pull request as ready for review June 29, 2022 00:00
@thaJeztah thaJeztah requested a review from crazy-max June 29, 2022 00:00
@thaJeztah
Copy link
Member Author

Moved this one out of draft

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit 77abede into docker:main Jul 4, 2022
@thaJeztah thaJeztah deleted the custom_aliases branch July 4, 2022 16:20
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.

3 participants