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

Function areFlagsSupported

cmd/docker/docker.go:672–705  ·  view source on GitHub ↗
(cmd *cobra.Command, details versionDetails)

Source from the content-addressed store, hash-verified

670}
671
672func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
673 var errs []error
674
675 cmd.Flags().VisitAll(func(f *pflag.Flag) {
676 if !f.Changed || len(f.Annotations) == 0 {
677 return
678 }
679 // Important: in the code below, calls to "details.CurrentVersion()" and
680 // "details.ServerInfo()" are deliberately executed inline to make them
681 // be executed "lazily". This is to prevent making a connection with the
682 // daemon to perform a "ping" (even for flags that do not require a
683 // daemon connection).
684 //
685 // See commit b39739123b845f872549e91be184cc583f5b387c for details.
686
687 if _, ok := f.Annotations["version"]; ok && !isVersionSupported(f, details.CurrentVersion()) {
688 errs = append(errs, fmt.Errorf(`"--%s" requires API version %s, but the Docker daemon API version is %s`, f.Name, getFlagAnnotation(f, "version"), details.CurrentVersion()))
689 return
690 }
691 if _, ok := f.Annotations["ostype"]; ok && !isOSTypeSupported(f, details.ServerInfo().OSType) {
692 errs = append(errs, fmt.Errorf(
693 `"--%s" is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s`,
694 f.Name,
695 getFlagAnnotation(f, "ostype"), details.ServerInfo().OSType),
696 )
697 return
698 }
699 if _, ok := f.Annotations["experimental"]; ok && !details.ServerInfo().HasExperimental {
700 errs = append(errs, fmt.Errorf(`"--%s" is only supported on a Docker daemon with experimental features enabled`, f.Name))
701 }
702 // buildkit-specific flags are noop when buildkit is not enabled, so we do not add an error in that case
703 })
704 return errors.Join(errs...)
705}
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 {

Callers 1

isSupportedFunction · 0.85

Calls 5

isVersionSupportedFunction · 0.85
getFlagAnnotationFunction · 0.85
isOSTypeSupportedFunction · 0.85
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…