From 9253f7ddbab1d20e3fee12a9690e62ca4afa7fb3 Mon Sep 17 00:00:00 2001 From: Drew Walters Date: Fri, 21 Feb 2020 10:38:24 -0600 Subject: [PATCH] [#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 --- cmd/config/set_context.go | 6 ++++-- cmd/config/set_context_test.go | 10 +++++++--- .../config-cmd-set-context-no-flags.golden | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-no-flags.golden diff --git a/cmd/config/set_context.go b/cmd/config/set_context.go index f440cdd62..ec07b74f0 100644 --- a/cmd/config/set_context.go +++ b/cmd/config/set_context.go @@ -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] diff --git a/cmd/config/set_context_test.go b/cmd/config/set_context_test.go index 7ae29005d..b017e7b64 100644 --- a/cmd/config/set_context_test.go +++ b/cmd/config/set_context_test.go @@ -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) diff --git a/cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-no-flags.golden b/cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-no-flags.golden new file mode 100644 index 000000000..3880d99cc --- /dev/null +++ b/cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-no-flags.golden @@ -0,0 +1 @@ +Context "context" not modified. No new options provided.