Skip to content

Commit

Permalink
Fixing bug where the script should have run from its own directory
Browse files Browse the repository at this point in the history
  • Loading branch information
matang28 committed Nov 26, 2019
1 parent 5542ce9 commit bce6c33
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
12 changes: 11 additions & 1 deletion internal/business/template_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
15 changes: 12 additions & 3 deletions internal/data/generic_script_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {

app := cli.App{
Name: "packman",
Version: "0.3",
Version: "0.4",
Commands: commands,
}

Expand Down

0 comments on commit bce6c33

Please sign in to comment.