-
Notifications
You must be signed in to change notification settings - Fork 26
/
uninstall.go
52 lines (41 loc) · 979 Bytes
/
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
48
49
50
51
52
package cmd
import (
"fmt"
"os"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/dockerx"
"github.com/fatih/color"
"github.com/pkg/errors"
)
type UninstallCmd struct{}
func (cmd UninstallCmd) Run(c *cc.CommonCtx) error {
color.Green(">>> uninstalling topaz...")
var err error
//nolint :gocritic // tbd
if err = (StopCmd{}).Run(c); err != nil {
return err
}
path, err := dockerx.DefaultRoots()
if err != nil {
return err
}
if err = os.RemoveAll(path); err != nil {
return errors.Wrap(err, "failed to delete topaz directory")
}
str, err := dockerx.DockerWithOut(map[string]string{
"NAME": "topaz",
},
"images",
"ghcr.io/aserto-dev/$NAME",
"--filter", "label=org.opencontainers.image.source=https://github.com/aserto-dev/topaz",
"-q",
)
if err != nil {
return err
}
if str != "" {
fmt.Fprintf(c.UI.Output(), "removing %s\n", "aserto-dev/topaz")
err = dockerx.DockerRun("rmi", str)
}
return err
}