Skip to content
Snippets Groups Projects
Commit 1e4ad6c8 authored by Alex Clemmer's avatar Alex Clemmer Committed by GitHub
Browse files

Merge pull request #28 from jessicayuen/default-namespaces

 Set env namespace to default when namespace not provided
parents c6010021 209a5abf
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,8 @@ const ( ...@@ -31,6 +31,8 @@ const (
flagEnvURI = "uri" flagEnvURI = "uri"
flagEnvNamespace = "namespace" flagEnvNamespace = "namespace"
flagEnvContext = "context" flagEnvContext = "context"
defaultNamespace = "default"
) )
func init() { func init() {
...@@ -118,6 +120,10 @@ var envAddCmd = &cobra.Command{ ...@@ -118,6 +120,10 @@ var envAddCmd = &cobra.Command{
return err return err
} }
if len(namespace) == 0 {
namespace = defaultNamespace
}
if len(uri) == 0 { if len(uri) == 0 {
// If uri is not provided, use the provided context. // If uri is not provided, use the provided context.
// If context is also not provided, use the current context. // If context is also not provided, use the current context.
...@@ -133,7 +139,7 @@ var envAddCmd = &cobra.Command{ ...@@ -133,7 +139,7 @@ var envAddCmd = &cobra.Command{
} }
// If namespace is not provided, use the default namespace provided in the context. // If namespace is not provided, use the default namespace provided in the context.
if len(namespace) == 0 { if !flags.Changed(flagEnvNamespace) {
namespace = ns namespace = ns
} }
} }
...@@ -308,6 +314,11 @@ var envSetCmd = &cobra.Command{ ...@@ -308,6 +314,11 @@ var envSetCmd = &cobra.Command{
return err return err
} }
// If namespace flag is provided but without a value, use the default namespace.
if flags.Changed(flagEnvNamespace) && len(namespace) == 0 {
namespace = defaultNamespace
}
if len(context) != 0 { if len(context) != 0 {
uri, _, err = resolveContext(&context) uri, _, err = resolveContext(&context)
if err != nil { if err != nil {
...@@ -356,7 +367,7 @@ func commonEnvFlags(flags *pflag.FlagSet) (uri, namespace, context string, err e ...@@ -356,7 +367,7 @@ func commonEnvFlags(flags *pflag.FlagSet) (uri, namespace, context string, err e
return "", "", "", err return "", "", "", err
} }
if len(context) != 0 && len(uri) != 0 { if flags.Changed(flagEnvContext) && flags.Changed(flagEnvURI) {
return "", "", "", fmt.Errorf("flags '%s' and '%s' are mutually exclusive, because '%s' has a URI. Try setting '%s', '%s' to the desired values", return "", "", "", fmt.Errorf("flags '%s' and '%s' are mutually exclusive, because '%s' has a URI. Try setting '%s', '%s' to the desired values",
flagEnvContext, flagEnvURI, flagEnvContext, flagEnvURI, flagEnvNamespace) flagEnvContext, flagEnvURI, flagEnvContext, flagEnvURI, flagEnvNamespace)
} }
......
...@@ -356,10 +356,8 @@ func overrideCluster(envName string) error { ...@@ -356,10 +356,8 @@ func overrideCluster(envName string) error {
clusterName := clusterURIs[env.URI] clusterName := clusterURIs[env.URI]
log.Debugf("Overwriting --cluster flag with '%s'", clusterName) log.Debugf("Overwriting --cluster flag with '%s'", clusterName)
overrides.Context.Cluster = clusterName overrides.Context.Cluster = clusterName
if len(env.Namespace) != 0 { log.Debugf("Overwriting --namespace flag with '%s'", env.Namespace)
log.Debugf("Overwriting --namespace flag with '%s'", env.Namespace) overrides.Context.Namespace = env.Namespace
overrides.Context.Namespace = env.Namespace
}
return nil return nil
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment