(buildCtx context.Context, args []string)
| 74 | } |
| 75 | |
| 76 | func (c *PluginsRemoveCommand) RunContext(buildCtx context.Context, args []string) int { |
| 77 | if len(args) < 1 || len(args) > 2 { |
| 78 | return cli.RunResultHelp |
| 79 | } |
| 80 | |
| 81 | pluginDir, err := packer.PluginFolder() |
| 82 | if err != nil { |
| 83 | return writeDiags(c.Ui, nil, hcl.Diagnostics{ |
| 84 | &hcl.Diagnostic{ |
| 85 | Severity: hcl.DiagError, |
| 86 | Summary: "Failed to get the plugin directory", |
| 87 | Detail: fmt.Sprintf( |
| 88 | "The directory in which plugins are installed could not be fetched from the environment. This is likely a Packer bug. Error: %s", |
| 89 | err), |
| 90 | }, |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | if filepath.IsAbs(args[0]) { |
| 95 | if len(args) != 1 { |
| 96 | c.Ui.Error("Unsupported: no version constraint may be specified with a local plugin path.\n") |
| 97 | return cli.RunResultHelp |
| 98 | } |
| 99 | |
| 100 | if !strings.Contains(args[0], pluginDir) { |
| 101 | return writeDiags(c.Ui, nil, hcl.Diagnostics{ |
| 102 | &hcl.Diagnostic{ |
| 103 | Severity: hcl.DiagError, |
| 104 | Summary: "Invalid plugin location", |
| 105 | Detail: fmt.Sprintf( |
| 106 | "The path %q is not under the plugin directory inferred by Packer (%s) and will not be removed.", |
| 107 | args[0], |
| 108 | pluginDir), |
| 109 | }, |
| 110 | }) |
| 111 | } |
| 112 | |
| 113 | log.Printf("will delete plugin located at %q", args[0]) |
| 114 | err := deletePluginBinary(args[0]) |
| 115 | if err != nil { |
| 116 | return writeDiags(c.Ui, nil, hcl.Diagnostics{ |
| 117 | &hcl.Diagnostic{ |
| 118 | Severity: hcl.DiagError, |
| 119 | Summary: "Failed to delete plugin", |
| 120 | Detail: fmt.Sprintf("The plugin %q failed to be deleted with the following error: %q", args[0], err), |
| 121 | }, |
| 122 | }) |
| 123 | } |
| 124 | |
| 125 | c.Ui.Say(args[0]) |
| 126 | |
| 127 | return 0 |
| 128 | } |
| 129 | |
| 130 | opts := plugingetter.ListInstallationsOptions{ |
| 131 | PluginDirectory: c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory, |
| 132 | BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{ |
| 133 | OS: runtime.GOOS, |
no test coverage detected