From e58190af9de5fecacd8331d11e863cde5c99fed2 Mon Sep 17 00:00:00 2001 From: pauhull Date: Wed, 8 Nov 2023 09:34:04 +0100 Subject: [PATCH] feat: add warning messages to context commands Related to #588 Closes #588 --- internal/cmd/context/active.go | 4 ++++ internal/cmd/context/delete.go | 2 ++ internal/cmd/context/use.go | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/internal/cmd/context/active.go b/internal/cmd/context/active.go index a37f89db..1f1c1198 100644 --- a/internal/cmd/context/active.go +++ b/internal/cmd/context/active.go @@ -2,6 +2,7 @@ package context import ( "fmt" + "os" "github.com/spf13/cobra" @@ -21,6 +22,9 @@ func newActiveCommand(cli *state.State) *cobra.Command { } func runActive(cli *state.State, cmd *cobra.Command, args []string) error { + if os.Getenv("HCLOUD_TOKEN") != "" { + _, _ = fmt.Fprintln(os.Stderr, "Warning: HCLOUD_TOKEN is set. The active context will have no effect.") + } if cli.Config.ActiveContext != nil { fmt.Println(cli.Config.ActiveContext.Name) } diff --git a/internal/cmd/context/delete.go b/internal/cmd/context/delete.go index 625dec21..8b9423a4 100644 --- a/internal/cmd/context/delete.go +++ b/internal/cmd/context/delete.go @@ -2,6 +2,7 @@ package context import ( "fmt" + "os" "github.com/spf13/cobra" @@ -29,6 +30,7 @@ func runDelete(cli *state.State, cmd *cobra.Command, args []string) error { return fmt.Errorf("context not found: %v", name) } if cli.Config.ActiveContext == context { + _, _ = fmt.Fprintln(os.Stderr, "Warning: You are deleting the currently active context. Please select a new active context.") cli.Config.ActiveContext = nil } cli.Config.RemoveContext(context) diff --git a/internal/cmd/context/use.go b/internal/cmd/context/use.go index 7b18c32c..cc5d4caa 100644 --- a/internal/cmd/context/use.go +++ b/internal/cmd/context/use.go @@ -2,6 +2,7 @@ package context import ( "fmt" + "os" "github.com/spf13/cobra" @@ -23,6 +24,9 @@ func newUseCommand(cli *state.State) *cobra.Command { } func runUse(cli *state.State, cmd *cobra.Command, args []string) error { + if os.Getenv("HCLOUD_TOKEN") != "" { + _, _ = fmt.Fprintln(os.Stderr, "Warning: HCLOUD_TOKEN is set. The active context will have no effect.") + } name := args[0] context := cli.Config.ContextByName(name) if context == nil {