[#56] Disable context switching with set-context
Users can change their current context by executing airshipctl config set-context [NAME]. The use-context subcommand was recently introduced to replace this behavior. This change removes the original behavior. Closes #56 Change-Id: Ib962d1d69a198c897aff18759fef869ee04d1beb Signed-off-by: Drew Walters <andrew.walters@att.com>
This commit is contained in:
parent
a437caa141
commit
9253f7ddba
@ -60,11 +60,13 @@ func NewCmdConfigSetContext(rootSettings *environment.AirshipCTLSettings) *cobra
|
|||||||
Example: setContextExample,
|
Example: setContextExample,
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
o.Name = args[0]
|
||||||
nFlags := cmd.Flags().NFlag()
|
nFlags := cmd.Flags().NFlag()
|
||||||
if nFlags == 0 {
|
if nFlags == 0 {
|
||||||
// Change the current context to the provided context name if no flags are provided
|
fmt.Fprintf(cmd.OutOrStdout(), "Context %q not modified. No new options provided.\n", o.Name)
|
||||||
o.CurrentContext = true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
//context name is made optional with --current flag added
|
//context name is made optional with --current flag added
|
||||||
o.Name = args[0]
|
o.Name = args[0]
|
||||||
|
@ -51,6 +51,11 @@ func TestConfigSetContext(t *testing.T) {
|
|||||||
CmdLine: "--help",
|
CmdLine: "--help",
|
||||||
Cmd: NewCmdConfigSetContext(nil),
|
Cmd: NewCmdConfigSetContext(nil),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "config-cmd-set-context-no-flags",
|
||||||
|
CmdLine: "context",
|
||||||
|
Cmd: NewCmdConfigSetContext(nil),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "config-cmd-set-context-too-many-args",
|
Name: "config-cmd-set-context-too-many-args",
|
||||||
CmdLine: "arg1 arg2",
|
CmdLine: "arg1 arg2",
|
||||||
@ -101,7 +106,7 @@ func TestSetContext(t *testing.T) {
|
|||||||
test.run(t)
|
test.run(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetCurrentContext(t *testing.T) {
|
func TestSetCurrentContextNoOptions(t *testing.T) {
|
||||||
tname := "def_target"
|
tname := "def_target"
|
||||||
given, cleanupGiven := config.InitConfig(t)
|
given, cleanupGiven := config.InitConfig(t)
|
||||||
defer cleanupGiven(t)
|
defer cleanupGiven(t)
|
||||||
@ -112,10 +117,9 @@ func TestSetCurrentContext(t *testing.T) {
|
|||||||
expected.CurrentContext = "def_target"
|
expected.CurrentContext = "def_target"
|
||||||
|
|
||||||
test := setContextTest{
|
test := setContextTest{
|
||||||
description: "Testing 'airshipctl config set-context' with a new current context",
|
|
||||||
givenConfig: given,
|
givenConfig: given,
|
||||||
args: []string{tname},
|
args: []string{tname},
|
||||||
expectedOutput: fmt.Sprintf("Context %q modified.\n", tname),
|
expectedOutput: fmt.Sprintf("Context %q not modified. No new options provided.\n", tname),
|
||||||
expectedConfig: expected,
|
expectedConfig: expected,
|
||||||
}
|
}
|
||||||
test.run(t)
|
test.run(t)
|
||||||
|
1
cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-no-flags.golden
vendored
Normal file
1
cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-no-flags.golden
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Context "context" not modified. No new options provided.
|
Loading…
Reference in New Issue
Block a user