docker / cli

The Docker CLI
Apache License 2.0
4.9k stars 1.92k forks source link

zsh completion breaks when optional arguments are combined (`-i -t` -> `-it`) #993

Open kenden opened 6 years ago

kenden commented 6 years ago

BUG REPORT INFORMATION

Description

docker zsh completion breaks when optional arguments are combined. Example, when -i and -t are combined to -it

This problem was reported here: https://github.com/robbyrussell/oh-my-zsh/issues/6710

Steps to reproduce the issue:

  1. Make sure you are using zsh and check that the docker autocomplete is enabled.
    Type docker then press tab. If it shows you:

    image   -- Manage images
    images  -- List images

    then docker zsh autocomplete is enabled.

  2. Type the following: docker run -it then press tab --> PROBLEM: A list of executables on the PATH is displayed instead of possible arguments to docker run

Describe the results you received:

When typing docker run -it and pressing tab, a list of executables on the PATH is displayed.

Describe the results you expected:

When typing docker run -it and pressing tab, I expect to get a list of possible arguments to docker run

Additional information you deem important (e.g. issue happens only occasionally):

When not combining options, it works fine. Ex, when typing docker run -i -t and pressing tab, I get:

02f9d6707661  -- 18.04           in ubuntu
0458a4468cbc  -- xenial-20180123 in ubuntu
3fd9065eaf02  -- latest          in alpine
4ea294712533  -- latest          in nate/dockviz
5b117edd0b76  -- 12.04           in ubuntu

Output of docker version:

$ docker version
Client:
 Version:   18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24
 Built: Wed Mar 21 23:06:22 2018
 OS/Arch:   darwin/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:  18.03.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   0520e24
  Built:    Wed Mar 21 23:14:32 2018
  OS/Arch:  linux/amd64
  Experimental: true

I tried using the current lastest version available at https://github.com/docker/cli/blob/ec412bdbb47b0cd84d85a0212c7160cec0ee9f02/contrib/completion/zsh/_docker (put the content of that file to ~/.oh-my-zsh/plugins/docker/_docker) with the same result.

Output of docker info:

$ docker info
Containers: 8
 Running: 1
 Paused: 0
 Stopped: 7
Images: 16
Server Version: 18.03.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.87-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: QOY4:456J:JD4J:E36Y:G6FJ:YAJS:K3HI:J23J:NLV2:OFCV:ZNOY:STQT
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 31
 Goroutines: 56
 System Time: 2018-04-10T08:07:26.055313Z
 EventsListeners: 2
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

Using docker for mac.

cpuguy83 commented 6 years ago

Not reproing here:

 ✗ docker run -it
-P  -- Publish all exposed ports
-a  -- Attach to stdin, stdout or stderr
-c  -- CPU shares (relative weight)
-d  -- Detached mode: leave the container running in the background
-e  -- Environment variables
-h  -- Container host name
-l  -- Container metadata
-m  -- Memory limit
-p  -- Expose a container's port to the host
-u  -- Username or UID
-v  -- Bind mount a volume
-w  -- Working directory inside the container

If I add a space after the -it, then attempt tab completion I see a list of all the images. Are we sure oh-my-zsh is up to date?

thaJeztah commented 6 years ago

Perhaps related to the "short-stacking option", which is disabled by default; https://github.com/docker/cli/blob/ec412bdbb47b0cd84d85a0212c7160cec0ee9f02/contrib/completion/zsh/_docker#L41-L43

See https://github.com/moby/moby/pull/17124

kenden commented 6 years ago

@thaJeztah thanks, that's it. I uncommentted:

#  zstyle ':completion:*:*:docker-*:*' option-stacking yes 

on line https://github.com/docker/cli/blob/ec412bdbb47b0cd84d85a0212c7160cec0ee9f02/contrib/completion/zsh/_docker#L43

and docker run -it now autocompletes as (I think) it should.

The comment as to why this is disabled is here: https://github.com/moby/moby/pull/17124#issuecomment-150518700

kenden commented 6 years ago

Should we create an issue to enable autocomplete by default (or rename this issue for that) Between this, this, this and this it seems there is a demand for it.

ratijas commented 3 years ago

Duplicate of, or rather duplicated by https://github.com/docker/cli/issues/2625.