Skip to content

Commit

Permalink
feat: add warning messages to context commands (#605)
Browse files Browse the repository at this point in the history
Related to #588

Closes #588
  • Loading branch information
phm07 committed Nov 8, 2023
1 parent e6810b1 commit d84fe36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/cmd/context/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package context

import (
"fmt"
"os"

"github.com/spf13/cobra"

Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/context/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package context

import (
"fmt"
"os"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/context/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package context

import (
"fmt"
"os"

"github.com/spf13/cobra"

Expand All @@ -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 {
Expand Down

0 comments on commit d84fe36

Please sign in to comment.