[28.x backport] cli/flags: add "hostVar" to handle --host / -H as a single string #6289
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cli/flags: use a regular StringArray for the
--host/-HflagThe 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
ClientConfigstruct 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 ofNewNamedListOptsReffor a regularStringArray.Unfortunately this changes the flag's type description from
listtostringArray, 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)