From b478e5594f2ebb95e77be209730c64f998f55681 Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim Date: Sun, 26 May 2024 19:44:57 +0300 Subject: [PATCH 1/4] fix: transform build.bin path to absolute path --- runner/config.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runner/config.go b/runner/config.go index 78a4eaa5..800e802a 100644 --- a/runner/config.go +++ b/runner/config.go @@ -384,8 +384,13 @@ 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 { + for key, value := range args { if value.Value != nil && *value.Value != unsetDefault { + // To avoid path resolving problems on Windows. + if key == "build.bin" { + abs, _ := filepath.Abs(*value.Value) + value.Value = &abs + } v := reflect.ValueOf(c) setValue2Struct(v, value.fieldPath, *value.Value) } From 7fc9edd24eb1fdbaa8980bd351099597f88016f2 Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim Date: Sun, 26 May 2024 19:51:58 +0300 Subject: [PATCH 2/4] docs: improve description of ParseConfigFlag --- runner/flag.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) From 69aa3867fcb994c529167ee078c4107d79c2eb3b Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim Date: Sun, 26 May 2024 20:22:35 +0300 Subject: [PATCH 3/4] refactor: handle error return of Abs --- main.go | 8 +++++++- runner/config.go | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) 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 800e802a..19757a13 100644 --- a/runner/config.go +++ b/runner/config.go @@ -383,16 +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) { +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, _ := filepath.Abs(*value.Value) + 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 } From 350a829596110d1dcd81d2e1bf8e7ac1cc675120 Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim Date: Sun, 26 May 2024 23:08:47 +0300 Subject: [PATCH 4/4] test: WithArgs --- runner/config_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 {