forked from docker/buildx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.go
58 lines (49 loc) · 1.35 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
48
49
50
51
52
53
54
55
56
57
58
package commands
import (
"os"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
type uninstallOptions struct {
}
func runUninstall(dockerCli command.Cli, in uninstallOptions) error {
dir := config.Dir()
cfg, err := config.Load(dir)
if err != nil {
return errors.Wrap(err, "could not load docker config to uninstall 'docker builder' alias")
}
// config.Load does not return an error if config file does not exist
// so let's detect that case, to avoid writing an empty config to disk.
if _, err := os.Stat(cfg.Filename); err != nil {
if !os.IsNotExist(err) {
// should never happen, already handled in config.Load
return errors.Wrap(err, "unexpected error loading docker config")
}
// no-op
return nil
}
delete(cfg.Aliases, "builder")
if len(cfg.Aliases) == 0 {
cfg.Aliases = nil
}
if err := cfg.Save(); err != nil {
return errors.Wrap(err, "could not write docker config")
}
return nil
}
func uninstallCmd(dockerCli command.Cli) *cobra.Command {
var options uninstallOptions
cmd := &cobra.Command{
Use: "uninstall",
Short: "Uninstall the 'docker builder' alias",
Args: cli.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return runUninstall(dockerCli, options)
},
Hidden: true,
}
return cmd
}