@@ -11,8 +11,13 @@ import (
11
11
"github.com/spf13/cobra"
12
12
)
13
13
14
+ type uninstallOptions struct {
15
+ credentialOptions
16
+ force bool
17
+ }
18
+
14
19
func uninstallCmd (dockerCli command.Cli ) * cobra.Command {
15
- var opts credentialOptions
20
+ var opts uninstallOptions
16
21
17
22
cmd := & cobra.Command {
18
23
Use : "uninstall INSTALLATION_NAME [--target-context TARGET_CONTEXT] [OPTIONS]" ,
@@ -24,11 +29,12 @@ func uninstallCmd(dockerCli command.Cli) *cobra.Command {
24
29
},
25
30
}
26
31
opts .addFlags (cmd .Flags ())
32
+ cmd .Flags ().BoolVar (& opts .force , "force" , false , "Force removal of installation" )
27
33
28
34
return cmd
29
35
}
30
36
31
- func runUninstall (dockerCli command.Cli , installationName string , opts credentialOptions ) error {
37
+ func runUninstall (dockerCli command.Cli , installationName string , opts uninstallOptions ) ( mainErr error ) {
32
38
defer muteDockerCli (dockerCli )()
33
39
opts .SetDefaultTargetContext (dockerCli )
34
40
@@ -41,6 +47,18 @@ func runUninstall(dockerCli command.Cli, installationName string, opts credentia
41
47
if err != nil {
42
48
return err
43
49
}
50
+ if opts .force {
51
+ defer func () {
52
+ if mainErr == nil {
53
+ return
54
+ }
55
+ if err := installationStore .Delete (installationName ); err != nil {
56
+ fmt .Fprintf (os .Stderr , "failed to force deletion of installation %q: %s\n " , installationName , err )
57
+ return
58
+ }
59
+ fmt .Fprintf (os .Stderr , "deletion forced for installation %q\n " , installationName )
60
+ }()
61
+ }
44
62
bind , err := requiredClaimBindMount (installation .Claim , opts .targetContext , dockerCli )
45
63
if err != nil {
46
64
return err
@@ -63,7 +81,7 @@ func runUninstall(dockerCli command.Cli, installationName string, opts credentia
63
81
if err2 := installationStore .Store (installation ); err2 != nil {
64
82
return fmt .Errorf ("%s while %s" , err2 , errBuf )
65
83
}
66
- return fmt .Errorf ("Uninstall failed: %s" , errBuf )
84
+ return fmt .Errorf ("Uninstall failed: %s\n %s" , err , errBuf )
67
85
}
68
86
if err := installationStore .Delete (installationName ); err != nil {
69
87
return fmt .Errorf ("Failed to delete installation %q from the installation store: %s" , installationName , err )
0 commit comments