-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.go
47 lines (42 loc) · 1.11 KB
/
uninstall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package composectl
import (
"fmt"
"github.com/spf13/cobra"
"os"
"path/filepath"
)
var uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "uninstall <app-name> [<app-name>]",
Long: ``,
Args: cobra.MinimumNArgs(1),
}
type (
uninstallOptions struct {
ignoreNonInstalled bool
}
)
func init() {
opts := uninstallOptions{}
uninstallCmd.Flags().BoolVar(&opts.ignoreNonInstalled, "ignore-non-installed", false,
"Do not yield error if app installation is not found")
uninstallCmd.Run = func(cmd *cobra.Command, args []string) {
uninstallApps(cmd, args, &opts)
}
rootCmd.AddCommand(uninstallCmd)
}
func uninstallApps(cmd *cobra.Command, args []string, opts *uninstallOptions) {
apps := getAllAppStatuses(cmd.Context())
for _, app := range args {
if _, ok := apps[app]; ok {
DieNotNil(fmt.Errorf("cannot uninstall running app: %s", app))
}
appComposeDir := filepath.Join(config.ComposeRoot, app)
if !opts.ignoreNonInstalled {
if _, err := os.Stat(appComposeDir); os.IsNotExist(err) {
DieNotNil(fmt.Errorf("app is not installed: %s", app))
}
}
DieNotNil(os.RemoveAll(appComposeDir))
}
}