Skip to content

Commit ff42ff9

Browse files
committed
cli/flags: use a regular StringArray for the --host / -H flag
The ClientOptions struct and related flags were inherited from the Moby repository, where originally the CLI and Daemon used the same implementation and had a "Common" options struct. When the CLI moved to a separate repository, those structs were duplicated, but some daemon-specific logic remained. For example, the daemon can be configured to listen on multiple ports and sockets ([moby@dede158]), but the CLI [can only connect to a single host][1]. The daemon config also had to account for flags conflicting with `daemon.json`, and use special flag-vars for this ([moby@677a6b3]). Unfortunately, the `ClientConfig` struct became part of the public API and is used as argument in various places, but we can remove the use of the special flag var. This patch replaces the use of `NewNamedListOptsRef` for a regular `StringArray`. Unfortunately this changes the flag's type description from `list` to `stringArray`, but we can look at changing that separately. [moby@dede158]: moby/moby@dede158 [1]: https://github.com/moby/moby/blob/0af135e9065562e14a77439e13a29b4f1eb627a0/docker/docker.go#L191-L193 [moby@677a6b3]: moby/moby@677a6b3 Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 5ee2906) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent bcc479b commit ff42ff9

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

cli/flags/options.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"path/filepath"
77

88
"github.com/docker/cli/cli/config"
9-
"github.com/docker/cli/opts"
109
"github.com/docker/docker/client"
1110
"github.com/docker/go-connections/tlsconfig"
1211
"github.com/sirupsen/logrus"
@@ -94,9 +93,9 @@ func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) {
9493
flags.Var(&quotedString{&tlsOptions.CertFile}, "tlscert", "Path to TLS certificate file")
9594
flags.Var(&quotedString{&tlsOptions.KeyFile}, "tlskey", "Path to TLS key file")
9695

97-
// opts.ValidateHost is not used here, so as to allow connection helpers
98-
hostOpt := opts.NewNamedListOptsRef("hosts", &o.Hosts, nil)
99-
flags.VarP(hostOpt, "host", "H", "Daemon socket to connect to")
96+
// TODO(thaJeztah): show the default host.
97+
// TODO(thaJeztah): this should be a string, not an "array" as we only allow a single host.
98+
flags.StringArrayVarP(&o.Hosts, "host", "H", nil, "Daemon socket to connect to")
10099
flags.StringVarP(&o.Context, "context", "c", "",
101100
`Name of the context to use to connect to the daemon (overrides `+client.EnvOverrideHost+` env var and default context set with "docker context use")`)
102101
}

docs/reference/commandline/docker.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,18 @@ The base command for the Docker CLI.
6969

7070
### Options
7171

72-
| Name | Type | Default | Description |
73-
|:---------------------------------|:---------|:-------------------------|:--------------------------------------------------------------------------------------------------------------------------------------|
74-
| `--config` | `string` | `/root/.docker` | Location of client config files |
75-
| `-c`, `--context` | `string` | | Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with `docker context use`) |
76-
| `-D`, `--debug` | `bool` | | Enable debug mode |
77-
| [`-H`](#host), [`--host`](#host) | `list` | | Daemon socket to connect to |
78-
| `-l`, `--log-level` | `string` | `info` | Set the logging level (`debug`, `info`, `warn`, `error`, `fatal`) |
79-
| `--tls` | `bool` | | Use TLS; implied by --tlsverify |
80-
| `--tlscacert` | `string` | `/root/.docker/ca.pem` | Trust certs signed only by this CA |
81-
| `--tlscert` | `string` | `/root/.docker/cert.pem` | Path to TLS certificate file |
82-
| `--tlskey` | `string` | `/root/.docker/key.pem` | Path to TLS key file |
83-
| `--tlsverify` | `bool` | | Use TLS and verify the remote |
72+
| Name | Type | Default | Description |
73+
|:---------------------------------|:--------------|:-------------------------|:--------------------------------------------------------------------------------------------------------------------------------------|
74+
| `--config` | `string` | `/root/.docker` | Location of client config files |
75+
| `-c`, `--context` | `string` | | Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with `docker context use`) |
76+
| `-D`, `--debug` | `bool` | | Enable debug mode |
77+
| [`-H`](#host), [`--host`](#host) | `stringArray` | | Daemon socket to connect to |
78+
| `-l`, `--log-level` | `string` | `info` | Set the logging level (`debug`, `info`, `warn`, `error`, `fatal`) |
79+
| `--tls` | `bool` | | Use TLS; implied by --tlsverify |
80+
| `--tlscacert` | `string` | `/root/.docker/ca.pem` | Trust certs signed only by this CA |
81+
| `--tlscert` | `string` | `/root/.docker/cert.pem` | Path to TLS certificate file |
82+
| `--tlskey` | `string` | `/root/.docker/key.pem` | Path to TLS key file |
83+
| `--tlsverify` | `bool` | | Use TLS and verify the remote |
8484

8585

8686
<!---MARKER_GEN_END-->

0 commit comments

Comments
 (0)