GetNamespace get namespace from command flags and env
(_ Factory, cmd *cobra.Command)
| 26 | |
| 27 | // GetNamespace get namespace from command flags and env |
| 28 | func GetNamespace(_ Factory, cmd *cobra.Command) string { |
| 29 | namespace, err := cmd.Flags().GetString(flagNamespace) |
| 30 | cmdutil.CheckErr(err) |
| 31 | if namespace != "" { |
| 32 | return namespace |
| 33 | } |
| 34 | // find namespace from env |
| 35 | envName, err := cmd.Flags().GetString(flagEnv) |
| 36 | if err != nil { |
| 37 | // ignore env if the command does not use the flag |
| 38 | return "" |
| 39 | } |
| 40 | var envMeta *types.EnvMeta |
| 41 | if envName != "" { |
| 42 | envMeta, err = env.GetEnvByName(envName) |
| 43 | } else { |
| 44 | envMeta, err = env.GetCurrentEnv() |
| 45 | } |
| 46 | if err != nil { |
| 47 | return "" |
| 48 | } |
| 49 | return envMeta.Namespace |
| 50 | } |
| 51 | |
| 52 | // GetNamespaceAndSource gets namespace from command flags and env and also returns source of the namespace |
| 53 | func GetNamespaceAndSource(cmd *cobra.Command) (string, string) { |
nothing calls this directly
no test coverage detected