Commit Graph

45 Commits

Author SHA1 Message Date
a85098e5f0 Improve error handling of commands run against unsupported daemon
The current error-handling only checked for version annotations
on the subcommand itself, but did not check the top-level command.

This patch always traverses the command path (parents), and
prints an error if the command is not supported.

Before this change:

    $ docker service
    Usage:	docker service COMMAND

    Manage services

    Options:
          --help   Print usage

    Commands:
      create      Create a new service
      inspect     Display detailed information on one or more services
      ls          List services
      ps          List the tasks of one or more services
      rm          Remove one or more services
      scale       Scale one or multiple replicated services
      update      Update a service

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

    $ docker service ls
    ID                  NAME                MODE                REPLICAS            IMAGE

After this change:

    $ DOCKER_API_VERSION=1.12 docker service
    docker service requires API version 1.24, but the Docker daemon API version is 1.12

    $ DOCKER_API_VERSION=1.12 docker service ls
    docker service ls requires API version 1.24, but the Docker daemon API version is 1.12

    $ DOCKER_API_VERSION=1.24 docker plugin --help
    docker plugin requires API version 1.25, but the Docker daemon API version is 1.24

    $ DOCKER_API_VERSION=1.25 docker plugin upgrade --help
    docker plugin upgrade requires API version 1.26, but the Docker daemon API version is 1.25

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 998950a9f4
Component: cli
2017-03-16 13:45:50 +01:00
1efe06c1d3 Hide command options that are related to Windows
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
Upstream-commit: e398a78466
Component: cli
2017-03-12 08:47:17 +02:00
d1cc836571 cmd: docker: fix TestDaemonCommand
In more recent versions of Cobra, `--help` parsing is done before
anything else resulting in TestDaemonCommand not actually passing. I'm
actually unsure if this test ever passed since it appears that !daemon
is not being run as part of the test suite.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
Upstream-commit: aa74f27866
Component: cli
2017-03-05 15:26:49 +11:00
0ea3cc9974 Additional experimental features in non-experimental mode error handling
This fix is the follow up of the last commit.
In this fix:
1. If any of the parents of a command has tags, then this command's
`Args` (Args validation func) will be wrapped up. The warpped up func
will check to see if the feature is supported or not. If it is not supported,
then a not supported message is generated instead.

This fix is related to 28626.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: d5010088e3
Component: cli
2017-02-10 17:05:10 -08:00
bb163c30ef Improve error handling of experimental features in non-experimental mode
This fix tries to address several issues raised in 28626 where
run against a non-experimental daemon may not generate correct
error message:
1. Incorrect flags were not checked against the supported features:
   ```
   $ docker stack --nonsense
   unknown flag: --nonsense
   ```
2. Subcommands were not checked against the supported features:
   ```
   $ docker stack ls
   Error response from daemon: This node is not a swarm manager...
   ```

This fix address the above mentioned issues by:
1. Add a pre-check for FlagErrorFunc
2. Recursively check if a feature is supported for cmd and its parents.

