Add abra app remove command #43
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/client"
|
||||
@ -29,7 +30,6 @@ var appRemoveCommand = &cli.Command{
|
||||
Aliases: []string{"rm", "delete"},
|
||||
Flags: []cli.Flag{
|
||||
knoflook marked this conversation as resolved
Outdated
|
||||
VolumesFlag,
|
||||
internal.SecretsFlag,
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
// Check if app name was provided by user
|
||||
@ -59,21 +59,69 @@ var appRemoveCommand = &cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(AppPath) //to be replaced by a remove method
|
||||
err = os.Remove(AppPath)
|
||||
decentral1se marked this conversation as resolved
Outdated
decentral1se
commented
`appFiles, err := config.LoadAppFiles()`
knoflook
commented
Can't do it that way, if you remove "" LoadAppFiles returns an empty map[] Can't do it that way, if you remove "" LoadAppFiles returns an empty map[]
|
||||
if err != nil {
|
||||
return err
|
||||
knoflook marked this conversation as resolved
Outdated
decentral1se
commented
`logrus.Fatal(err)`
|
||||
}
|
||||
|
||||
knoflook marked this conversation as resolved
Outdated
decentral1se
commented
`appPath := AppFiles[appName].Path`
|
||||
// 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})
|
||||
fs := filters.NewArgs()
|
||||
fs.Add("name", AppName)
|
||||
SecretList, err := cl.SecretList(ctx, types.SecretListOptions{Filters: fs})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: Actually remove secrets
|
||||
Secrets := make(map[string]string)
|
||||
SecretNames := []string{}
|
||||
knoflook marked this conversation as resolved
decentral1se
commented
```golang
if err != nil {
logrus.Fatal(err)
}
logrus.Info(fmt.Sprintf("File: %s removed", appPath))
```
|
||||
for _, cont := range SecretList {
|
||||
Secrets[cont.Spec.Annotations.Name] = cont.ID //we have to map the names to ID's
|
||||
SecretNames = append(SecretNames, cont.Spec.Annotations.Name)
|
||||
//cl.SecretRemove(ctx, cont.ID)
|
||||
}
|
||||
SecretNamesToRemove := []string{}
|
||||
SecretsPrompt := &survey.MultiSelect{
|
||||
Message: "Which secrets do you want to remove?",
|
||||
Options: SecretNames,
|
||||
Default: SecretNames,
|
||||
}
|
||||
knoflook marked this conversation as resolved
Outdated
decentral1se
commented
`logrus.Fatal(err)`
|
||||
survey.AskOne(SecretsPrompt, &SecretNamesToRemove)
|
||||
for _, name := range SecretNamesToRemove {
|
||||
err := cl.SecretRemove(ctx, Secrets[name])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(SecretList)
|
||||
// SecretIDsToRemove = append(SecretIDsToRemove, Secrets[name])
|
||||
}
|
||||
|
||||
// Remove the volumes if desired
|
||||
if Volumes == true {
|
||||
VolumeListOKBody, err := cl.VolumeList(ctx, fs)
|
||||
VolumeList := VolumeListOKBody.Volumes
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Vols := []string{}
|
||||
for _, vol := range VolumeList {
|
||||
Vols = append(Vols, vol.Name)
|
||||
}
|
||||
RemoveVols := []string{}
|
||||
VolumesPrompt := &survey.MultiSelect{
|
||||
Message: "Which volumes do you want to remove?",
|
||||
Options: Vols,
|
||||
knoflook marked this conversation as resolved
Outdated
decentral1se
commented
Let's remove that 🙃 Let's remove that 🙃
|
||||
Default: Vols,
|
||||
}
|
||||
knoflook marked this conversation as resolved
Outdated
decentral1se
commented
```golang
if err != nil {
logrus.Fatal(err)
}
logrus.Info(fmt.Sprintf("Secret: %s removed", name))
```
|
||||
survey.AskOne(VolumesPrompt, &RemoveVols)
|
||||
fmt.Println("Volumes to remove: ", RemoveVols) //TODO: Replace with a remove method
|
||||
for _, vol := range RemoveVols {
|
||||
err := cl.VolumeRemove(ctx, vol, false) // false is for force removing
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Volumes will not be removed")
|
||||
}
|
||||
knoflook marked this conversation as resolved
decentral1se
commented
`logrus.Fatal(err)`
|
||||
|
||||
return nil
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user
This is a general flag we'll add to other sub-commands, it can live in cli/internal/common.go?