Skip to content
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

Add zsh completion for new 'docker container' subcommands #27888

Merged

Conversation

sdurrheimer
Copy link
Contributor

@sdurrheimer sdurrheimer commented Oct 30, 2016

ref. #26025

Same logic as @albers #27579 PR, splitting commits for better review session.

@vincentbernat

@sdurrheimer sdurrheimer force-pushed the zsh-completion-container-subcommand branch 2 times, most recently from 2365583 to 97ab0a6 Compare October 30, 2016 21:30
@thaJeztah thaJeztah added this to the 1.13.0 milestone Oct 30, 2016
@thaJeztah
Copy link
Member

Thank you @sdurrheimer!!

Also /cc @vdemeester @tianon @mlaventure

@cpuguy83
Copy link
Member

Looks ok, but doesn't complete docker container.
We can probably squash this down a bit.

@sdurrheimer
Copy link
Contributor Author

@cpuguy83 Hum, the docker container completion comes from the docker --help output.

Hum right, the docker --help has changed, commands are now split into two categories: Management Commands and Commands. We might need a fix in the zsh completion to handle that.

@cpuguy83
Copy link
Member

Ah, that may be why -- I'm not on latest, just replaced my normal completion with this here.

@albers
Copy link
Member

albers commented Oct 31, 2016

@sdurrheimer There's also #27468 pending, which might not be solvable by parsing help output.
The aliases should not appear in completion but be considered when they are used.

@sdurrheimer
Copy link
Contributor Author

@albers It won't be a problem, short aliases will not be handled the same way as main commands, I will handle that when #27468 will be merge.

@sdurrheimer
Copy link
Contributor Author

@vincentbernat What do you think about the 1st level completion of docker commands, should we keep parsing the docker --help output, or should we switch to a hard list ?

@vincentbernat
Copy link
Contributor

I don't have a strong opinion on this. If you need help to parse the new docker --help, I can do that if you copy/paste the current output in a gist.

@sdurrheimer
Copy link
Contributor Author

@vincentbernat They introduce a new Management Commands: section, and there is also the inspect comment that is now on two lines which gives false results.

Here you go

$ docker

Usage:  docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/home/steve/.docker")
  -D, --debug              Enable debug mode
      --help               Print usage
  -H, --host list          Daemon socket(s) to connect to (default [])
  -l, --log-level string   Set the logging level (debug, info, warn, error, fatal) (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/home/steve/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/home/steve/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/home/steve/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  service     Manage services
  swarm       Manage Swarm
  system      Manage Docker
  volume      Manage volumes

Commands:
  attach      Attach to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker object(s) (e.g. container, image, volume,
network, node, service, or task) identified by name or ID
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Tag an image into a repository
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

@vincentbernat
Copy link
Contributor

Thanks. I propose the following:

_docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/ ##/:})

This is a bit simpler (and works with older versions too). It also deals with the inspect line being cut (but the description should simply be shortened, I have created #28045 for that).

Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
…command

Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
@sdurrheimer sdurrheimer force-pushed the zsh-completion-container-subcommand branch from 97ab0a6 to 94863d8 Compare November 4, 2016 07:55
@sdurrheimer
Copy link
Contributor Author

@vincentbernat Thank you very much, change added to the PR.

@sdurrheimer
Copy link
Contributor Author

docker image and docker system PR waiting behind the scene.

@vieux
Copy link
Contributor

vieux commented Nov 8, 2016

LGTM

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐮
@sdurrheimer one question though : docker con<tab> doesn't propose container, is this intended ?

@sdurrheimer
Copy link
Contributor Author

@vdemeester Same as for @cpuguy83, are you using a docker 1.13 client when doing the test ? First level commands are completed/cached from the docker --help output.

@vdemeester
Copy link
Member

@sdurrheimer arg you're right, my client was 1.12.2 😓 It's working as expected once I switch 👼

@vdemeester vdemeester merged commit d46c710 into moby:master Nov 8, 2016
@sdurrheimer sdurrheimer deleted the zsh-completion-container-subcommand branch November 8, 2016 10:29
Sign up for free to 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.

8 participants