cmd/geth: improve prompt

This commit is contained in:
Gary Rong 2023-12-21 21:46:13 +08:00
parent a3991058be
commit 81bbc4f1c0

View file

@ -238,22 +238,30 @@ func removeFolder(dir string) {
// confirmAndRemoveDB prompts the user for a last confirmation and removes the // confirmAndRemoveDB prompts the user for a last confirmation and removes the
// list of folders if accepted. // list of folders if accepted.
func confirmAndRemoveDB(paths []string, kind string) { func confirmAndRemoveDB(paths []string, kind string) {
confirm, err := prompt.Stdin.PromptConfirm(fmt.Sprintf("Remove %s (%s)?", kind, paths)) msg := fmt.Sprintf("Remove %s?\n", kind)
for _, path := range paths {
msg += fmt.Sprintf("\t- %s\n", path)
}
confirm, err := prompt.Stdin.PromptConfirm(msg)
switch { switch {
case err != nil: case err != nil:
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
case !confirm: case !confirm:
log.Info("Database deletion skipped", "kind", kind, "paths", paths) log.Info("Database deletion skipped", "kind", kind, "paths", paths)
default: default:
start := time.Now() var (
deleted []string
start = time.Now()
)
for _, path := range paths { for _, path := range paths {
if common.FileExist(path) { if common.FileExist(path) {
removeFolder(path) removeFolder(path)
deleted = append(deleted, path)
} else { } else {
log.Info("Folder is not existent", "path", path) log.Info("Folder is not existent", "path", path)
} }
} }
log.Info("Database successfully deleted", "kind", kind, "paths", paths, "elapsed", common.PrettyDuration(time.Since(start))) log.Info("Database successfully deleted", "kind", kind, "paths", deleted, "elapsed", common.PrettyDuration(time.Since(start)))
} }
} }