MCPcopy
hub / github.com/kubevela/kubevela / GetNamespaceAndSource

Function GetNamespaceAndSource

pkg/cmd/utils.go:53–75  ·  view source on GitHub ↗

GetNamespaceAndSource gets namespace from command flags and env and also returns source of the namespace

(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

51
52// GetNamespaceAndSource gets namespace from command flags and env and also returns source of the namespace
53func 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
78func GetGroup(cmd *cobra.Command) string {

Callers

nothing calls this directly

Calls 3

GetEnvByNameFunction · 0.92
GetCurrentEnvFunction · 0.92
FlagsMethod · 0.80

Tested by

no test coverage detected