This fix fixes 28626.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: 8e688f17a3
Component: cli
2017-02-10 16:54:19 -08:00
7cd5a4ceb5 review code about cmd/* and fix some easy typos :D
Signed-off-by: Aaron.L.Xu <likexu@harmonycloud.cn>
Upstream-commit: 0d8fd85842
Component: cli
2017-02-10 15:52:33 +08:00
1855724a2a print error if unsupported flags are used
Docker 1.13 and up allows a client to communicate
with older daemons. As a result, flags may be
present that are not supported by the older daemon.

The client already _hides_ flags that are not
supported yet, but this doesn't present users
from using those flags.

This change shows an error if a flag is used
that is not supported by the daemon (either
based on the API version, or because experimental
features are not enabled).

Note that for some options, a check is already
in place in the API client. For those
options, this is just a minor enhancement
to more clearly indicate which _flag_ is
not supported.

Before this change;

    DOCKER_API_VERSION=1.24 docker run -d --stop-timeout=30 busybox top
    mjfyt3qpvnq0iwmun3sjwth9i

    echo -e "FROM busybox\nRUN echo foo > bar" |  DOCKER_API_VERSION=1.24 docker build --squash -
    "squash" requires API version 1.25, but the Docker server is version 1.24

After this change;

    DOCKER_API_VERSION=1.24 docker run -d --stop-timeout=30 busybox top
    "--stop-timeout" requires API version 1.25, but the Docker daemon is version 1.24

    echo -e "FROM busybox\nRUN echo foo > bar" | DOCKER_API_VERSION=1.24 docker build --squash -
    "--squash" requires API version 1.25, but the Docker daemon is version 1.24

    echo -e "FROM busybox\nRUN echo foo > bar" | docker build --squash -
    "--squash" is only supported on a Docker daemon with experimental features enabled

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 0c71f36027
Component: cli
2017-02-03 16:59:20 -08:00
aeae0b960a Move package cliconfig to cli/config
I felt it made more sence 👼

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: d29175b73c
Component: cli
2016-12-25 20:31:52 +01:00
e670b03668 Move debug functions to cli/debug package
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 26c5b4b7b8
Component: cli
2016-12-12 09:33:58 +01:00
c34c8c73ff exit with status 1 if help is called on an invalid command.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 004fc6b9e4
Component: cli
2016-11-23 15:13:58 -05:00
7365ba4700 Merge pull request #28611 from vieux/fix_golint
fix a few golint errors
Upstream-commit: 4d1209844f
Component: cli
2016-11-19 07:16:44 -05:00
08da0db0bf fix a few golint errors
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
Upstream-commit: 40acabdfe9
Component: cli
2016-11-18 18:32:02 -08:00
c0c99dbe13 error on cli when trying to use experimental feature with non experimental daemon
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
Upstream-commit: 1ab47a8be8
Component: cli
2016-11-17 14:52:01 -08:00
3164628a33 refactor help func in CLI
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
Upstream-commit: 05ddb16e59
Component: cli
2016-11-17 10:54:10 -08:00
cfe7cb61c6 Skip cli initialization for daemon command
Cli initialization pings back to remote API and
creates a deadlock if socket is already being
listened by systemd.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Upstream-commit: 28f8f92963
Component: cli
2016-11-16 13:19:45 -08:00
c6c57b1d27 Show experimental flags and subcommands if enabled
Signed-off-by: John Stephens <johnstep@docker.com>
Upstream-commit: 13d6a1bb67
Component: cli
2016-11-11 17:43:06 -08:00
cc37942a6e Use '.' directly
Signed-off-by: Wang Long <long.wanglong@huawei.com>
Upstream-commit: 076bfc0647
Component: cli
2016-11-11 10:22:32 +08:00
b322424e88 always add but hide experimental cmds and flags
Signed-off-by: Victor Vieux <vieux@docker.com>

update cobra and use Tags

Signed-off-by: Victor Vieux <vieux@docker.com>

allow client to talk to an older server

Signed-off-by: Victor Vieux <vieux@docker.com>
Upstream-commit: e1beebbeef
Component: cli
2016-11-08 04:55:27 -08:00
35da390f93 Align arg with other cli
Signed-off-by: yupeng <yu.peng36@zte.com.cn>
Upstream-commit: 46418414a2
Component: cli
2016-11-05 13:47:02 +08:00
18b0c2adc0 update cobra and use Tags
Signed-off-by: Victor Vieux <vieux@docker.com>
Upstream-commit: 2ee5bbcbfa
Component: cli
2016-11-04 12:04:14 -07:00
0fef0ef25c always add but hide experimental cmds and flags
Signed-off-by: Victor Vieux <vieux@docker.com>
Upstream-commit: 73d63ec5a6
Component: cli
2016-11-03 17:31:12 -07:00
a70e23cbcd Align with other cli descriptions
Signed-off-by: yupeng <yu.peng36@zte.com.cn>
Upstream-commit: f1b1e55f7a
Component: cli
2016-11-01 13:41:49 +08:00
2ff5e5a0f8 Make experimental a runtime flag
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
Upstream-commit: 773a7f6cb8
Component: cli
2016-10-24 15:20:01 -07:00
b77b8228bf Modify function name from SetDaemonLogLevel to SetLogLevel
Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
Upstream-commit: a0e694d7c0
Component: cli
2016-10-11 19:35:12 +08:00
b06624604b Deprecate "daemon" subcommand
The daemon is in a separate (dockerd) binary
since docker 1.12, so should no longer be
used.

This marks the command as deprecated, and
adds it to the deprecated features list.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 4a2f7d8092
Component: cli
2016-09-23 00:26:27 +02:00
a5bf28b72a Move api/client -> cli/command
Using
  gomvpkg
     -from github.com/docker/docker/api/client
     -to github.com/docker/docker/cli/command
     -vcs_mv_cmd 'git mv {{.Src}} {{.Dst}}'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: b2c77abc35
Component: cli
2016-09-08 15:46:29 -04:00
c3ab654101 Fix daemon command proxy.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: ad96b991e9
Component: cli
2016-08-26 12:19:02 -04:00
e110c778f4 Fix tests and windows service.
Support args to RunCommand
Fix docker help text test.
Fix for ipv6 tests.
Fix TLSverify option.
Fix TestDaemonDiscoveryBackendConfigReload
Use tempfile for another test.
Restore missing flag.
Fix tests for removal of shlex.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 9af25060cd
Component: cli
2016-08-25 13:09:36 -04:00
e062c54a99 Remove old cli framework.
Also consolidate the leftover packages under cli.
Remove pkg/mflag.
Make manpage generation work with new cobra layout.
Remove remaining mflag and fix tests after rebase with master.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 3b178887a7
Component: cli
2016-08-25 13:09:04 -04:00
7e9f26ef70 Update unit tests for new cobra root command.
Cleanup cobra integration
Update windows files for cobra and pflags
Cleanup SetupRootcmd, and remove unnecessary SetFlagErrorFunc.
Use cobra command traversal

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 58a14cd18c
Component: cli
2016-08-25 13:09:04 -04:00
c526dbb69a Convert docker root command to use pflag and cobra
Fix the daemon proxy for cobra commands.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 08784d7e0e
Component: cli
2016-08-25 13:09:03 -04:00
88b6751cda Convert dockerd to use cobra and pflag
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 23dd85befd
Component: cli
2016-08-25 13:09:03 -04:00
ab55be6e38 Support running 'docker help daemon'
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 90e5326097
Component: cli
2016-06-09 13:22:03 -04:00
50bfe19924 Convert 'docker create' to use cobra and pflag
Return the correct status code on flag parsins errors.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: aee3578520
Component: cli
2016-06-04 13:57:30 +02:00
64201068c6 Migrate volume commands to cobra.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: ad83c422f2
Component: cli
2016-05-31 14:41:37 -07:00
4b0173813a Windows: work around Go 1.6.2/Nano Server TP5 issue
This works around golang/go#15286 by explicitly loading shell32.dll at
load time, ensuring that syscall can load it dynamically during process
startup.

Signed-off-by: John Starks <jostarks@microsoft.com>
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Upstream-commit: 9b1a322d9e
Component: cli
2016-05-25 11:59:28 +02:00
3773be609d Raise a more relevant error when dockerd is not available on the platform.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 765ab2b692
Component: cli
2016-05-02 11:59:25 -04:00
55cad02477 When exec'ing dockerd, look for it in the same directory as the docker binary first, before checking path.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 625263e2c7
Component: cli
2016-05-02 11:52:50 -04:00
ea37da58de Merge pull request #22372 from dnephin/cli_cleanup
Reorganize client and cli packages
Upstream-commit: 5de3b105a8
Component: cli
2016-04-29 17:31:39 -07:00
5df7e1fa55 Merge pull request #22340 from Microsoft/jstarks/split-service
Windows: Support running dockerd as a service
Upstream-commit: 320dbb2c30
Component: cli
2016-04-29 10:47:20 -07:00
a190e4c730 Remove reflection on CLI init
before:
```
$ time docker --help
real  0m0.177s
user  0m0.000s
sys 0m0.040s
```

after:
```
$ time docker --help
real  0m0.010s
user  0m0.000s
sys 0m0.000s
```

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: eb35552fb3
Component: cli
2016-04-29 11:57:46 -04:00
9d807c4424 Consolidate the files in client/
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: ec6cc96fa1
Component: cli
2016-04-27 14:53:36 -04:00
9e49ad8267 Cleanup the structure of the cli package.
Move all flags into cli/flags
Move usage help into cli/usage.go

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 315e242b9c
Component: cli
2016-04-27 14:25:47 -04:00
73fd4d25b9 Windows: Support running dockerd as a service
This adds support for Windows dockerd to run as a Windows service, managed
by the service control manager. The log is written to the Windows event
log (and can be viewed in the event viewer or in PowerShell). If there is
a Go panic, the stack is written to a file panic.log in the Docker root.

Signed-off-by: John Starks <jostarks@microsoft.com>
Upstream-commit: 421e366d8d
Component: cli
2016-04-26 14:04:47 -07:00
977a19e21d Make dockerd debuggable
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: c6919a6e79
Component: cli
2016-04-26 09:35:22 -07:00