Merge "[#51] Remove current-context flag"

This commit is contained in:
Zuul 2020-02-19 07:35:35 +00:00 committed by Gerrit Code Review
commit 24542ca8bc
7 changed files with 17 additions and 21 deletions

View File

@ -35,13 +35,12 @@ Specifying a name that already exists will merge new fields on top of existing v
airshipctl config set-context e2e --%v=kube-system --%v=manifest --%v=auth-info --%v=%v airshipctl config set-context e2e --%v=kube-system --%v=manifest --%v=auth-info --%v=%v
# Update the current-context to e2e # Update the current-context to e2e
airshipctl config set-context e2e --%v=true`, airshipctl config set-context e2e`,
config.FlagNamespace, config.FlagNamespace,
config.FlagManifest, config.FlagManifest,
config.FlagAuthInfoName, config.FlagAuthInfoName,
config.FlagClusterType, config.FlagClusterType,
config.Target, config.Target)
config.FlagCurrentContext)
) )
// NewCmdConfigSetContext creates a command object for the "set-context" action, which // NewCmdConfigSetContext creates a command object for the "set-context" action, which
@ -51,13 +50,19 @@ func NewCmdConfigSetContext(rootSettings *environment.AirshipCTLSettings) *cobra
setcontextcmd := &cobra.Command{ setcontextcmd := &cobra.Command{
Use: "set-context NAME", Use: "set-context NAME",
Short: "Sets a context entry or updates current-context in the airshipctl config", Short: "Switch to a new context or update context values in the airshipctl config",
Long: setContextLong, Long: setContextLong,
Example: setContextExample, Example: setContextExample,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
nFlags := cmd.Flags().NFlag()
if nFlags == 0 {
// Change the current context to the provided context name if no flags are provided
theContext.CurrentContext = true
}
theContext.Name = cmd.Flags().Args()[0] theContext.Name = cmd.Flags().Args()[0]
modified, err := config.RunSetContext(theContext, rootSettings.Config(), true) modified, err := config.RunSetContext(theContext, rootSettings.Config(), true)
if err != nil { if err != nil {
return err return err
} }
@ -75,9 +80,6 @@ func NewCmdConfigSetContext(rootSettings *environment.AirshipCTLSettings) *cobra
} }
func sctxInitFlags(o *config.ContextOptions, setcontextcmd *cobra.Command) { func sctxInitFlags(o *config.ContextOptions, setcontextcmd *cobra.Command) {
setcontextcmd.Flags().BoolVar(&o.CurrentContext, config.FlagCurrentContext, false,
config.FlagCurrentContext+" for the context entry in airshipctl config")
setcontextcmd.Flags().StringVar(&o.Cluster, config.FlagClusterName, o.Cluster, setcontextcmd.Flags().StringVar(&o.Cluster, config.FlagClusterName, o.Cluster,
config.FlagClusterName+" for the context entry in airshipctl config") config.FlagClusterName+" for the context entry in airshipctl config")

View File

@ -112,12 +112,9 @@ func TestSetCurrentContext(t *testing.T) {
expconf.CurrentContext = "def_target" expconf.CurrentContext = "def_target"
test := setContextTest{ test := setContextTest{
description: "Testing 'airshipctl config set-context' with a new current context", description: "Testing 'airshipctl config set-context' with a new current context",
config: conf, config: conf,
args: []string{tname}, args: []string{tname},
flags: []string{
"--" + config.FlagCurrentContext + "=true",
},
expected: `Context "` + tname + `" modified.` + "\n", expected: `Context "` + tname + `" modified.` + "\n",
expectedConfig: expconf, expectedConfig: expconf,
} }

View File

@ -11,7 +11,7 @@ Available Commands:
help Help about any command help Help about any command
init Generate initial configuration files for airshipctl init Generate initial configuration files for airshipctl
set-cluster Sets a cluster entry in the airshipctl config set-cluster Sets a cluster entry in the airshipctl config
set-context Sets a context entry or updates current-context in the airshipctl config set-context Switch to a new context or update context values in the airshipctl config
set-credentials Sets a user entry in the airshipctl config set-credentials Sets a user entry in the airshipctl config
Flags: Flags:

View File

@ -11,7 +11,7 @@ Available Commands:
help Help about any command help Help about any command
init Generate initial configuration files for airshipctl init Generate initial configuration files for airshipctl
set-cluster Sets a cluster entry in the airshipctl config set-cluster Sets a cluster entry in the airshipctl config
set-context Sets a context entry or updates current-context in the airshipctl config set-context Switch to a new context or update context values in the airshipctl config
set-credentials Sets a user entry in the airshipctl config set-credentials Sets a user entry in the airshipctl config
Flags: Flags:

View File

@ -8,12 +8,11 @@ Examples:
airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target
# Update the current-context to e2e # Update the current-context to e2e
airshipctl config set-context e2e --current-context=true airshipctl config set-context e2e
Flags: Flags:
--cluster string cluster for the context entry in airshipctl config --cluster string cluster for the context entry in airshipctl config
--cluster-type string cluster-type for the context entry in airshipctl config --cluster-type string cluster-type for the context entry in airshipctl config
--current-context current-context for the context entry in airshipctl config
-h, --help help for set-context -h, --help help for set-context
--manifest string manifest for the context entry in airshipctl config --manifest string manifest for the context entry in airshipctl config
--namespace string namespace for the context entry in airshipctl config --namespace string namespace for the context entry in airshipctl config

View File

@ -8,12 +8,11 @@ Examples:
airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target
# Update the current-context to e2e # Update the current-context to e2e
airshipctl config set-context e2e --current-context=true airshipctl config set-context e2e
Flags: Flags:
--cluster string cluster for the context entry in airshipctl config --cluster string cluster for the context entry in airshipctl config
--cluster-type string cluster-type for the context entry in airshipctl config --cluster-type string cluster-type for the context entry in airshipctl config
--current-context current-context for the context entry in airshipctl config
-h, --help help for set-context -h, --help help for set-context
--manifest string manifest for the context entry in airshipctl config --manifest string manifest for the context entry in airshipctl config
--namespace string namespace for the context entry in airshipctl config --namespace string namespace for the context entry in airshipctl config

View File

@ -11,12 +11,11 @@ Examples:
airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target
# Update the current-context to e2e # Update the current-context to e2e
airshipctl config set-context e2e --current-context=true airshipctl config set-context e2e
Flags: Flags:
--cluster string cluster for the context entry in airshipctl config --cluster string cluster for the context entry in airshipctl config
--cluster-type string cluster-type for the context entry in airshipctl config --cluster-type string cluster-type for the context entry in airshipctl config
--current-context current-context for the context entry in airshipctl config
-h, --help help for set-context -h, --help help for set-context
--manifest string manifest for the context entry in airshipctl config --manifest string manifest for the context entry in airshipctl config
--namespace string namespace for the context entry in airshipctl config --namespace string namespace for the context entry in airshipctl config