WithNamespaceFlag add namespace flag to the command, by default, it will also add env flag to the command
(options ...NamespaceFlagOption)
| 115 | |
| 116 | // WithNamespaceFlag add namespace flag to the command, by default, it will also add env flag to the command |
| 117 | func (builder *Builder) WithNamespaceFlag(options ...NamespaceFlagOption) *Builder { |
| 118 | cfg := newNamespaceFlagOptions(options...) |
| 119 | builder.cmd.Flags().StringP(flagNamespace, "n", "", cfg.usage) |
| 120 | if cfg.completion { |
| 121 | cmdutil.CheckErr(builder.cmd.RegisterFlagCompletionFunc( |
| 122 | flagNamespace, |
| 123 | func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 124 | return GetNamespacesForCompletion(cmd.Context(), builder.f, toComplete) |
| 125 | })) |
| 126 | } |
| 127 | if cfg.loadEnv { |
| 128 | return builder.WithEnvFlag() |
| 129 | } |
| 130 | return builder |
| 131 | } |
| 132 | |
| 133 | // WithEnvFlag add env flag to the command |
| 134 | func (builder *Builder) WithEnvFlag() *Builder { |
no test coverage detected