refactor: move confirmation logic to common.go
This commit is contained in:
1 parent
bd47c76d26
commit
0b758d2ba0
2 files changed
+22
-13
No files matched your search
@@ -75,6 +75,27 @@ func AppRoot(appName string) string {
|
|||||||
return fmt.Sprintf("%v/%v", dokkuRoot, appName)
|
return fmt.Sprintf("%v/%v", dokkuRoot, appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks for confirmation on destructive actions
|
||||||
|
func AskForDestructiveConfirmation(name string, objectType string) error {
|
||||||
|
LogWarn("WARNING: Potentially Destructive Action")
|
||||||
|
LogWarn(fmt.Sprintf("This command will destroy %v %v.", objectType, name))
|
||||||
|
LogWarn(fmt.Sprintf("To proceed, type \"%v\"", name))
|
||||||
|
fmt.Print("> ")
|
||||||
|
var response string
|
||||||
|
_, err := fmt.Scanln(&response)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if response != name {
|
||||||
|
LogStderr("Confirmation did not match test. Aborted.")
|
||||||
|
os.Exit(1)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented
|
// GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented
|
||||||
func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName string) {
|
func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName string) {
|
||||||
if appName == "" {
|
if appName == "" {
|
||||||
|
|||||||
@@ -41,21 +41,9 @@ func CommandDestroy(networkName string, forceDestroy bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !forceDestroy {
|
if !forceDestroy {
|
||||||
common.LogWarn("WARNING: Potentially Destructive Action")
|
if err := common.AskForDestructiveConfirmation(networkName, "network"); err != nil {
|
||||||
common.LogWarn(fmt.Sprintf("This command will destroy network %v.", networkName))
|
|
||||||
common.LogWarn(fmt.Sprintf("To proceed, type \"%v\"", networkName))
|
|
||||||
fmt.Print("> ")
|
|
||||||
var response string
|
|
||||||
_, err := fmt.Scanln(&response)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if response != networkName {
|
|
||||||
common.LogStderr("Confirmation did not match test. Aborted.")
|
|
||||||
os.Exit(1)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
common.LogInfo1Quiet(fmt.Sprintf("Destroying network %v", networkName))
|
common.LogInfo1Quiet(fmt.Sprintf("Destroying network %v", networkName))
|
||||||
|
|||||||
Reference in new issue
Block a user