MCPcopy
hub / github.com/kubevela/kubevela / GetNamespace

Function GetNamespace

pkg/cmd/utils.go:28–50  ·  view source on GitHub ↗

GetNamespace get namespace from command flags and env

(_ Factory, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

26
27// GetNamespace get namespace from command flags and env
28func 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
53func GetNamespaceAndSource(cmd *cobra.Command) (string, string) {

Callers

nothing calls this directly

Calls 3

GetEnvByNameFunction · 0.92
GetCurrentEnvFunction · 0.92
FlagsMethod · 0.80

Tested by

no test coverage detected