Skip to content

Commit

Permalink
commands: rename plugin to execute
Browse files Browse the repository at this point in the history
The plugin and plugins command had a name that was close, and while
plugin is not supposed to be directly called by Packer users, this could
happen by accident while trying to execute packer plugins subcommands,
and when it does, the error messages are far from explicit, so unless
they understand what Packer is doing here, they'll likely be lost.

To reduce the risk of confusion, we rename the command to run packer
embedded components as execute.
  • Loading branch information
lbajolet-hashicorp committed Mar 5, 2024
1 parent 525b0a7 commit 34b1baf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions command/plugin.go → command/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
windowsshellprovisioner "github.com/hashicorp/packer/provisioner/windows-shell"
)

type PluginCommand struct {
type ExecuteCommand struct {
Meta
}

Expand Down Expand Up @@ -75,13 +75,13 @@ var Datasources = map[string]packersdk.Datasource{

var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner|datasource)-(.+)")

func (c *PluginCommand) Run(args []string) int {
func (c *ExecuteCommand) Run(args []string) int {
// This is an internal call (users should not call this directly) so we're
// not going to do much input validation. If there's a problem we'll often
// just crash. Error handling should be added to facilitate debugging.
log.Printf("args: %#v", args)
if len(args) != 1 {
c.Ui.Error("Wrong number of args")
c.Ui.Error("Wrong number of args - this command is not meant tobe manually invoked.")
return 1
}

Expand Down Expand Up @@ -136,9 +136,9 @@ func (c *PluginCommand) Run(args []string) int {
return 0
}

func (*PluginCommand) Help() string {
func (*ExecuteCommand) Help() string {
helpText := `
Usage: packer plugin PLUGIN
Usage: packer execute PLUGIN
Runs an internally-compiled version of a plugin from the packer binary.
Expand All @@ -148,6 +148,6 @@ Usage: packer plugin PLUGIN
return strings.TrimSpace(helpText)
}

func (c *PluginCommand) Synopsis() string {
func (c *ExecuteCommand) Synopsis() string {
return "internal plugin command"
}
12 changes: 6 additions & 6 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func init() {
}, nil
},

"execute": func() (cli.Command, error) {
return &command.ExecuteCommand{
Meta: *CommandMeta,
}, nil
},

"fix": func() (cli.Command, error) {
return &command.FixCommand{
Meta: *CommandMeta,
Expand Down Expand Up @@ -59,12 +65,6 @@ func init() {
}, nil
},

"plugin": func() (cli.Command, error) {
return &command.PluginCommand{
Meta: *CommandMeta,
}, nil
},

"plugins": func() (cli.Command, error) {
return &command.PluginsCommand{
Meta: *CommandMeta,
Expand Down
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (c *config) discoverInternalComponents() error {
for builder := range command.Builders {
builder := builder
if !c.Plugins.Builders.Has(builder) {
bin := fmt.Sprintf("%s%splugin%spacker-builder-%s",
bin := fmt.Sprintf("%s%sexecute%spacker-builder-%s",
packerPath, PACKERSPACE, PACKERSPACE, builder)
c.Plugins.Builders.Set(builder, func() (packersdk.Builder, error) {
return c.Plugins.Client(bin).Builder()
Expand All @@ -164,7 +164,7 @@ func (c *config) discoverInternalComponents() error {
for provisioner := range command.Provisioners {
provisioner := provisioner
if !c.Plugins.Provisioners.Has(provisioner) {
bin := fmt.Sprintf("%s%splugin%spacker-provisioner-%s",
bin := fmt.Sprintf("%s%sexecute%spacker-provisioner-%s",
packerPath, PACKERSPACE, PACKERSPACE, provisioner)
c.Plugins.Provisioners.Set(provisioner, func() (packersdk.Provisioner, error) {
return c.Plugins.Client(bin).Provisioner()
Expand All @@ -175,7 +175,7 @@ func (c *config) discoverInternalComponents() error {
for postProcessor := range command.PostProcessors {
postProcessor := postProcessor
if !c.Plugins.PostProcessors.Has(postProcessor) {
bin := fmt.Sprintf("%s%splugin%spacker-post-processor-%s",
bin := fmt.Sprintf("%s%sexecute%spacker-post-processor-%s",
packerPath, PACKERSPACE, PACKERSPACE, postProcessor)
c.Plugins.PostProcessors.Set(postProcessor, func() (packersdk.PostProcessor, error) {
return c.Plugins.Client(bin).PostProcessor()
Expand All @@ -186,7 +186,7 @@ func (c *config) discoverInternalComponents() error {
for dataSource := range command.Datasources {
dataSource := dataSource
if !c.Plugins.DataSources.Has(dataSource) {
bin := fmt.Sprintf("%s%splugin%spacker-datasource-%s",
bin := fmt.Sprintf("%s%sexecute%spacker-datasource-%s",
packerPath, PACKERSPACE, PACKERSPACE, dataSource)
c.Plugins.DataSources.Set(dataSource, func() (packersdk.Datasource, error) {
return c.Plugins.Client(bin).Datasource()
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func wrappedMain() int {
Args: args,
Autocomplete: true,
Commands: Commands,
HelpFunc: excludeHelpFunc(Commands, []string{"plugin"}),
HelpFunc: excludeHelpFunc(Commands, []string{"execute"}),
HelpWriter: os.Stdout,
Name: "packer",
Version: version.Version,
Expand Down

0 comments on commit 34b1baf

Please sign in to comment.