-
Notifications
You must be signed in to change notification settings - Fork 2.1k
build: only show buildkit-specific flags if buildkit is enabled #1427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,8 +100,10 @@ func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag. | |
| ccmd.Println(err) | ||
| return | ||
| } | ||
|
|
||
| hideUnsupportedFeatures(ccmd, dockerCli) | ||
| if err := hideUnsupportedFeatures(ccmd, dockerCli); err != nil { | ||
| ccmd.Println(err) | ||
| return | ||
| } | ||
| defaultHelpFunc(ccmd, args) | ||
| }) | ||
| } | ||
|
|
@@ -235,15 +237,21 @@ func hideFeatureSubCommand(subcmd *cobra.Command, hasFeature bool, annotation st | |
| } | ||
| } | ||
|
|
||
| func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) { | ||
| func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) error { | ||
| clientVersion := details.Client().ClientVersion() | ||
| osType := details.ServerInfo().OSType | ||
| hasExperimental := details.ServerInfo().HasExperimental | ||
| hasExperimentalCLI := details.ClientInfo().HasExperimental | ||
| hasBuildKit, err := command.BuildKitEnabled(details.ServerInfo()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| cmd.Flags().VisitAll(func(f *pflag.Flag) { | ||
| hideFeatureFlag(f, hasExperimental, "experimental") | ||
| hideFeatureFlag(f, hasExperimentalCLI, "experimentalCLI") | ||
| hideFeatureFlag(f, hasBuildKit, "buildkit") | ||
tiborvass marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| hideFeatureFlag(f, !hasBuildKit, "no-buildkit") | ||
| // hide flags not supported by the server | ||
| if !isOSTypeSupported(f, osType) || !isVersionSupported(f, clientVersion) { | ||
| f.Hidden = true | ||
|
|
@@ -259,6 +267,8 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) { | |
| for _, subcmd := range cmd.Commands() { | ||
| hideFeatureSubCommand(subcmd, hasExperimental, "experimental") | ||
| hideFeatureSubCommand(subcmd, hasExperimentalCLI, "experimentalCLI") | ||
| hideFeatureSubCommand(subcmd, hasBuildKit, "buildkit") | ||
| hideFeatureSubCommand(subcmd, !hasBuildKit, "no-buildkit") | ||
| // hide subcommands not supported by the server | ||
| if subcmdVersion, ok := subcmd.Annotations["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) { | ||
| subcmd.Hidden = true | ||
|
|
@@ -267,6 +277,7 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) { | |
| subcmd.Hidden = true | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Checks if a command or one of its ancestors is in the list | ||
|
|
@@ -313,6 +324,7 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error { | |
| if _, ok := f.Annotations["experimentalCLI"]; ok && !hasExperimentalCLI { | ||
| errs = append(errs, fmt.Sprintf("\"--%s\" is on a Docker cli with experimental cli features enabled", f.Name)) | ||
| } | ||
| // buildkit-specific flags are noop when buildkit is not enabled, so we do not add an error in that case | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can still print
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could make sense to inform them that an option is only supported with/without buildkit, and will be ignored. Given that we're already ignoring those flags in the current code, I think that'd be good to do separately, in a follow-up; |
||
| } | ||
| }) | ||
| if len(errs) > 0 { | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.