diff --git a/cli/app/remove.go b/cli/app/remove.go index b211afbf..bdefb0c9 100644 --- a/cli/app/remove.go +++ b/cli/app/remove.go @@ -1,7 +1,16 @@ package app import ( + "context" + "errors" + "fmt" + "coopcloud.tech/abra/cli/internal" + "coopcloud.tech/abra/client" + "coopcloud.tech/abra/config" + "github.com/AlecAivazis/survey/v2" + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/filters" "github.com/urfave/cli/v2" ) @@ -16,9 +25,56 @@ var VolumesFlag = &cli.BoolFlag{ } var appRemoveCommand = &cli.Command{ - Name: "remove", + Name: "remove", + Aliases: []string{"rm", "delete"}, Flags: []cli.Flag{ VolumesFlag, internal.SecretsFlag, }, + Action: func(c *cli.Context) error { + // Check if app name was provided by user + AppName := c.Args().First() + if AppName == "" { + internal.ShowSubcommandHelpAndError(c, errors.New("No app name provided!")) + } + // Make sure that the user really wants to delete the app + response := false + prompt := &survey.Confirm{ + Message: "About to delete " + AppName + ", are you sure?", + } + survey.AskOne(prompt, &response) + if response == false { + return errors.New("User aborted app removal") + } + // Remove the file + AppFiles, err := config.LoadAppFiles("") + if err != nil { + return err + } + AppPath := AppFiles[AppName].Path + host := AppFiles[AppName].Server + // Initialize docker client + ctx := context.Background() + cl, err := client.NewClientWithContext(host) + if err != nil { + return err + } + + fmt.Println(AppPath) //to be replaced by a remove method + + // Check if the app has secrets and remove them too + if internal.Secrets { + fs := filters.NewArgs() + fs.Add("name", AppName) + SecretList, err := cl.SecretList(ctx, types.SecretListOptions{Filters: fs}) + if err != nil { + return err + } + fmt.Println(SecretList) + } + + // Remove the volumes if desired + + return nil + }, }