Separate ExecSystem into ExecSystemFull and ExecSystenErr

This commit is contained in:
Late Night Defender 2024-06-04 10:07:58 +07:00
parent 624f26fbf5
commit 5578be58f5

28
main.go
View file

@ -11,9 +11,8 @@ import (
var verbosePtr = flag.Bool("v", false, "boolean")
func ExecSystem(command string) {
func ExecSystemFull(command string) {
if *verbosePtr{
cmd := exec.Command("/usr/bin/bash", "-c", command)
stdout, err := cmd.StdoutPipe()
@ -44,7 +43,8 @@ func ExecSystem(command string) {
for stderrScanner.Scan() {
fmt.Println(stderrScanner.Text())
}
} else {
}
func ExecSystemErr(command string) {
cmd := exec.Command("/usr/bin/bash", "-c", command)
stderr, err := cmd.StderrPipe()
if err != nil {
@ -64,10 +64,10 @@ func ExecSystem(command string) {
for stderrScanner.Scan() {
fmt.Println(stderrScanner.Text())
}
}
}
func main() {
flag.Parse()
@ -87,8 +87,9 @@ func main() {
panic(err)
}
os.Chdir(workDir)
fmt.Println("Running docker compose up -d in", workDir)
ExecSystem("docker compose up -d")
fmt.Println("[1] Running docker compose up -d in", workDir)
ExecSystemErr("docker compose up -d")
ExecSystemFull("docker compose ps")
}
if len(os.Args) == 2 {
@ -102,16 +103,18 @@ func main() {
}
os.Chdir(workDir)
fmt.Println("Running docker compose up -d in", workDir)
ExecSystem("docker compose up -d")
fmt.Println("[2v] Running docker compose up -d in", workDir)
ExecSystemFull("docker compose up -d")
ExecSystemFull("docker compose ps")
} else {
// ./compose-runner /path should run docker compose up -d in /path
workDir := os.Args[1]
os.Chdir(workDir)
fmt.Println("Running docker compose up -d in", workDir)
ExecSystem("docker compose up -d")
fmt.Println("[2] Running docker compose up -d in", workDir)
ExecSystemErr("docker compose up -d")
ExecSystemFull("docker compose ps")
}
}
@ -119,8 +122,9 @@ func main() {
if len(os.Args) == 3 {
workDir := os.Args[2]
os.Chdir(workDir)
fmt.Println("Running docker compose up -d in", workDir)
ExecSystem("docker compose up -d")
fmt.Println("[3] Running docker compose up -d in", workDir)
ExecSystemFull("docker compose up -d")
ExecSystemFull("docker compose ps")
}
}