Compare commits
9 Commits
random-fix
...
context_de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6070a33c2 | ||
|
|
22b9b902a9 | ||
|
|
5795988d01 | ||
|
|
449642e6f4 | ||
|
|
14b6447154 | ||
|
|
7a8926773f | ||
|
|
0b868732a7 | ||
|
|
4f2581cde2 | ||
|
|
cb78b4da9f |
@@ -115,15 +115,18 @@ func deleteContextConfigCmd(q *qliksense.Qliksense) *cobra.Command {
|
|||||||
var (
|
var (
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
)
|
)
|
||||||
|
skipConfirmation := false
|
||||||
cmd = &cobra.Command{
|
cmd = &cobra.Command{
|
||||||
Use: "delete-context",
|
Use: "delete-context",
|
||||||
Short: "deletes a specific context locally (not in-cluster)",
|
Short: "deletes a specific context locally (not in-cluster)",
|
||||||
Example: `qliksense config delete-contexts <context_name>`,
|
Example: `qliksense config delete-contexts <context_name>`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return q.DeleteContextConfig(args)
|
return q.DeleteContextConfig(args, skipConfirmation)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
f := cmd.Flags()
|
||||||
|
|
||||||
|
f.BoolVar(&skipConfirmation, "yes", skipConfirmation, "skips confirmation")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
pkg/qliksense/confirmation.go
Normal file
24
pkg/qliksense/confirmation.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package qliksense
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AskForConfirmation(s string) bool {
|
||||||
|
for {
|
||||||
|
fmt.Printf("%s [y/n]: ", s)
|
||||||
|
var response string
|
||||||
|
_, err := fmt.Scanln(&response)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.EqualFold(response, "y") || strings.EqualFold(response, "yes") {
|
||||||
|
return true
|
||||||
|
} else if strings.EqualFold(response, "n") || strings.EqualFold(response, "no") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -312,7 +312,7 @@ func (q *Qliksense) ListContextConfigs() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Qliksense) DeleteContextConfig(args []string) error {
|
func (q *Qliksense) DeleteContextConfig(args []string, flag bool) error {
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
qliksenseConfigFile := filepath.Join(q.QliksenseHome, QliksenseConfigFile)
|
qliksenseConfigFile := filepath.Join(q.QliksenseHome, QliksenseConfigFile)
|
||||||
var qliksenseConfig api.QliksenseConfig
|
var qliksenseConfig api.QliksenseConfig
|
||||||
@@ -354,9 +354,17 @@ func (q *Qliksense) DeleteContextConfig(args []string) error {
|
|||||||
}
|
}
|
||||||
newLength := len(qliksenseConfig.Spec.Contexts)
|
newLength := len(qliksenseConfig.Spec.Contexts)
|
||||||
if currentLength != newLength {
|
if currentLength != newLength {
|
||||||
api.WriteToFile(&qliksenseConfig, qliksenseConfigFile)
|
ans := flag
|
||||||
fmt.Fprintln(out, chalk.Yellow.Color(chalk.Underline.TextStyle("Warning: Active resources may still be running in-cluster")))
|
if ans == false {
|
||||||
fmt.Fprintln(out, chalk.Green.Color("Successfully deleted context: "), chalk.Bold.TextStyle(args[0]))
|
ans = AskForConfirmation("Are You Sure? ")
|
||||||
|
}
|
||||||
|
if ans == true {
|
||||||
|
api.WriteToFile(&qliksenseConfig, qliksenseConfigFile)
|
||||||
|
fmt.Fprintln(out, chalk.Yellow.Color(chalk.Underline.TextStyle("Warning: Active resources may still be running in-cluster")))
|
||||||
|
fmt.Fprintln(out, chalk.Green.Color("Successfully deleted context: "), chalk.Bold.TextStyle(args[0]))
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
err := fmt.Errorf(chalk.Red.Color("Context not found"))
|
err := fmt.Errorf(chalk.Red.Color("Context not found"))
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -928,9 +928,10 @@ func TestDeleteContexts(t *testing.T) {
|
|||||||
q := New(tt.args.qlikSenseHome)
|
q := New(tt.args.qlikSenseHome)
|
||||||
var arg []string
|
var arg []string
|
||||||
arg = append(arg, tt.args.contextName)
|
arg = append(arg, tt.args.contextName)
|
||||||
if err := q.DeleteContextConfig(arg); (err != nil) != tt.wantErr {
|
if err := q.DeleteContextConfig(arg, true); (err != nil) != tt.wantErr {
|
||||||
t.Errorf("DeleteContext() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("DeleteContext() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user