Update code for upstream cobra
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
@ -88,6 +88,7 @@ func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *p
|
||||
}
|
||||
|
||||
func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
||||
defaultHelpFunc := cmd.HelpFunc()
|
||||
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
||||
initializeDockerCli(dockerCli, flags, opts)
|
||||
if err := isSupported(ccmd, dockerCli); err != nil {
|
||||
@ -96,10 +97,7 @@ func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.
|
||||
}
|
||||
|
||||
hideUnsupportedFeatures(ccmd, dockerCli)
|
||||
|
||||
if err := ccmd.Help(); err != nil {
|
||||
ccmd.Println(err)
|
||||
}
|
||||
defaultHelpFunc(ccmd, args)
|
||||
})
|
||||
}
|
||||
|
||||
@ -225,13 +223,13 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
|
||||
for _, subcmd := range cmd.Commands() {
|
||||
// hide experimental subcommands
|
||||
if !hasExperimental {
|
||||
if _, ok := subcmd.Tags["experimental"]; ok {
|
||||
if _, ok := subcmd.Annotations["experimental"]; ok {
|
||||
subcmd.Hidden = true
|
||||
}
|
||||
}
|
||||
|
||||
// hide subcommands not supported by the server
|
||||
if subcmdVersion, ok := subcmd.Tags["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) {
|
||||
if subcmdVersion, ok := subcmd.Annotations["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) {
|
||||
subcmd.Hidden = true
|
||||
}
|
||||
}
|
||||
@ -244,10 +242,10 @@ func isSupported(cmd *cobra.Command, details versionDetails) error {
|
||||
|
||||
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
|
||||
for curr := cmd; curr != nil; curr = curr.Parent() {
|
||||
if cmdVersion, ok := curr.Tags["version"]; ok && versions.LessThan(clientVersion, cmdVersion) {
|
||||
if cmdVersion, ok := curr.Annotations["version"]; ok && versions.LessThan(clientVersion, cmdVersion) {
|
||||
return fmt.Errorf("%s requires API version %s, but the Docker daemon API version is %s", cmd.CommandPath(), cmdVersion, clientVersion)
|
||||
}
|
||||
if _, ok := curr.Tags["experimental"]; ok && !hasExperimental {
|
||||
if _, ok := curr.Annotations["experimental"]; ok && !hasExperimental {
|
||||
return fmt.Errorf("%s is only supported on a Docker daemon with experimental features enabled", cmd.CommandPath())
|
||||
}
|
||||
}
|
||||
@ -300,7 +298,7 @@ func isOSTypeSupported(f *pflag.Flag, osType string) bool {
|
||||
// hasTags return true if any of the command's parents has tags
|
||||
func hasTags(cmd *cobra.Command) bool {
|
||||
for curr := cmd; curr != nil; curr = curr.Parent() {
|
||||
if len(curr.Tags) > 0 {
|
||||
if len(curr.Annotations) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user