Change behaviour of 1-arg and 3-arg commands

This commit is contained in:
Late Night Defender 2024-06-04 09:10:46 +07:00
parent 663d89bded
commit 07e844d0f6

32
main.go
View file

@ -68,7 +68,6 @@ func ExecSystem(command string) {
}
func main() {
flag.Parse()
@ -80,12 +79,21 @@ func main() {
os.Exit(1)
}
// ./compose-runner should run docker compose up -d in current working directory
if len(os.Args) == 1 {
fmt.Println("Usage: compose-runner [-v] [path]")
os.Exit(2)
workDir, err := os.Getwd()
if err != nil {
panic(err)
}
os.Chdir(workDir)
fmt.Println("Running docker compose up -d in", workDir)
ExecSystem("docker compose up -d")
}
if len(os.Args) == 2 {
// ./compose-runner -v should run docker compose up -d in current working directory, verbose output
if *verbosePtr {
workDir, err := os.Getwd()
@ -94,25 +102,25 @@ func main() {
}
os.Chdir(workDir)
fmt.Println("Running docker compose up -d in", workDir)
ExecSystem("docker compose up -d")
} 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")
}
}
// ./compose-runner -v /path should run docker compose up -d in /path, verbose output
if len(os.Args) == 3 {
if os.Args[1] == "-v" {
workDir := os.Args[2]
os.Chdir(workDir)
ExecSystem("docker compose up -d")
} else {
workDir := os.Args[1]
os.Chdir(workDir)
ExecSystem("docker compose up -d")
}
workDir := os.Args[2]
os.Chdir(workDir)
fmt.Println("Running docker compose up -d in", workDir)
ExecSystem("docker compose up -d")
}
}