Add some exit codes and use a constant for -PACKERSPACE-
This commit is contained in:
parent
9fa93712a1
commit
e080e73b04
|
@ -3,7 +3,6 @@ package command
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/packer/builder/amazon/chroot"
|
||||
|
@ -105,7 +104,7 @@ func (c *PluginCommand) Run(args []string) int {
|
|||
log.Printf("args: %#v", args)
|
||||
if len(args) != 1 {
|
||||
c.Ui.Error("Wrong number of args")
|
||||
os.Exit(1)
|
||||
return 1
|
||||
}
|
||||
|
||||
// Plugin should be called like "packer-builder-amazon-ebs" so we'll take it
|
||||
|
@ -124,25 +123,29 @@ func (c *PluginCommand) Run(args []string) int {
|
|||
|
||||
server, err := plugin.Server()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
c.Ui.Error(fmt.Sprintf("Error starting plugin server: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
if pluginType == "builder" {
|
||||
builder, found := Builders[pluginName]
|
||||
if !found {
|
||||
c.Ui.Error(fmt.Sprintf("Could not load builder: %s", pluginName))
|
||||
return 1
|
||||
}
|
||||
server.RegisterBuilder(builder)
|
||||
} else if pluginType == "provisioner" {
|
||||
provisioner, found := Provisioners[pluginName]
|
||||
if !found {
|
||||
c.Ui.Error(fmt.Sprintf("Could not load provisioner: %s", pluginName))
|
||||
return 1
|
||||
}
|
||||
server.RegisterProvisioner(provisioner)
|
||||
} else if pluginType == "post-processor" {
|
||||
postProcessor, found := PostProcessors[pluginName]
|
||||
if !found {
|
||||
c.Ui.Error(fmt.Sprintf("Could not load post-processor: %s", pluginName))
|
||||
return 1
|
||||
}
|
||||
server.RegisterPostProcessor(postProcessor)
|
||||
}
|
||||
|
@ -156,13 +159,14 @@ func (*PluginCommand) Help() string {
|
|||
helpText := `
|
||||
Usage: packer plugin PLUGIN
|
||||
|
||||
Runs an internally-compiled version of a plugin from the packer binary. Note
|
||||
that this is an internal command and you should not call it yourself.
|
||||
Runs an internally-compiled version of a plugin from the packer binary.
|
||||
|
||||
NOTE: this is an internal command and you should not call it yourself.
|
||||
`
|
||||
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (c *PluginCommand) Synopsis() string {
|
||||
return "call an internal plugin"
|
||||
return "internal plugin command"
|
||||
}
|
||||
|
|
21
config.go
21
config.go
|
@ -16,6 +16,10 @@ import (
|
|||
"github.com/mitchellh/packer/packer/plugin"
|
||||
)
|
||||
|
||||
// PACKERSPACE is used to represent the spaces that separate args for a command
|
||||
// without being confused with spaces in the path to the command itself.
|
||||
const PACKERSPACE = "-PACKERSPACE-"
|
||||
|
||||
type config struct {
|
||||
DisableCheckpoint bool `json:"disable_checkpoint"`
|
||||
DisableCheckpointSignature bool `json:"disable_checkpoint_signature"`
|
||||
|
@ -80,7 +84,7 @@ func (c *config) Discover() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Finally, try to use an internal plugin. Note that this will not Override
|
||||
// Finally, try to use an internal plugin. Note that this will not override
|
||||
// any previously-loaded plugins.
|
||||
if err := c.discoverInternal(); err != nil {
|
||||
return err
|
||||
|
@ -216,7 +220,8 @@ func (c *config) discoverInternal() error {
|
|||
_, found := (c.Builders)[builder]
|
||||
if !found {
|
||||
log.Printf("Using internal plugin for %s", builder)
|
||||
(c.Builders)[builder] = fmt.Sprintf("%s-PACKERSPACE-plugin-PACKERSPACE-packer-builder-%s", packerPath, builder)
|
||||
(c.Builders)[builder] = fmt.Sprintf("%s%splugin%spacker-builder-%s",
|
||||
packerPath, PACKERSPACE, PACKERSPACE, builder)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,7 +229,9 @@ func (c *config) discoverInternal() error {
|
|||
_, found := (c.Provisioners)[provisioner]
|
||||
if !found {
|
||||
log.Printf("Using internal plugin for %s", provisioner)
|
||||
(c.Provisioners)[provisioner] = fmt.Sprintf("%s-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-%s", packerPath, provisioner)
|
||||
(c.Provisioners)[provisioner] = fmt.Sprintf(
|
||||
"%s%splugin%spacker-provisioner-%s",
|
||||
packerPath, PACKERSPACE, PACKERSPACE, provisioner)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +239,9 @@ func (c *config) discoverInternal() error {
|
|||
_, found := (c.PostProcessors)[postProcessor]
|
||||
if !found {
|
||||
log.Printf("Using internal plugin for %s", postProcessor)
|
||||
(c.PostProcessors)[postProcessor] = fmt.Sprintf("%s-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-%s", packerPath, postProcessor)
|
||||
(c.PostProcessors)[postProcessor] = fmt.Sprintf(
|
||||
"%s%splugin%spacker-post-processor-%s",
|
||||
packerPath, PACKERSPACE, PACKERSPACE, postProcessor)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,8 +268,8 @@ func (c *config) pluginClient(path string) *plugin.Client {
|
|||
|
||||
// Check for special case using `packer plugin PLUGIN`
|
||||
args := []string{}
|
||||
if strings.Contains(path, "-PACKERSPACE-") {
|
||||
parts := strings.Split(path, "-PACKERSPACE-")
|
||||
if strings.Contains(path, PACKERSPACE) {
|
||||
parts := strings.Split(path, PACKERSPACE)
|
||||
path = parts[0]
|
||||
args = parts[1:]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue