MCPcopy Index your code
hub / github.com/docker/cli / areSubcommandsSupported

Function areSubcommandsSupported

cmd/docker/docker.go:708–730  ·  view source on GitHub ↗

Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`

(cmd *cobra.Command, details versionDetails)

Source from the content-addressed store, hash-verified

706
707// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
708func areSubcommandsSupported(cmd *cobra.Command, details versionDetails) error {
709 // Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
710 for curr := cmd; curr != nil; curr = curr.Parent() {
711 // Important: in the code below, calls to "details.CurrentVersion()" and
712 // "details.ServerInfo()" are deliberately executed inline to make them
713 // be executed "lazily". This is to prevent making a connection with the
714 // daemon to perform a "ping" (even for commands that do not require a
715 // daemon connection).
716 //
717 // See commit b39739123b845f872549e91be184cc583f5b387c for details.
718
719 if cmdVersion, ok := curr.Annotations["version"]; ok && versions.LessThan(details.CurrentVersion(), cmdVersion) {
720 return fmt.Errorf("%s requires API version %s, but the Docker daemon API version is %s", cmd.CommandPath(), cmdVersion, details.CurrentVersion())
721 }
722 if ost, ok := curr.Annotations["ostype"]; ok && details.ServerInfo().OSType != "" && ost != details.ServerInfo().OSType {
723 return fmt.Errorf("%s is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s", cmd.CommandPath(), ost, details.ServerInfo().OSType)
724 }
725 if _, ok := curr.Annotations["experimental"]; ok && !details.ServerInfo().HasExperimental {
726 return fmt.Errorf("%s is only supported on a Docker daemon with experimental features enabled", cmd.CommandPath())
727 }
728 }
729 return nil
730}
731
732func getFlagAnnotation(f *pflag.Flag, annotation string) string {
733 if value, ok := f.Annotations[annotation]; ok && len(value) == 1 {

Callers 1

isSupportedFunction · 0.85

Calls 3

ParentMethod · 0.80
CurrentVersionMethod · 0.65
ServerInfoMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…