Skip to content

Conversation

@thaJeztah
Copy link
Member


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. 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.

cli/flags: add "hostVar" to handle --host / -H as a single string

hostVar is used for the '--host' / '-H' flag to set [ClientOptions.Hosts].
The [ClientOptions.Hosts] field is a slice because it was originally shared
with the daemon config. However, the CLI only allows for a single host to
be specified.

hostVar presents itself as a "string", but stores the value in a string
slice. It produces an error when trying to set multiple values, matching
the check in getServerHost.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

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]>
hostVar is used for the '--host' / '-H' flag to set [ClientOptions.Hosts].
The [ClientOptions.Hosts] field is a slice because it was originally shared
with the daemon config. However, the CLI only allows for a single host to
be specified.

hostVar presents itself as a "string", but stores the value in a string
slice. It produces an error when trying to set multiple values, matching
the check in [getServerHost].

[getServerHost]: https://github.com/docker/cli/blob/7eab668982645def1cd46fe1b60894cba6fd17a4/cli/command/cli.go#L542-L551

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit f14eeeb)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah added this to the 28.4.0 milestone Aug 18, 2025
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Aug 18, 2025
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 43.75000% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/flags/options.go 43.75% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@thaJeztah
Copy link
Member Author

GitHub actions?

toomanyrequests: <?xml version="1.0" encoding="UTF-8"?><Error><Code>ServiceUnavailable</Code><Message>Reduce your rate of simultaneous reads on the same object.</Message></Error>

@thaJeztah thaJeztah marked this pull request as ready for review August 18, 2025 16:27
@thaJeztah thaJeztah requested a review from a team as a code owner August 18, 2025 16:27
@thaJeztah thaJeztah merged commit 14f2972 into docker:28.x Aug 18, 2025
118 of 126 checks passed
@thaJeztah thaJeztah deleted the 28.x_backport_hosts_regular_stringarray branch August 18, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants