Skip to content

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Aug 15, 2025

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)

@thaJeztah thaJeztah added this to the 29.0.0 milestone Aug 15, 2025
@thaJeztah thaJeztah requested a review from a team as a code owner August 15, 2025 21:42
@thaJeztah thaJeztah force-pushed the hosts_regular_stringarray branch from c925a2d to ecbea9b Compare August 15, 2025 21:43
@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2025

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 thaJeztah changed the title flags: use a regular StringArray for the --host / -H flag cli/flags: use a regular StringArray for the --host / -H flag Aug 16, 2025
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]>
@thaJeztah thaJeztah force-pushed the hosts_regular_stringarray branch from ecbea9b to 0bc52fd Compare August 16, 2025 17:13
@thaJeztah thaJeztah changed the title cli/flags: use a regular StringArray for the --host / -H flag cli/flags: add "hostVar" to handle --host / -H as a single string Aug 16, 2025
@thaJeztah thaJeztah force-pushed the hosts_regular_stringarray branch from 0bc52fd to bbbf93b Compare August 16, 2025 17:17
@thaJeztah
Copy link
Member Author

Oh! I need to update a test, because the flag-validation adds invalid argument or something as prefix.

@thaJeztah thaJeztah force-pushed the hosts_regular_stringarray branch from bbbf93b to a96a409 Compare August 18, 2025 08:39
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]>
@thaJeztah thaJeztah force-pushed the hosts_regular_stringarray branch from a96a409 to f14eeeb Compare August 18, 2025 09:01
@thaJeztah thaJeztah merged commit 2bcf433 into docker:master Aug 18, 2025
105 of 106 checks passed
@thaJeztah thaJeztah deleted the hosts_regular_stringarray branch August 18, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants