(cmd *cobra.Command, details versionDetails)
| 670 | } |
| 671 | |
| 672 | func 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` |
| 708 | func areSubcommandsSupported(cmd *cobra.Command, details versionDetails) error { |
no test coverage detected
searching dependent graphs…