Skip to content

Commit

Permalink
Merge pull request hashicorp#1629 from mitchellh/f-no-command-plugins
Browse files Browse the repository at this point in the history
Remove command plugins, command interface from core, etc.
  • Loading branch information
mitchellh committed Oct 28, 2014
2 parents 4406c20 + c51cd3e commit 835b8c6
Show file tree
Hide file tree
Showing 62 changed files with 508 additions and 1,137 deletions.
19 changes: 10 additions & 9 deletions checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"path/filepath"

"github.com/hashicorp/go-checkpoint"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/command"
)

func init() {
packer.VersionChecker = packerVersionCheck
checkpointResult = make(chan *checkpoint.CheckResponse, 1)
}

Expand All @@ -33,9 +32,9 @@ func runCheckpoint(c *config) {
return
}

version := packer.Version
if packer.VersionPrerelease != "" {
version += fmt.Sprintf(".%s", packer.VersionPrerelease)
version := Version
if VersionPrerelease != "" {
version += fmt.Sprintf(".%s", VersionPrerelease)
}

signaturePath := filepath.Join(configDir, "checkpoint_signature")
Expand All @@ -58,21 +57,23 @@ func runCheckpoint(c *config) {
checkpointResult <- resp
}

// packerVersionCheck implements packer.VersionCheckFunc and is used
// commandVersionCheck implements command.VersionCheckFunc and is used
// as the version checker.
func packerVersionCheck(current string) (packer.VersionCheckInfo, error) {
func commandVersionCheck() (command.VersionCheckInfo, error) {
// Wait for the result to come through
info := <-checkpointResult
if info == nil {
var zero packer.VersionCheckInfo
var zero command.VersionCheckInfo
return zero, nil
}

// Build the alerts that we may have received about our version
alerts := make([]string, len(info.Alerts))
for i, a := range info.Alerts {
alerts[i] = a.Message
}

return packer.VersionCheckInfo{
return command.VersionCheckInfo{
Outdated: info.Outdated,
Latest: info.CurrentVersion,
Alerts: alerts,
Expand Down
40 changes: 33 additions & 7 deletions command/build/command.go → command/build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package build
package command

import (
"bytes"
Expand All @@ -14,16 +14,20 @@ import (
"sync"
)

type Command byte

func (Command) Help() string {
return strings.TrimSpace(helpText)
type BuildCommand struct {
Meta
}

func (c Command) Run(env packer.Environment, args []string) int {
func (c BuildCommand) Run(args []string) int {
var cfgColor, cfgDebug, cfgForce, cfgParallel bool
buildOptions := new(cmdcommon.BuildOptions)

env, err := c.Meta.Environment()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing environment: %s", err))
return 1
}

cmdFlags := flag.NewFlagSet("build", flag.ContinueOnError)
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
cmdFlags.BoolVar(&cfgColor, "color", true, "enable or disable color")
Expand Down Expand Up @@ -278,6 +282,28 @@ func (c Command) Run(env packer.Environment, args []string) int {
return 0
}

func (Command) Synopsis() string {
func (BuildCommand) Help() string {
helpText := `
Usage: packer build [options] TEMPLATE
Will execute multiple builds in parallel as defined in the template.
The various artifacts created by the template will be outputted.
Options:
-debug Debug mode enabled for builds
-force Force a build to continue if artifacts exist, deletes existing artifacts
-machine-readable Machine-readable output
-except=foo,bar,baz Build all builds other than these
-only=foo,bar,baz Only build the given builds by name
-parallel=false Disable parallelization (on by default)
-var 'key=value' Variable for templates, can be used multiple times.
-var-file=path JSON file containing user variables.
`

return strings.TrimSpace(helpText)
}

func (BuildCommand) Synopsis() string {
return "build image(s) from template"
}
54 changes: 0 additions & 54 deletions command/build/command_test.go

This file was deleted.

19 changes: 0 additions & 19 deletions command/build/help.go

This file was deleted.

49 changes: 39 additions & 10 deletions command/fix/command.go → command/fix.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package fix
package command

import (
"bytes"
"encoding/json"
"flag"
"fmt"
"github.com/mitchellh/packer/packer"
"log"
"os"
"strings"
)

type Command byte
"github.com/mitchellh/packer/fix"
)

func (Command) Help() string {
return strings.TrimSpace(helpString)
type FixCommand struct {
Meta
}

func (c Command) Run(env packer.Environment, args []string) int {
func (c *FixCommand) Run(args []string) int {
env, err := c.Meta.Environment()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing environment: %s", err))
return 1
}

cmdFlags := flag.NewFlagSet("fix", flag.ContinueOnError)
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
Expand Down Expand Up @@ -50,9 +55,9 @@ func (c Command) Run(env packer.Environment, args []string) int {
tplF.Close()

input := templateData
for _, name := range FixerOrder {
for _, name := range fix.FixerOrder {
var err error
fixer, ok := Fixers[name]
fixer, ok := fix.Fixers[name]
if !ok {
panic("fixer not found: " + name)
}
Expand Down Expand Up @@ -85,6 +90,30 @@ func (c Command) Run(env packer.Environment, args []string) int {
return 0
}

func (c Command) Synopsis() string {
func (*FixCommand) Help() string {
helpText := `
Usage: packer fix [options] TEMPLATE
Reads the JSON template and attempts to fix known backwards
incompatibilities. The fixed template will be outputted to standard out.
If the template cannot be fixed due to an error, the command will exit
with a non-zero exit status. Error messages will appear on standard error.
Fixes that are run:
iso-md5 Replaces "iso_md5" in builders with newer "iso_checksum"
createtime Replaces ".CreateTime" in builder configs with "{{timestamp}}"
virtualbox-gaattach Updates VirtualBox builders using "guest_additions_attach"
to use "guest_additions_mode"
pp-vagrant-override Replaces old-style provider overrides for the Vagrant
post-processor to new-style as of Packer 0.5.0.
virtualbox-rename Updates "virtualbox" builders to "virtualbox-iso"
`

return strings.TrimSpace(helpText)
}

func (c *FixCommand) Synopsis() string {
return "fixes templates from old versions of packer"
}
14 changes: 0 additions & 14 deletions command/fix/command_test.go

This file was deleted.

22 changes: 0 additions & 22 deletions command/fix/help.go

This file was deleted.

38 changes: 29 additions & 9 deletions command/inspect/command.go → command/inspect.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package inspect
package command

import (
"flag"
Expand All @@ -9,17 +9,17 @@ import (
"strings"
)

type Command struct{}

func (Command) Help() string {
return strings.TrimSpace(helpText)
type InspectCommand struct{
Meta
}

func (c Command) Synopsis() string {
return "see components of a template"
}
func (c *InspectCommand) Run(args []string) int {
env, err := c.Meta.Environment()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing environment: %s", err))
return 1
}

func (c Command) Run(env packer.Environment, args []string) int {
flags := flag.NewFlagSet("inspect", flag.ContinueOnError)
flags.Usage = func() { env.Ui().Say(c.Help()) }
if err := flags.Parse(args); err != nil {
Expand Down Expand Up @@ -148,3 +148,23 @@ func (c Command) Run(env packer.Environment, args []string) int {

return 0
}

func (*InspectCommand) Help() string {
helpText := `
Usage: packer inspect TEMPLATE
Inspects a template, parsing and outputting the components a template
defines. This does not validate the contents of a template (other than
basic syntax by necessity).
Options:
-machine-readable Machine-readable output
`

return strings.TrimSpace(helpText)
}

func (c *InspectCommand) Synopsis() string {
return "see components of a template"
}
14 changes: 0 additions & 14 deletions command/inspect/command_test.go

This file was deleted.

13 changes: 0 additions & 13 deletions command/inspect/help.go

This file was deleted.

Loading

0 comments on commit 835b8c6

Please sign in to comment.