@@ -25,7 +25,6 @@ import (
2525 "github.com/docker/buildx/controller/pb"
2626 "github.com/docker/buildx/localstate"
2727 "github.com/docker/buildx/util/buildflags"
28- "github.com/docker/buildx/util/cobrautil"
2928 "github.com/docker/buildx/util/cobrautil/completion"
3029 "github.com/docker/buildx/util/confutil"
3130 "github.com/docker/buildx/util/desktop"
@@ -42,20 +41,25 @@ import (
4241)
4342
4443type bakeOptions struct {
45- files []string
46- overrides []string
47- printOnly bool
48- listTargets bool
49- listVars bool
50- sbom string
51- provenance string
52- allow []string
44+ files []string
45+ overrides []string
46+
47+ sbom string
48+ provenance string
49+ allow []string
5350
5451 builder string
5552 metadataFile string
5653 exportPush bool
5754 exportLoad bool
5855 callFunc string
56+
57+ print bool
58+ list string
59+
60+ // TODO: remove deprecated flags
61+ listTargets bool
62+ listVars bool
5963}
6064
6165func runBake (ctx context.Context , dockerCli command.Cli , targets []string , in bakeOptions , cFlags commonFlags ) (err error ) {
@@ -123,7 +127,7 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
123127
124128 // instance only needed for reading remote bake files or building
125129 var driverType string
126- if url != "" || ! (in .printOnly || in .listTargets || in . listVars ) {
130+ if url != "" || ! (in .print || in .list != "" ) {
127131 b , err := builder .New (dockerCli ,
128132 builder .WithName (in .builder ),
129133 builder .WithContextPathHash (contextPathHash ),
@@ -184,18 +188,21 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
184188 "BAKE_LOCAL_PLATFORM" : platforms .Format (platforms .DefaultSpec ()),
185189 }
186190
187- if in .listTargets || in . listVars {
191+ if in .list != "" {
188192 cfg , pm , err := bake .ParseFiles (files , defaults )
189193 if err != nil {
190194 return err
191195 }
192196 if err = printer .Wait (); err != nil {
193197 return err
194198 }
195- if in .listTargets {
199+ switch in .list {
200+ case "targets" :
196201 return printTargetList (dockerCli .Out (), cfg )
197- } else if in . listVars {
202+ case "variables" :
198203 return printVars (dockerCli .Out (), pm .AllVariables )
204+ default :
205+ return errors .Errorf ("invalid list mode %q" , in .list )
199206 }
200207 }
201208
@@ -231,7 +238,7 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
231238 Target : tgts ,
232239 }
233240
234- if in .printOnly {
241+ if in .print {
235242 if err = printer .Wait (); err != nil {
236243 return err
237244 }
@@ -427,6 +434,13 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
427434 if ! cmd .Flags ().Lookup ("pull" ).Changed {
428435 cFlags .pull = nil
429436 }
437+ if options .list == "" {
438+ if options .listTargets {
439+ options .list = "targets"
440+ } else if options .listVars {
441+ options .list = "variables"
442+ }
443+ }
430444 options .builder = rootOpts .builder
431445 options .metadataFile = cFlags .metadataFile
432446 // Other common flags (noCache, pull and progress) are processed in runBake function.
@@ -439,7 +453,6 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
439453
440454 flags .StringArrayVarP (& options .files , "file" , "f" , []string {}, "Build definition file" )
441455 flags .BoolVar (& options .exportLoad , "load" , false , `Shorthand for "--set=*.output=type=docker"` )
442- flags .BoolVar (& options .printOnly , "print" , false , "Print the options without building" )
443456 flags .BoolVar (& options .exportPush , "push" , false , `Shorthand for "--set=*.output=type=registry"` )
444457 flags .StringVar (& options .sbom , "sbom" , "" , `Shorthand for "--set=*.attest=type=sbom"` )
445458 flags .StringVar (& options .provenance , "provenance" , "" , `Shorthand for "--set=*.attest=type=provenance"` )
@@ -450,13 +463,16 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
450463 flags .VarPF (callAlias (& options .callFunc , "check" ), "check" , "" , `Shorthand for "--call=check"` )
451464 flags .Lookup ("check" ).NoOptDefVal = "true"
452465
466+ flags .BoolVar (& options .print , "print" , false , "Print the options without building" )
467+ flags .StringVar (& options .list , "list" , "" , "List targets or variables" )
468+
469+ // TODO: remove deprecated flags
453470 flags .BoolVar (& options .listTargets , "list-targets" , false , "List available targets" )
454- cobrautil .MarkFlagsExperimental (flags , "list-targets" )
455471 flags .MarkHidden ("list-targets" )
456-
472+ flags . MarkDeprecated ( "list-targets" , "list-targets is deprecated, use list=targets instead" )
457473 flags .BoolVar (& options .listVars , "list-variables" , false , "List defined variables" )
458- cobrautil .MarkFlagsExperimental (flags , "list-variables" )
459474 flags .MarkHidden ("list-variables" )
475+ flags .MarkDeprecated ("list-variables" , "list-variables is deprecated, use list=variables instead" )
460476
461477 commonBuildFlags (& cFlags , flags )
462478
0 commit comments