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