Skip to content

Commit

Permalink
Only allow use-context on existing contexts (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmholmes authored Jan 4, 2024
1 parent 01faa49 commit a80f3ac
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,15 @@ func GetContexts() error {
}

func UseContext(context string) error {
viper.Set(CURRENT_CONTEXT, context)
return Write()
contexts := map[string]interface{}{}
viper.UnmarshalKey("contexts", &contexts)
for k := range contexts {
if k == context {
viper.Set(CURRENT_CONTEXT, context)
return Write()
}
}
return fmt.Errorf("Context %s not found", context)
}

func CurrentContext() (*Context, error) {
Expand Down

0 comments on commit a80f3ac

Please sign in to comment.