[#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:
Drew Walters 2020-02-21 10:38:24 -06:00
parent a437caa141
commit 9253f7ddba
3 changed files with 12 additions and 5 deletions

View File

@ -60,11 +60,13 @@ func NewCmdConfigSetContext(rootSettings *environment.AirshipCTLSettings) *cobra
Example: setContextExample,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
o.Name = args[0]
nFlags := cmd.Flags().NFlag()
if nFlags == 0 {
// Change the current context to the provided context name if no flags are provided
o.CurrentContext = true
fmt.Fprintf(cmd.OutOrStdout(), "Context %q not modified. No new options provided.\n", o.Name)
return nil
}
if len(args) == 1 {
//context name is made optional with --current flag added
o.Name = args[0]

View File

@ -51,6 +51,11 @@ func TestConfigSetContext(t *testing.T) {
CmdLine: "--help",
Cmd: NewCmdConfigSetContext(nil),
},
{
Name: "config-cmd-set-context-no-flags",
CmdLine: "context",
Cmd: NewCmdConfigSetContext(nil),
},
{
Name: "config-cmd-set-context-too-many-args",
CmdLine: "arg1 arg2",
@ -101,7 +106,7 @@ func TestSetContext(t *testing.T) {
test.run(t)
}
func TestSetCurrentContext(t *testing.T) {
func TestSetCurrentContextNoOptions(t *testing.T) {
tname := "def_target"
given, cleanupGiven := config.InitConfig(t)
defer cleanupGiven(t)
@ -112,10 +117,9 @@ func TestSetCurrentContext(t *testing.T) {
expected.CurrentContext = "def_target"
test := setContextTest{
description: "Testing 'airshipctl config set-context' with a new current context",
givenConfig: given,
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,
}
test.run(t)

View File

@ -0,0 +1 @@
Context "context" not modified. No new options provided.