@@ -100,8 +100,10 @@ func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.
100100 ccmd .Println (err )
101101 return
102102 }
103-
104- hideUnsupportedFeatures (ccmd , dockerCli )
103+ if err := hideUnsupportedFeatures (ccmd , dockerCli ); err != nil {
104+ ccmd .Println (err )
105+ return
106+ }
105107 defaultHelpFunc (ccmd , args )
106108 })
107109}
@@ -215,6 +217,7 @@ type versionDetails interface {
215217 Client () client.APIClient
216218 ClientInfo () command.ClientInfo
217219 ServerInfo () command.ServerInfo
220+ BuildKitEnabled () (bool , error )
218221}
219222
220223func hideFeatureFlag (f * pflag.Flag , hasFeature bool , annotation string ) {
@@ -235,15 +238,20 @@ func hideFeatureSubCommand(subcmd *cobra.Command, hasFeature bool, annotation st
235238 }
236239}
237240
238- func hideUnsupportedFeatures (cmd * cobra.Command , details versionDetails ) {
241+ func hideUnsupportedFeatures (cmd * cobra.Command , details versionDetails ) error {
239242 clientVersion := details .Client ().ClientVersion ()
240243 osType := details .ServerInfo ().OSType
241244 hasExperimental := details .ServerInfo ().HasExperimental
242245 hasExperimentalCLI := details .ClientInfo ().HasExperimental
246+ hasBuildKit , err := details .BuildKitEnabled ()
247+ if err != nil {
248+ return err
249+ }
243250
244251 cmd .Flags ().VisitAll (func (f * pflag.Flag ) {
245252 hideFeatureFlag (f , hasExperimental , "experimental" )
246253 hideFeatureFlag (f , hasExperimentalCLI , "experimentalCLI" )
254+ hideFeatureFlag (f , hasBuildKit , "buildkit" )
247255 // hide flags not supported by the server
248256 if ! isOSTypeSupported (f , osType ) || ! isVersionSupported (f , clientVersion ) {
249257 f .Hidden = true
@@ -259,6 +267,7 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
259267 for _ , subcmd := range cmd .Commands () {
260268 hideFeatureSubCommand (subcmd , hasExperimental , "experimental" )
261269 hideFeatureSubCommand (subcmd , hasExperimentalCLI , "experimentalCLI" )
270+ hideFeatureSubCommand (subcmd , hasBuildKit , "buildkit" )
262271 // hide subcommands not supported by the server
263272 if subcmdVersion , ok := subcmd .Annotations ["version" ]; ok && versions .LessThan (clientVersion , subcmdVersion ) {
264273 subcmd .Hidden = true
@@ -267,6 +276,7 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
267276 subcmd .Hidden = true
268277 }
269278 }
279+ return nil
270280}
271281
272282// Checks if a command or one of its ancestors is in the list
@@ -313,6 +323,7 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
313323 if _ , ok := f .Annotations ["experimentalCLI" ]; ok && ! hasExperimentalCLI {
314324 errs = append (errs , fmt .Sprintf ("\" --%s\" is on a Docker cli with experimental cli features enabled" , f .Name ))
315325 }
326+ // buildkit-specific flags are noop when buildkit is not enabled, so we do not add an error in that case
316327 }
317328 })
318329 if len (errs ) > 0 {
0 commit comments