simplify path parsing by making at string instead of an array + add tests

pull/7501/head
Adrien Delorme 7 years ago
parent a4b8570991
commit cb2d89af6f

@ -56,7 +56,7 @@ type Config struct {
Color, Debug, Force, Timestamp bool
ParallelBuilds int64
OnError string
Args []string
Path string
}
func (c *BuildCommand) ParseArgs(args []string) (Config, int) {
@ -83,11 +83,12 @@ func (c *BuildCommand) ParseArgs(args []string) (Config, int) {
cfg.ParallelBuilds = math.MaxInt64
}
cfg.Args = flags.Args()
if len(cfg.Args) != 1 {
args = flags.Args()
if len(args) != 1 {
flags.Usage()
return cfg, 1
}
cfg.Path = args[0]
return cfg, 0
}
@ -100,7 +101,7 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, args []string) int {
// Parse the template
var tpl *template.Template
var err error
tpl, err = template.ParseFile(cfg.Args[0])
tpl, err = template.ParseFile(cfg.Path)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to parse template: %s", err))
return 1

@ -231,7 +231,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
{fields{defaultMeta},
args{[]string{"file.json"}},
Config{
Args: []string{"file.json"},
Path: "file.json",
ParallelBuilds: math.MaxInt64,
Color: true,
},
@ -240,7 +240,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
{fields{defaultMeta},
args{[]string{"-parallel=true", "file.json"}},
Config{
Args: []string{"file.json"},
Path: "file.json",
ParallelBuilds: math.MaxInt64,
Color: true,
},
@ -249,7 +249,7 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
{fields{defaultMeta},
args{[]string{"-parallel=false", "file.json"}},
Config{
Args: []string{"file.json"},
Path: "file.json",
ParallelBuilds: 1,
Color: true,
},
@ -258,7 +258,16 @@ func TestBuildCommand_ParseArgs(t *testing.T) {
{fields{defaultMeta},
args{[]string{"-parallel-builds=5", "file.json"}},
Config{
Args: []string{"file.json"},
Path: "file.json",
ParallelBuilds: 5,
Color: true,
},
0,
},
{fields{defaultMeta},
args{[]string{"-parallel=false", "-parallel-builds=5", "otherfile.json"}},
Config{
Path: "otherfile.json",
ParallelBuilds: 5,
Color: true,
},

Loading…
Cancel
Save