GetNamespaceAndSource gets namespace from command flags and env and also returns source of the namespace
(cmd *cobra.Command)
| 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) { |
| 54 | namespace, err := cmd.Flags().GetString(flagNamespace) |
| 55 | cmdutil.CheckErr(err) |
| 56 | if namespace != "" { |
| 57 | return namespace, "namespaceflag" |
| 58 | } |
| 59 | // find namespace from env |
| 60 | envName, err := cmd.Flags().GetString(flagEnv) |
| 61 | if err != nil { |
| 62 | // ignore env if the command does not use the flag |
| 63 | return "", "defaulted" |
| 64 | } |
| 65 | var envMeta *types.EnvMeta |
| 66 | if envName != "" { |
| 67 | envMeta, err = env.GetEnvByName(envName) |
| 68 | } else { |
| 69 | envMeta, err = env.GetCurrentEnv() |
| 70 | } |
| 71 | if err != nil { |
| 72 | return "", "defaulted" |
| 73 | } |
| 74 | return envMeta.Namespace, "env" |
| 75 | } |
| 76 | |
| 77 | // GetGroup get group from command flags |
| 78 | func GetGroup(cmd *cobra.Command) string { |
nothing calls this directly
no test coverage detected