context does not exist

This commit is contained in:
knoflook 2021-08-05 12:02:13 +02:00
parent efb9d6f6a5
commit edaedeac3a
Signed by: knoflook
GPG Key ID: D6A1D0E8FC4FEF1C
1 changed files with 57 additions and 1 deletions

View File

@ -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
},
}