diff --git a/main.go b/main.go index ee31295e..60a4b12c 100644 --- a/main.go +++ b/main.go @@ -95,7 +95,13 @@ func main() { log.Fatal(err) return } - cfg.WithArgs(cmdArgs) + + err = cfg.WithArgs(cmdArgs) + if err != nil { + log.Fatal(err) + return + } + r, err := runner.NewEngineWithConfig(cfg, debugMode) if err != nil { log.Fatal(err) diff --git a/runner/config.go b/runner/config.go index 78a4eaa5..19757a13 100644 --- a/runner/config.go +++ b/runner/config.go @@ -383,11 +383,20 @@ func (c *Config) rel(path string) string { } // WithArgs returns a new config with the given arguments added to the configuration. -func (c *Config) WithArgs(args map[string]TomlInfo) { - for _, value := range args { +func (c *Config) WithArgs(args map[string]TomlInfo) error { + for key, value := range args { if value.Value != nil && *value.Value != unsetDefault { + // To avoid path resolving problems on Windows. + if key == "build.bin" { + abs, err := filepath.Abs(*value.Value) + if err != nil { + return err + } + value.Value = &abs + } v := reflect.ValueOf(c) setValue2Struct(v, value.fieldPath, *value.Value) } } + return nil } diff --git a/runner/config_test.go b/runner/config_test.go index 97a1bd2a..5ee39b6d 100644 --- a/runner/config_test.go +++ b/runner/config_test.go @@ -203,6 +203,29 @@ func TestKillDelay(t *testing.T) { } } +func TestWithArgs(t *testing.T) { + testData := []struct { + bin string + }{{ + bin: "bin\\main.exe", + }, {bin: "bin/main.exe"}} + + for _, test := range testData { + config := Config{} + args := map[string]TomlInfo{ + "build.bin": { + Value: &test.bin, + }, + } + err := config.WithArgs(args) + + if err != nil { + t.Fatal("Test shouldn't have failed, found: ", err) + } + } + +} + func contains(sl []string, target string) bool { for _, c := range sl { if c == target { diff --git a/runner/flag.go b/runner/flag.go index af8f478b..0724c7cf 100644 --- a/runner/flag.go +++ b/runner/flag.go @@ -6,7 +6,8 @@ import ( const unsetDefault = "DEFAULT" -// ParseConfigFlag parse toml information for flag +// ParseConfigFlag parse toml information for flag and register +// keys as Vars in `flag` to be filled later when using `.Parse()` func ParseConfigFlag(f *flag.FlagSet) map[string]TomlInfo { c := Config{} m := flatConfig(c)