2013-08-09 18:10:24 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2013-08-09 18:41:40 -04:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2013-08-09 18:10:24 -04:00
|
|
|
)
|
|
|
|
|
2013-08-09 18:21:24 -04:00
|
|
|
// BuildOptionFlags sets the proper command line flags needed for
|
|
|
|
// build options.
|
|
|
|
func BuildOptionFlags(fs *flag.FlagSet, f *BuildOptions) {
|
2013-08-09 18:10:24 -04:00
|
|
|
fs.Var((*SliceValue)(&f.Except), "except", "build all builds except these")
|
|
|
|
fs.Var((*SliceValue)(&f.Only), "only", "only build the given builds by name")
|
2013-08-09 18:41:40 -04:00
|
|
|
fs.Var((*userVarValue)(&f.UserVars), "var", "specify a user variable")
|
2013-08-09 19:45:29 -04:00
|
|
|
fs.Var((*AppendSliceValue)(&f.UserVarFiles), "var-file", "file with user variables")
|
2013-08-09 18:41:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// userVarValue is a flag.Value that parses out user variables in
|
|
|
|
// the form of 'key=value' and sets it on this map.
|
|
|
|
type userVarValue map[string]string
|
|
|
|
|
|
|
|
func (v *userVarValue) String() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *userVarValue) Set(raw string) error {
|
|
|
|
idx := strings.Index(raw, "=")
|
|
|
|
if idx == -1 {
|
|
|
|
return fmt.Errorf("No '=' value in arg: %s", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *v == nil {
|
|
|
|
*v = make(map[string]string)
|
|
|
|
}
|
|
|
|
|
|
|
|
key, value := raw[0:idx], raw[idx+1:]
|
|
|
|
(*v)[key] = value
|
|
|
|
return nil
|
2013-08-09 18:10:24 -04:00
|
|
|
}
|