@@ -25,7 +25,6 @@ import (
2525 "github.com/docker/buildx/localstate"
2626 "github.com/docker/buildx/util/buildflags"
2727 "github.com/docker/buildx/util/cobrautil"
28- "github.com/docker/buildx/util/cobrautil/completion"
2928 "github.com/docker/buildx/util/confutil"
3029 "github.com/docker/buildx/util/desktop"
3130 "github.com/docker/buildx/util/dockerutil"
@@ -510,7 +509,7 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
510509 // Other common flags (noCache, pull and progress) are processed in runBake function.
511510 return runBake (cmd .Context (), dockerCli , args , options , cFlags , filesFromEnv )
512511 },
513- ValidArgsFunction : completion . BakeTargets (options .files ),
512+ ValidArgsFunction : bakeTargetsCompletion (options .files ),
514513 DisableFlagsInUseLine : true ,
515514 }
516515
@@ -545,6 +544,29 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
545544 return cmd
546545}
547546
547+ func bakeTargetsCompletion (files []string ) cobrautil.ValidArgsFn {
548+ return func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
549+ f , err := bake .ReadLocalFiles (files , nil , nil )
550+ if err != nil {
551+ return nil , cobra .ShellCompDirectiveError
552+ }
553+ tgts , err := bake .ListTargets (f )
554+ if err != nil {
555+ return nil , cobra .ShellCompDirectiveError
556+ }
557+ var filtered []string
558+ if toComplete == "" {
559+ return tgts , cobra .ShellCompDirectiveNoFileComp
560+ }
561+ for _ , tgt := range tgts {
562+ if strings .HasPrefix (tgt , toComplete ) {
563+ filtered = append (filtered , tgt )
564+ }
565+ }
566+ return filtered , cobra .ShellCompDirectiveNoFileComp
567+ }
568+ }
569+
548570func bakeEnvFiles (lookup func (string string ) (string , bool )) ([]string , error ) {
549571 sep , _ := lookup (bakeEnvFileSeparator )
550572 if sep == "" {
0 commit comments