Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
(cmd *cobra.Command, details versionDetails)
| 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 { |
| 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 | |
| 732 | func getFlagAnnotation(f *pflag.Flag, annotation string) string { |
| 733 | if value, ok := f.Annotations[annotation]; ok && len(value) == 1 { |
no test coverage detected
searching dependent graphs…