common/command: rename BuildFilters to BuildOptions
This commit is contained in:
parent
41b3f9ebd9
commit
1a1b4ba715
|
@ -22,13 +22,13 @@ func (Command) Help() string {
|
||||||
func (c Command) Run(env packer.Environment, args []string) int {
|
func (c Command) Run(env packer.Environment, args []string) int {
|
||||||
var cfgDebug bool
|
var cfgDebug bool
|
||||||
var cfgForce bool
|
var cfgForce bool
|
||||||
buildFilters := new(cmdcommon.BuildFilters)
|
buildOptions := new(cmdcommon.BuildOptions)
|
||||||
|
|
||||||
cmdFlags := flag.NewFlagSet("build", flag.ContinueOnError)
|
cmdFlags := flag.NewFlagSet("build", flag.ContinueOnError)
|
||||||
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
|
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
|
||||||
cmdFlags.BoolVar(&cfgDebug, "debug", false, "debug mode for builds")
|
cmdFlags.BoolVar(&cfgDebug, "debug", false, "debug mode for builds")
|
||||||
cmdFlags.BoolVar(&cfgForce, "force", false, "force a build if artifacts exist")
|
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 {
|
if err := cmdFlags.Parse(args); err != nil {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := buildFilters.Validate(); err != nil {
|
if err := buildOptions.Validate(); err != nil {
|
||||||
env.Ui().Error(err.Error())
|
env.Ui().Error(err.Error())
|
||||||
env.Ui().Error("")
|
env.Ui().Error("")
|
||||||
env.Ui().Error(c.Help())
|
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
|
// 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 {
|
if err != nil {
|
||||||
env.Ui().Error(err.Error())
|
env.Ui().Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -17,12 +17,12 @@ func (Command) Help() string {
|
||||||
|
|
||||||
func (c Command) Run(env packer.Environment, args []string) int {
|
func (c Command) Run(env packer.Environment, args []string) int {
|
||||||
var cfgSyntaxOnly bool
|
var cfgSyntaxOnly bool
|
||||||
buildFilters := new(cmdcommon.BuildFilters)
|
buildOptions := new(cmdcommon.BuildOptions)
|
||||||
|
|
||||||
cmdFlags := flag.NewFlagSet("validate", flag.ContinueOnError)
|
cmdFlags := flag.NewFlagSet("validate", flag.ContinueOnError)
|
||||||
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
|
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
|
||||||
cmdFlags.BoolVar(&cfgSyntaxOnly, "syntax-only", false, "check syntax only")
|
cmdFlags.BoolVar(&cfgSyntaxOnly, "syntax-only", false, "check syntax only")
|
||||||
cmdcommon.BuildFilterFlags(cmdFlags, buildFilters)
|
cmdcommon.BuildOptionFlags(cmdFlags, buildOptions)
|
||||||
if err := cmdFlags.Parse(args); err != nil {
|
if err := cmdFlags.Parse(args); err != nil {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := buildFilters.Validate(); err != nil {
|
if err := buildOptions.Validate(); err != nil {
|
||||||
env.Ui().Error(err.Error())
|
env.Ui().Error(err.Error())
|
||||||
env.Ui().Error("")
|
env.Ui().Error("")
|
||||||
env.Ui().Error(c.Help())
|
env.Ui().Error(c.Help())
|
||||||
|
@ -64,7 +64,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, get all the builds
|
// Otherwise, get all the builds
|
||||||
builds, err := buildFilters.Builds(tpl, components)
|
builds, err := buildOptions.Builds(tpl, components)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
env.Ui().Error(err.Error())
|
env.Ui().Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BuildFilterFlags sets the proper command line flags needed for
|
// BuildOptionFlags sets the proper command line flags needed for
|
||||||
// build filters.
|
// build options.
|
||||||
func BuildFilterFlags(fs *flag.FlagSet, f *BuildFilters) {
|
func BuildOptionFlags(fs *flag.FlagSet, f *BuildOptions) {
|
||||||
fs.Var((*SliceValue)(&f.Except), "except", "build all builds except these")
|
fs.Var((*SliceValue)(&f.Except), "except", "build all builds except these")
|
||||||
fs.Var((*SliceValue)(&f.Only), "only", "only build the given builds by name")
|
fs.Var((*SliceValue)(&f.Only), "only", "only build the given builds by name")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,15 @@ import (
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BuildFilters is a set of options to filter the builds out of a template.
|
// BuildOptions is a set of options related to builds that can be set
|
||||||
type BuildFilters struct {
|
// from the command line.
|
||||||
|
type BuildOptions struct {
|
||||||
Except []string
|
Except []string
|
||||||
Only []string
|
Only []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the filter settings
|
// Validate validates the options
|
||||||
func (f *BuildFilters) Validate() error {
|
func (f *BuildOptions) Validate() error {
|
||||||
if len(f.Except) > 0 && len(f.Only) > 0 {
|
if len(f.Except) > 0 && len(f.Only) > 0 {
|
||||||
return errors.New("Only one of '-except' or '-only' may be specified.")
|
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
|
// Builds returns the builds out of the given template that pass the
|
||||||
// configured filters.
|
// configured options.
|
||||||
func (f *BuildFilters) Builds(t *packer.Template, cf *packer.ComponentFinder) ([]packer.Build, error) {
|
func (f *BuildOptions) Builds(t *packer.Template, cf *packer.ComponentFinder) ([]packer.Build, error) {
|
||||||
buildNames := t.BuildNames()
|
buildNames := t.BuildNames()
|
||||||
builds := make([]packer.Build, 0, len(buildNames))
|
builds := make([]packer.Build, 0, len(buildNames))
|
||||||
for _, buildName := range buildNames {
|
for _, buildName := range buildNames {
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildFiltersValidate(t *testing.T) {
|
func TestBuildOptionsValidate(t *testing.T) {
|
||||||
bf := new(BuildFilters)
|
bf := new(BuildOptions)
|
||||||
|
|
||||||
err := bf.Validate()
|
err := bf.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue