Skip to content

Commit

Permalink
When debug is on, output the commands used to run frameworks (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Aug 9, 2023
1 parent f25d3bd commit 875c7be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions amod/amod.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/asmaloney/gactar/actr/modules"
"github.com/asmaloney/gactar/actr/param"

"github.com/asmaloney/gactar/util/executil"
"github.com/asmaloney/gactar/util/issues"
"github.com/asmaloney/gactar/util/keyvalue"
)
Expand All @@ -39,6 +40,8 @@ func (e ErrParseChunk) Error() string {
// SetDebug turns debugging on and off. This will output the tokens as they are generated.
func SetDebug(debug bool) {
debugging = debug

executil.SetDebug(debug)
}

// OutputEBNF outputs the extended Backus–Naur form (EBNF) of the amod grammar to stdout.
Expand Down
23 changes: 23 additions & 0 deletions util/executil/executil.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"os/exec"
)

var (
debugging bool = false
)

type ErrExecuteCommand struct {
Output string
}
Expand All @@ -16,12 +20,31 @@ func (e ErrExecuteCommand) Error() string {

func ExecCommand(name string, arg ...string) (output string, err error) {
cmd := exec.Command(name, arg...)

if debugging {
fmt.Printf("Executing: %s\n", cmd.String())
}

outputBytes, err := cmd.CombinedOutput()
output = string(outputBytes)

if debugging {
if err != nil {
fmt.Printf("Exec FAIL: %s\n%s\n", cmd.String(), output)
} else {
fmt.Printf("Exec SUCCESS: %s\n", cmd.String())
}
}

if err != nil {
err = &ErrExecuteCommand{Output: output}
return
}

return
}

// SetDebug turns debugging on and off. This will output the command before executing it.
func SetDebug(debug bool) {
debugging = debug
}

0 comments on commit 875c7be

Please sign in to comment.