Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ var helpCommand = &cobra.Command{
},
}

// isExperimental reports whether cmd (or one of its parents) carries the
// "experimentalCLI" annotation. This is a client-side, build-time check:
// it only inspects the static Annotations map and never consults a
// connected daemon.
func isExperimental(cmd *cobra.Command) bool {
if _, ok := cmd.Annotations["experimentalCLI"]; ok {
return true
Expand Down Expand Up @@ -330,6 +334,12 @@ func vendorAndVersion(cmd *cobra.Command) string {
return ""
}

// managementSubCommands and orchestratorSubCommands (below) group
// sub-commands by the "swarm" annotation for help-text display. The
// annotation itself is evaluated server-side elsewhere: a command's
// swarm-related behavior/availability is checked against the connected
// daemon's reported swarm state (see ServerInfo/SwarmStatus), not this
// static annotation lookup.
func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
cmds := []*cobra.Command{}
for _, sub := range allManagementSubCommands(cmd) {
Expand Down
11 changes: 9 additions & 2 deletions cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,11 @@ func hideSubcommandIf(subcmd *cobra.Command, condition func(string) bool, annota
func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
var (
notExperimental = func(_ string) bool { return !details.ServerInfo().HasExperimental }
notOSType = func(v string) bool { return details.ServerInfo().OSType != "" && v != details.ServerInfo().OSType }
notSwarmStatus = func(v string) bool {
// notOSType implements the server-side check for the "ostype" annotation:
// it hides flags/commands whose "ostype" value doesn't match the
// connected daemon's reported ServerInfo().OSType.
notOSType = func(v string) bool { return details.ServerInfo().OSType != "" && v != details.ServerInfo().OSType }
notSwarmStatus = func(v string) bool {
s := details.ServerInfo().SwarmStatus
if s == nil {
// engine did not return swarm status header
Expand Down Expand Up @@ -775,6 +778,10 @@ func isVersionSupported(f *pflag.Flag, clientVersion string) bool {
return true
}

// isOSTypeSupported checks the "ostype" flag annotation against osType,
// which callers pass as the connected daemon's ServerInfo().OSType. This
// makes "ostype" a server-side check: it depends on the daemon's reported
// OS, not on any client-side/build-time state.
func isOSTypeSupported(f *pflag.Flag, osType string) bool {
if v := getFlagAnnotation(f, "ostype"); v != "" && osType != "" {
return osType == v
Expand Down