common/command: rename BuildFilters to BuildOptions

This commit is contained in:
Mitchell Hashimoto 2013-08-09 15:21:24 -07:00
parent 41b3f9ebd9
commit 1a1b4ba715
5 changed files with 20 additions and 19 deletions

View File

@ -22,13 +22,13 @@ func (Command) Help() string {
func (c Command) Run(env packer.Environment, args []string) int {
var cfgDebug bool
var cfgForce bool
buildFilters := new(cmdcommon.BuildFilters)
buildOptions := new(cmdcommon.BuildOptions)
cmdFlags := flag.NewFlagSet("build", flag.ContinueOnError)
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
cmdFlags.BoolVar(&cfgDebug, "debug", false, "debug mode for builds")
cmdFlags.BoolVar(&cfgForce, "force", false, "force a build if artifacts exist")
cmdcommon.BuildFilterFlags(cmdFlags, buildFilters)
cmdcommon.BuildOptionFlags(cmdFlags, buildOptions)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
@ -39,7 +39,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
return 1
}
if err := buildFilters.Validate(); err != nil {
if err := buildOptions.Validate(); err != nil {
env.Ui().Error(err.Error())
env.Ui().Error("")
env.Ui().Error(c.Help())
@ -63,7 +63,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
}
// Go through each builder and compile the builds that we care about
builds, err := buildFilters.Builds(tpl, components)
builds, err := buildOptions.Builds(tpl, components)
if err != nil {
env.Ui().Error(err.Error())
return 1

View File

@ -17,12 +17,12 @@ func (Command) Help() string {
func (c Command) Run(env packer.Environment, args []string) int {
var cfgSyntaxOnly bool
buildFilters := new(cmdcommon.BuildFilters)
buildOptions := new(cmdcommon.BuildOptions)
cmdFlags := flag.NewFlagSet("validate", flag.ContinueOnError)
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
cmdFlags.BoolVar(&cfgSyntaxOnly, "syntax-only", false, "check syntax only")
cmdcommon.BuildFilterFlags(cmdFlags, buildFilters)
cmdcommon.BuildOptionFlags(cmdFlags, buildOptions)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
@ -33,7 +33,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
return 1
}
if err := buildFilters.Validate(); err != nil {
if err := buildOptions.Validate(); err != nil {
env.Ui().Error(err.Error())
env.Ui().Error("")
env.Ui().Error(c.Help())
@ -64,7 +64,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
}
// Otherwise, get all the builds
builds, err := buildFilters.Builds(tpl, components)
builds, err := buildOptions.Builds(tpl, components)
if err != nil {
env.Ui().Error(err.Error())
return 1

View File

@ -4,9 +4,9 @@ import (
"flag"
)
// BuildFilterFlags sets the proper command line flags needed for
// build filters.
func BuildFilterFlags(fs *flag.FlagSet, f *BuildFilters) {
// BuildOptionFlags sets the proper command line flags needed for
// build options.
func BuildOptionFlags(fs *flag.FlagSet, f *BuildOptions) {
fs.Var((*SliceValue)(&f.Except), "except", "build all builds except these")
fs.Var((*SliceValue)(&f.Only), "only", "only build the given builds by name")
}

View File

@ -7,14 +7,15 @@ import (
"log"
)
// BuildFilters is a set of options to filter the builds out of a template.
type BuildFilters struct {
// BuildOptions is a set of options related to builds that can be set
// from the command line.
type BuildOptions struct {
Except []string
Only []string
}
// Validate validates the filter settings
func (f *BuildFilters) Validate() error {
// Validate validates the options
func (f *BuildOptions) Validate() error {
if len(f.Except) > 0 && len(f.Only) > 0 {
return errors.New("Only one of '-except' or '-only' may be specified.")
}
@ -23,8 +24,8 @@ func (f *BuildFilters) Validate() error {
}
// Builds returns the builds out of the given template that pass the
// configured filters.
func (f *BuildFilters) Builds(t *packer.Template, cf *packer.ComponentFinder) ([]packer.Build, error) {
// configured options.
func (f *BuildOptions) Builds(t *packer.Template, cf *packer.ComponentFinder) ([]packer.Build, error) {
buildNames := t.BuildNames()
builds := make([]packer.Build, 0, len(buildNames))
for _, buildName := range buildNames {

View File

@ -4,8 +4,8 @@ import (
"testing"
)
func TestBuildFiltersValidate(t *testing.T) {
bf := new(BuildFilters)
func TestBuildOptionsValidate(t *testing.T) {
bf := new(BuildOptions)
err := bf.Validate()
if err != nil {