Skip to content

Commit

Permalink
Add stderr output
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielJuliao committed Feb 21, 2024
1 parent 5497dcd commit eb905be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
1.0.0
29 changes: 25 additions & 4 deletions cmd/os/exec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import (
"bufio"
"fmt"
"log"
"os"
"os/exec"
)

func Cmd(executableName string, arguments []string) {
cmd := exec.Command(executableName, arguments...)
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}

stderr, err := cmd.StderrPipe()
if err != nil {
log.Fatal(err)
}
Expand All @@ -19,16 +24,32 @@ func Cmd(executableName string, arguments []string) {
log.Fatal(err)
}

go func() {
reader := bufio.NewReader(stderr)
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
_, err = fmt.Fprint(os.Stderr, line)
if err != nil {
return
}
}
}()

reader := bufio.NewReader(stdout)
line, err := reader.ReadString('\n')
for err == nil {
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
fmt.Print(line)
line, err = reader.ReadString('\n')
}

// Wait for the command to finish
err = cmd.Wait()
if err != nil {
fmt.Println("Error waiting for command to finish:", err)
fmt.Println("\nGODO: Error waiting for command to finish:", err)
}
}
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ var appConfigFileExample string
func main() {
info.NewAppInfo(appVersion, appUsageMsg, appBanner, appConfigFileExample)
info.PrintBanner()

env.InitEnv()
env.FindConfigFilePath()

preConfigActions(filterGodoArgs(os.Args[1:]))
}
Expand All @@ -55,6 +53,7 @@ func filterGodoArgs(args []string) []string {
}

func preConfigActions(argv []string) {
env.FindConfigFilePath()
var action = ""

if len(argv) > 0 {
Expand Down

0 comments on commit eb905be

Please # to comment.