fix!: make "app rm" more explicit & simpler
We point users to "app volume/secret remove" for more specific deletion of other app data resources now. The idea is that if you lose the env file locally, then you can't clean up anything after. So it is handy to have a sort of WARNING barrier to deleting that file. This flow is the only way to get Abra to delete your local env file. It now feels more documented and sufficiently scary in the UI/UX to merit that. Hopefully addresses the ticket sufficiently. Closes coop-cloud/organising#335.
This commit is contained in:
parent
521570224b
commit
a93786c6be
@ -15,35 +15,43 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// Volumes stores the variable from VolumesFlag
|
||||
var Volumes bool
|
||||
|
||||
// VolumesFlag is used to specify if volumes should be deleted when deleting an app
|
||||
var VolumesFlag = &cli.BoolFlag{
|
||||
Name: "volumes, V",
|
||||
Destination: &Volumes,
|
||||
}
|
||||
|
||||
var appRemoveCommand = cli.Command{
|
||||
Name: "remove",
|
||||
Aliases: []string{"rm"},
|
||||
ArgsUsage: "<domain>",
|
||||
Usage: "Remove an already undeployed app",
|
||||
Usage: "Remove all app data, locally and remotely",
|
||||
Description: `
|
||||
This command removes everything related to an app which is already undeployed.
|
||||
|
||||
By default, it will prompt for confirmation before proceeding. All secrets,
|
||||
volumes and the local app env file will be deleted.
|
||||
|
||||
Only run this command when you are sure you want to completely remove the app
|
||||
and all associated app data. This is a destructive action, Be Careful!
|
||||
|
||||
If you would like to delete specific volumes or secrets, please use removal
|
||||
sub-commands under "app volume" and "app secret" instead.
|
||||
|
||||
Please note, if you delete the local app env file without removing volumes and
|
||||
secrets first, Abra will *not* be able to help you remove them afterwards.
|
||||
|
||||
To delete everything without prompt, use the "--force/-f" or the "--no-input/n"
|
||||
flag.
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
VolumesFlag,
|
||||
internal.ForceFlag,
|
||||
internal.DebugFlag,
|
||||
internal.NoInputFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
BashComplete: autocomplete.AppNameComplete,
|
||||
Before: internal.SubCommandBefore,
|
||||
Action: func(c *cli.Context) error {
|
||||
app := internal.ValidateApp(c)
|
||||
|
||||
if !internal.Force && !internal.NoInput {
|
||||
response := false
|
||||
prompt := &survey.Confirm{
|
||||
Message: fmt.Sprintf("about to remove %s, are you sure?", app.Name),
|
||||
}
|
||||
msg := "ALERTA ALERTA: this will completely remove %s data and configurations locally and remotely, are you sure?"
|
||||
prompt := &survey.Confirm{Message: fmt.Sprintf(msg, app.Name)}
|
||||
if err := survey.AskOne(prompt, &response); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -84,26 +92,7 @@ var appRemoveCommand = cli.Command{
|
||||
}
|
||||
|
||||
if len(secrets) > 0 {
|
||||
var secretNamesToRemove []string
|
||||
|
||||
if !internal.Force && !internal.NoInput {
|
||||
secretsPrompt := &survey.MultiSelect{
|
||||
Message: "which secrets do you want to remove?",
|
||||
Help: "'x' indicates selected, enter / return to confirm, ctrl-c to exit, vim mode is enabled",
|
||||
VimMode: true,
|
||||
Options: secretNames,
|
||||
Default: secretNames,
|
||||
}
|
||||
if err := survey.AskOne(secretsPrompt, &secretNamesToRemove); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if internal.Force || internal.NoInput {
|
||||
secretNamesToRemove = secretNames
|
||||
}
|
||||
|
||||
for _, name := range secretNamesToRemove {
|
||||
for _, name := range secretNames {
|
||||
err := cl.SecretRemove(context.Background(), secrets[name])
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
@ -131,44 +120,24 @@ var appRemoveCommand = cli.Command{
|
||||
}
|
||||
|
||||
if len(vols) > 0 {
|
||||
if Volumes {
|
||||
var removeVols []string
|
||||
if !internal.Force && !internal.NoInput {
|
||||
volumesPrompt := &survey.MultiSelect{
|
||||
Message: "which volumes do you want to remove?",
|
||||
Help: "'x' indicates selected, enter / return to confirm, ctrl-c to exit, vim mode is enabled",
|
||||
VimMode: true,
|
||||
Options: vols,
|
||||
Default: vols,
|
||||
}
|
||||
if err := survey.AskOne(volumesPrompt, &removeVols); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
var removeVols []string
|
||||
for _, vol := range removeVols {
|
||||
err := cl.VolumeRemove(context.Background(), vol, internal.Force) // last argument is for force removing
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
for _, vol := range removeVols {
|
||||
err := cl.VolumeRemove(context.Background(), vol, internal.Force) // last argument is for force removing
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
logrus.Info(fmt.Sprintf("volume %s removed", vol))
|
||||
}
|
||||
} else {
|
||||
logrus.Info("no volumes were removed")
|
||||
logrus.Info(fmt.Sprintf("volume %s removed", vol))
|
||||
}
|
||||
} else {
|
||||
if Volumes {
|
||||
logrus.Info("no volumes to remove")
|
||||
}
|
||||
logrus.Info("no volumes to remove")
|
||||
}
|
||||
|
||||
err = os.Remove(app.Path)
|
||||
if err != nil {
|
||||
if err = os.Remove(app.Path); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
logrus.Info(fmt.Sprintf("file: %s removed", app.Path))
|
||||
|
||||
return nil
|
||||
},
|
||||
BashComplete: autocomplete.AppNameComplete,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user