|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package completion
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/docker/buildx/bake"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -10,3 +13,26 @@ type ValidArgsFn func(cmd *cobra.Command, args []string, toComplete string) ([]s
|
|
|
|
|
func Disable(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
|
|
return nil, cobra.ShellCompDirectiveNoSpace
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BakeTargets(files []string) ValidArgsFn {
|
|
|
|
|
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
|
|
f, err := bake.ReadLocalFiles(files)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, cobra.ShellCompDirectiveError
|
|
|
|
|
}
|
|
|
|
|
tgts, err := bake.ListTargets(f)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, cobra.ShellCompDirectiveError
|
|
|
|
|
}
|
|
|
|
|
var filtered []string
|
|
|
|
|
if toComplete == "" {
|
|
|
|
|
return tgts, cobra.ShellCompDirectiveNoFileComp
|
|
|
|
|
}
|
|
|
|
|
for _, tgt := range tgts {
|
|
|
|
|
if strings.HasPrefix(tgt, toComplete) {
|
|
|
|
|
filtered = append(filtered, tgt)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return filtered, cobra.ShellCompDirectiveNoFileComp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|