Change behaviour of 1-arg and 3-arg commands
This commit is contained in:
parent
663d89bded
commit
07e844d0f6
1 changed files with 20 additions and 12 deletions
26
main.go
26
main.go
|
@ -68,7 +68,6 @@ func ExecSystem(command string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -80,12 +79,21 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ./compose-runner should run docker compose up -d in current working directory
|
||||||
if len(os.Args) == 1 {
|
if len(os.Args) == 1 {
|
||||||
fmt.Println("Usage: compose-runner [-v] [path]")
|
workDir, err := os.Getwd()
|
||||||
os.Exit(2)
|
|
||||||
|
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 {
|
if len(os.Args) == 2 {
|
||||||
|
|
||||||
|
// ./compose-runner -v should run docker compose up -d in current working directory, verbose output
|
||||||
if *verbosePtr {
|
if *verbosePtr {
|
||||||
workDir, err := os.Getwd()
|
workDir, err := os.Getwd()
|
||||||
|
|
||||||
|
@ -94,25 +102,25 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Chdir(workDir)
|
os.Chdir(workDir)
|
||||||
|
fmt.Println("Running docker compose up -d in", workDir)
|
||||||
ExecSystem("docker compose up -d")
|
ExecSystem("docker compose up -d")
|
||||||
} else {
|
} else {
|
||||||
|
// ./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)
|
||||||
ExecSystem("docker compose up -d")
|
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 len(os.Args) == 3 {
|
||||||
if os.Args[1] == "-v" {
|
|
||||||
workDir := os.Args[2]
|
workDir := os.Args[2]
|
||||||
os.Chdir(workDir)
|
os.Chdir(workDir)
|
||||||
|
fmt.Println("Running docker compose up -d in", workDir)
|
||||||
ExecSystem("docker compose up -d")
|
ExecSystem("docker compose up -d")
|
||||||
} else {
|
|
||||||
workDir := os.Args[1]
|
|
||||||
os.Chdir(workDir)
|
|
||||||
ExecSystem("docker compose up -d")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue