diff --git a/command/build/command.go b/command/build/command.go index ef66fc95b..dc1ee9da7 100644 --- a/command/build/command.go +++ b/command/build/command.go @@ -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 diff --git a/command/validate/command.go b/command/validate/command.go index edbce9341..ee0788ca2 100644 --- a/command/validate/command.go +++ b/command/validate/command.go @@ -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 diff --git a/common/command/build_flags.go b/common/command/build_flags.go index b0f49222f..477c83ef8 100644 --- a/common/command/build_flags.go +++ b/common/command/build_flags.go @@ -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") } diff --git a/common/command/template.go b/common/command/template.go index 6c8462378..90280de9f 100644 --- a/common/command/template.go +++ b/common/command/template.go @@ -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 { diff --git a/common/command/template_test.go b/common/command/template_test.go index c934c21f8..18a9805db 100644 --- a/common/command/template_test.go +++ b/common/command/template_test.go @@ -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 {