Skip to content

Commit bce6c33

Browse files
committed
Fixing bug where the script should have run from its own directory
1 parent 5542ce9 commit bce6c33

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎internal/business/template_service.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (this *templateService) Render(templatePath string, packagePath string, fla
4343
}
4444

4545
err = filepath.Walk(packagePath, func(path string, info os.FileInfo, err error) error {
46-
if info.IsDir() {
46+
if shouldSkip(info, path) {
4747
return nil
4848
}
4949

@@ -97,3 +97,13 @@ func toScriptPath(prefix string) (string, error) {
9797
}
9898
return "", fmt.Errorf("in order for packman to work you must have a 'main.*' file within your packman folder")
9999
}
100+
101+
func shouldSkip(info os.FileInfo, path string) bool {
102+
if info.IsDir() {
103+
return true
104+
}
105+
if strings.Contains(path, ".git") {
106+
return true
107+
}
108+
return false
109+
}

‎internal/data/generic_script_engine.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ func (this *genericScriptEngine) Run(scriptPath string, flags map[string]string)
3030

3131
var cmdArgs []string
3232
cmdArgs = append(cmdArgs, args...)
33-
cmdArgs = append(cmdArgs, scriptPath)
34-
cmdArgs = append(cmdArgs, flagsFile)
35-
cmdArgs = append(cmdArgs, replyFile)
33+
cmdArgs = append(cmdArgs, filepath.Base(scriptPath))
34+
cmdArgs = append(cmdArgs, panicOrString(filepath.Abs, flagsFile))
35+
cmdArgs = append(cmdArgs, panicOrString(filepath.Abs, replyFile))
3636

3737
cmd := exec.Command(mainCommand, cmdArgs...)
38+
cmd.Dir = filepath.Dir(scriptPath)
3839

3940
etc.PrintInfo(fmt.Sprintf("Running '%s %v'", mainCommand, cmdArgs))
4041
result, err := cmd.CombinedOutput()
@@ -84,3 +85,11 @@ func splitCommand(command string) (string, []string, error) {
8485
}
8586
return "", nil, fmt.Errorf("cannot parse command %s, the command syntax should be as follows: 'commnad arg1 arg2 arg3 ...'", command)
8687
}
88+
89+
func panicOrString(f func(s string) (string, error), s string) string {
90+
str, err := f(s)
91+
if err != nil {
92+
panic(err)
93+
}
94+
return str
95+
}

‎main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func main() {
1919

2020
app := cli.App{
2121
Name: "packman",
22-
Version: "0.3",
22+
Version: "0.4",
2323
Commands: commands,
2424
}
2525

0 commit comments

Comments
 (0)
⌂ 换网址