107 lines
2.3 KiB
Go
107 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/client"
|
|
"coopcloud.tech/abra/pkg/config"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var appVolumeListCommand = &cli.Command{
|
|
Name: "list",
|
|
Usage: "List volumes associated with an app",
|
|
Aliases: []string{"ls"},
|
|
Action: func(c *cli.Context) error {
|
|
app := internal.ValidateApp(c)
|
|
|
|
volumeList, err := client.GetVolumes(c.Context, app.Server, app.Name)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
table := abraFormatter.CreateTable([]string{"driver", "volume name"})
|
|
var volTable [][]string
|
|
for _, volume := range volumeList {
|
|
volRow := []string{
|
|
volume.Driver,
|
|
volume.Name,
|
|
}
|
|
volTable = append(volTable, volRow)
|
|
}
|
|
|
|
table.AppendBulk(volTable)
|
|
table.Render()
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var appVolumeRemoveCommand = &cli.Command{
|
|
Name: "remove",
|
|
Usage: "Remove volume(s) associated with an app",
|
|
Aliases: []string{"rm"},
|
|
Flags: []cli.Flag{
|
|
internal.ForceFlag,
|
|
},
|
|
Action: func(c *cli.Context) error {
|
|
app := internal.ValidateApp(c)
|
|
|
|
volumeList, err := client.GetVolumes(c.Context, app.Server, app.Name)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
volumeNames := client.GetVolumeNames(volumeList)
|
|
|
|
var volumesToRemove []string
|
|
if !internal.Force {
|
|
volumesPrompt := &survey.MultiSelect{
|
|
Message: "which volumes do you want to remove?",
|
|
Options: volumeNames,
|
|
Default: volumeNames,
|
|
}
|
|
if err := survey.AskOne(volumesPrompt, &volumesToRemove); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
} else {
|
|
volumesToRemove = volumeNames
|
|
}
|
|
|
|
err = client.RemoveVolumes(c.Context, app.Server, volumesToRemove, internal.Force)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
logrus.Info("volumes removed successfully")
|
|
|
|
return nil
|
|
},
|
|
BashComplete: func(c *cli.Context) {
|
|
appNames, err := config.GetAppNames()
|
|
if err != nil {
|
|
logrus.Warn(err)
|
|
}
|
|
if c.NArg() > 0 {
|
|
return
|
|
}
|
|
for _, a := range appNames {
|
|
fmt.Println(a)
|
|
}
|
|
},
|
|
}
|
|
|
|
var appVolumeCommand = &cli.Command{
|
|
Name: "volume",
|
|
Aliases: []string{"vl"},
|
|
Usage: "Manage app volumes",
|
|
ArgsUsage: "<command>",
|
|
Subcommands: []*cli.Command{
|
|
appVolumeListCommand,
|
|
appVolumeRemoveCommand,
|
|
},
|
|
}
|