diff --git a/kustomize/commands/build/build.go b/kustomize/commands/build/build.go index 5914f89593..96dcc72605 100644 --- a/kustomize/commands/build/build.go +++ b/kustomize/commands/build/build.go @@ -102,12 +102,18 @@ func NewCmdBuild( return err }, } + AddFlagOutputPath(cmd.Flags()) AddFunctionBasicsFlags(cmd.Flags()) AddFlagLoadRestrictor(cmd.Flags()) AddFlagEnablePlugins(cmd.Flags()) AddFlagReorderOutput(cmd.Flags()) AddFlagEnableManagedbyLabel(cmd.Flags()) + + if err := AddFlagLoadRestrictorCompletion(cmd); err != nil { + log.Fatalf("Error adding completion for flag '--%s': %v", flagLoadRestrictorName, err) + } + msg := "Error marking flag '%s' as deprecated: %v" err := cmd.Flags().MarkDeprecated(flagReorderOutputName, "use the new 'sortOptions' field in kustomization.yaml instead.") diff --git a/kustomize/commands/build/flagloadrestrictor.go b/kustomize/commands/build/flagloadrestrictor.go index 928a530754..71e336b0af 100644 --- a/kustomize/commands/build/flagloadrestrictor.go +++ b/kustomize/commands/build/flagloadrestrictor.go @@ -6,6 +6,7 @@ package build import ( "fmt" + "github.com/spf13/cobra" "github.com/spf13/pflag" "sigs.k8s.io/kustomize/api/types" ) @@ -23,6 +24,21 @@ func AddFlagLoadRestrictor(set *pflag.FlagSet) { "relocatability of the kustomization.") } +func AddFlagLoadRestrictorCompletion(cmd *cobra.Command) error { + err := cmd.RegisterFlagCompletionFunc(flagLoadRestrictorName, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{ + types.LoadRestrictionsNone.String(), + types.LoadRestrictionsRootOnly.String(), + }, cobra.ShellCompDirectiveNoFileComp + }) + + if err != nil { + return fmt.Errorf("unable to add completion for --%s flag: %w", flagLoadRestrictorName, err) + } + + return nil +} + func validateFlagLoadRestrictor() error { switch theFlags.loadRestrictor { case types.LoadRestrictionsRootOnly.String(),