feat: prompt for confirmation on storage:destroy
`storage:destroy` now prompts for confirmation before removing a named storage entry, matching the behavior of other destructive commands such as `apps:destroy` and `network:destroy`. The prompt can be skipped with the `--force` flag or the global `dokku --force` flag for non-interactive callers.
This commit is contained in:
@@ -95,8 +95,10 @@ func CommandCreate(input CommandCreateInput) error {
|
||||
}
|
||||
|
||||
// CommandDestroy removes a registered storage entry. Refuses to remove
|
||||
// an entry that any app still has attached.
|
||||
func CommandDestroy(name string) error {
|
||||
// an entry that any app still has attached. Prompts for confirmation
|
||||
// unless force is set (or the global --force flag exported
|
||||
// DOKKU_APPS_FORCE_DELETE).
|
||||
func CommandDestroy(name string, force bool) error {
|
||||
if name == "" {
|
||||
return errors.New("storage entry name is required")
|
||||
}
|
||||
@@ -112,6 +114,15 @@ func CommandDestroy(name string) error {
|
||||
return fmt.Errorf("storage entry %q is still mounted by app(s): %s", name, strings.Join(using, ", "))
|
||||
}
|
||||
|
||||
if os.Getenv("DOKKU_APPS_FORCE_DELETE") == "1" {
|
||||
force = true
|
||||
}
|
||||
if !force {
|
||||
if err := common.AskForDestructiveConfirmation(name, "storage entry"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
entry, err := LoadEntry(name)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -19,7 +19,7 @@ Additional commands:`
|
||||
|
||||
helpContent = `
|
||||
storage:create <name> [<path>] [flags], Register a named storage entry
|
||||
storage:destroy <name>, Remove a named storage entry (must be unmounted from every app first)
|
||||
storage:destroy <name> [--force], Remove a named storage entry (must be unmounted from every app first)
|
||||
storage:ensure-directory [--chown option] <directory>, [DEPRECATED] use storage:create instead
|
||||
storage:exec <name> [-- <cmd>...], Run a command (or shell) in a temporary container that mounts the entry
|
||||
storage:info <name> [--format text|json], Show details for one storage entry
|
||||
|
||||
@@ -58,8 +58,9 @@ func main() {
|
||||
})
|
||||
case "destroy":
|
||||
args := flag.NewFlagSet("storage:destroy", flag.ExitOnError)
|
||||
force := args.Bool("force", false, "--force: force destroy without confirmation")
|
||||
args.Parse(os.Args[2:])
|
||||
err = storage.CommandDestroy(args.Arg(0))
|
||||
err = storage.CommandDestroy(args.Arg(0), *force)
|
||||
case "ensure-directory":
|
||||
args := flag.NewFlagSet("storage:ensure-directory", flag.ExitOnError)
|
||||
chown := args.String("chown", "herokuish", "--chown: chown option (herokuish, heroku, paketo, root, false)")
|
||||
|
||||
@@ -20,7 +20,7 @@ Additional commands:`
|
||||
|
||||
helpContent = `
|
||||
storage:create <name> [<path>] [flags], Register a named storage entry
|
||||
storage:destroy <name>, Remove a named storage entry (must be unmounted from every app first)
|
||||
storage:destroy <name> [--force], Remove a named storage entry (must be unmounted from every app first)
|
||||
storage:ensure-directory [--chown option] <directory>, [DEPRECATED] use storage:create instead
|
||||
storage:exec <name> [-- <cmd>...], Run a command (or shell) in a temporary container that mounts the entry
|
||||
storage:info <name> [--format text|json], Show details for one storage entry
|
||||
|
||||
Reference in New Issue
Block a user