docker / cli

The Docker CLI
Apache License 2.0
4.95k stars 1.93k forks source link

docker doesn't error out on `docker missing-subcommand --version` #3833

Open ojab opened 2 years ago

ojab commented 2 years ago

Description

AFAIU it's impossible to check if plugin is installed/subcommand is available (docker compose, for example), because

$ docker asdasd --version
Docker version 20.10.20, build 9fdeb9c

Without --version flag it correctly reports that subcommand is not avaiable.

Reproduce

  1. docker asdasd --version without asdasd plugin installed
  2. Docker version 20.10.20, build 9fdeb9c

Expected behavior

$ docker asdasd 
docker: 'asdasd' is not a docker command.
See 'docker --help'
$ docker asdasd --version
docker: 'asdasd' is not a docker command.
See 'docker --help'

docker version

Client: Docker Engine - Community
 Version:           20.10.20
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        9fdeb9c
 Built:             Tue Oct 18 18:21:27 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.20
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       03df974
  Built:            Tue Oct 18 18:19:04 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
  compose: Docker Compose (Docker Inc., v2.12.2)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 3
  Running: 1
  Paused: 0
  Stopped: 2
 Images: 6
 Server Version: 20.10.20
 Storage Driver: btrfs
  Build Version: Btrfs v6.0
  Library Version: 102
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1c90a442489720eec95342e1789ee8a5e1b9536f
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.19.15-301.fc37.x86_64
 Operating System: Fedora Linux 37 (Workstation Edition)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.32GiB
 Name: ojab-laptop
 ID: H5QF:PZEA:G5XP:YIOW:YMAC:I7T5:3LJV:PEHB:VMTS:3SBY:F52F:7ZP4
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

No response

bsousaa commented 2 years ago

Running docker info returns the list of installed plugins. See below:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
  compose: Docker Compose (Docker Inc., v2.12.2)
  scan: Docker Scan (Docker Inc., v0.17.0)
...
ojab commented 2 years ago

yeah, but IMHO --version should still fail in this case, so we can easily check if plugin is installed without grepping.

bsousaa commented 2 years ago

Right and agree. I'm labelling as an enhancement. Thanks!

vahnrr commented 1 year ago

After looking into this, it seems to come from cobra's Command.Execute() intended behaviour. Which starts by handling --help, then --version, then the command's arguments (e.g. your asdasd).

Docker CLI could manually check for invalid arguments before calling cobra's Command.Execute() but that would defeat the purpose of relying on cobra, since we'd be reinventing the wheel on subcommand checks.

thaJeztah commented 1 year ago

This is also (slightly?) related to;

There's a work-in-progress PR for that issue, but not sure if the fix is correct