@@ -11,8 +11,13 @@ import (
1111 "github.com/spf13/cobra"
1212)
1313
14+ type uninstallOptions struct {
15+ credentialOptions
16+ force bool
17+ }
18+
1419func uninstallCmd (dockerCli command.Cli ) * cobra.Command {
15- var opts credentialOptions
20+ var opts uninstallOptions
1621
1722 cmd := & cobra.Command {
1823 Use : "uninstall INSTALLATION_NAME [--target-context TARGET_CONTEXT] [OPTIONS]" ,
@@ -24,11 +29,12 @@ func uninstallCmd(dockerCli command.Cli) *cobra.Command {
2429 },
2530 }
2631 opts .addFlags (cmd .Flags ())
32+ cmd .Flags ().BoolVar (& opts .force , "force" , false , "Force removal of installation" )
2733
2834 return cmd
2935}
3036
31- func runUninstall (dockerCli command.Cli , installationName string , opts credentialOptions ) error {
37+ func runUninstall (dockerCli command.Cli , installationName string , opts uninstallOptions ) ( mainErr error ) {
3238 defer muteDockerCli (dockerCli )()
3339 opts .SetDefaultTargetContext (dockerCli )
3440
@@ -41,6 +47,18 @@ func runUninstall(dockerCli command.Cli, installationName string, opts credentia
4147 if err != nil {
4248 return err
4349 }
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+ }
4462 bind , err := requiredClaimBindMount (installation .Claim , opts .targetContext , dockerCli )
4563 if err != nil {
4664 return err
@@ -63,7 +81,7 @@ func runUninstall(dockerCli command.Cli, installationName string, opts credentia
6381 if err2 := installationStore .Store (installation ); err2 != nil {
6482 return fmt .Errorf ("%s while %s" , err2 , errBuf )
6583 }
66- return fmt .Errorf ("Uninstall failed: %s" , errBuf )
84+ return fmt .Errorf ("Uninstall failed: %s\n %s" , err , errBuf )
6785 }
6886 if err := installationStore .Delete (installationName ); err != nil {
6987 return fmt .Errorf ("Failed to delete installation %q from the installation store: %s" , installationName , err )
0 commit comments