Files
kubevela/references/cli/common.go
qiaozp b38aa1cdf0 Fix: Align -n command argument (#2719)
* add namespace flag

fix

fix test

fix tests

* try test

* try test

* fix tests
2021-11-19 18:00:03 +08:00

69 lines
2.1 KiB
Go

/*
Copyright 2021 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cli
import (
"github.com/spf13/cobra"
"github.com/oam-dev/kubevela/pkg/utils/common"
)
// constants used in `svc` command
const (
App = "app"
Service = "svc"
Namespace = "namespace"
// FlagDescription command flag to specify the description of the definition
FlagDescription = "desc"
// FlagDryRun command flag to disable actual changes and only display intend changes
FlagDryRun = "dry-run"
// FlagTemplateYAML command flag to specify which existing template YAML file to use
FlagTemplateYAML = "template-yaml"
// FlagOutput command flag to specify which file to save
FlagOutput = "output"
// FlagMessage command flag to specify which file to save
FlagMessage = "message"
// FlagType command flag to specify which definition type to use
FlagType = "type"
// FlagNamespace command flag to specify which namespace to use
FlagNamespace = "namespace"
// FlagInteractive command flag to specify the use of interactive process
FlagInteractive = "interactive"
)
func addNamespaceArg(cmd *cobra.Command) {
cmd.Flags().StringP(Namespace, "n", "", "specify the namespace to use")
}
// GetFlagNamespaceOrEnv will get env and namespace flag, namespace flag takes the priority
func GetFlagNamespaceOrEnv(cmd *cobra.Command, args common.Args) (string, error) {
namespace, err := cmd.Flags().GetString(Namespace)
if err != nil {
return "", err
}
if namespace != "" {
return namespace, nil
}
velaEnv, err := GetFlagEnvOrCurrent(cmd, args)
if err != nil {
return "", err
}
return velaEnv.Namespace, nil
}