From bce6c33d0dc94a09ec879cbf452d5076ab4478cb Mon Sep 17 00:00:00 2001 From: matang Date: Tue, 26 Nov 2019 09:23:32 +0200 Subject: [PATCH] Fixing bug where the script should have run from its own directory --- internal/business/template_service.go | 12 +++++++++++- internal/data/generic_script_engine.go | 15 ++++++++++++--- main.go | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/internal/business/template_service.go b/internal/business/template_service.go index 348b61e..ed425c2 100644 --- a/internal/business/template_service.go +++ b/internal/business/template_service.go @@ -43,7 +43,7 @@ func (this *templateService) Render(templatePath string, packagePath string, fla } err = filepath.Walk(packagePath, func(path string, info os.FileInfo, err error) error { - if info.IsDir() { + if shouldSkip(info, path) { return nil } @@ -97,3 +97,13 @@ func toScriptPath(prefix string) (string, error) { } return "", fmt.Errorf("in order for packman to work you must have a 'main.*' file within your packman folder") } + +func shouldSkip(info os.FileInfo, path string) bool { + if info.IsDir() { + return true + } + if strings.Contains(path, ".git") { + return true + } + return false +} diff --git a/internal/data/generic_script_engine.go b/internal/data/generic_script_engine.go index 173c986..486a965 100644 --- a/internal/data/generic_script_engine.go +++ b/internal/data/generic_script_engine.go @@ -30,11 +30,12 @@ func (this *genericScriptEngine) Run(scriptPath string, flags map[string]string) var cmdArgs []string cmdArgs = append(cmdArgs, args...) - cmdArgs = append(cmdArgs, scriptPath) - cmdArgs = append(cmdArgs, flagsFile) - cmdArgs = append(cmdArgs, replyFile) + cmdArgs = append(cmdArgs, filepath.Base(scriptPath)) + cmdArgs = append(cmdArgs, panicOrString(filepath.Abs, flagsFile)) + cmdArgs = append(cmdArgs, panicOrString(filepath.Abs, replyFile)) cmd := exec.Command(mainCommand, cmdArgs...) + cmd.Dir = filepath.Dir(scriptPath) etc.PrintInfo(fmt.Sprintf("Running '%s %v'", mainCommand, cmdArgs)) result, err := cmd.CombinedOutput() @@ -84,3 +85,11 @@ func splitCommand(command string) (string, []string, error) { } return "", nil, fmt.Errorf("cannot parse command %s, the command syntax should be as follows: 'commnad arg1 arg2 arg3 ...'", command) } + +func panicOrString(f func(s string) (string, error), s string) string { + str, err := f(s) + if err != nil { + panic(err) + } + return str +} diff --git a/main.go b/main.go index bbbd492..c2e9ead 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ func main() { app := cli.App{ Name: "packman", - Version: "0.3", + Version: "0.4", Commands: commands, }