From 98e7a26433e9b71ddd9008c5d3c9d7c97020f6b8 Mon Sep 17 00:00:00 2001 From: Jongkuk Lim Date: Mon, 3 Jul 2023 08:01:46 +0900 Subject: [PATCH] Add DUCKER_DEBUG environment variable check to print raw command only. Fix ducker exec to use default shell type by default. (#28) --- VERSION | 2 +- cmd/ducker/ducker.go | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index 1180819..699c6c6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.7 +0.1.8 diff --git a/cmd/ducker/ducker.go b/cmd/ducker/ducker.go index e3708e3..e95d40f 100644 --- a/cmd/ducker/ducker.go +++ b/cmd/ducker/ducker.go @@ -20,6 +20,19 @@ var ( // Cross compile options // env GOOS=darwin GOARCH=arm64 go build ./cmd/ducker + +func checkDebugMode(msg string, always_print bool) bool { + if os.Getenv("DUCKER_DEBUG") != "" { + fmt.Println(msg) + + return true + } else if always_print { + fmt.Println(msg) + } + + return false +} + func duckerConfig(ctx *cli.Context) { // TODO(jeikeilim): add more flexible setting options genGlobal := ctx.Bool("global") @@ -83,7 +96,9 @@ func dockerBuild(ctx *cli.Context, dockerTag string) { buildCmd += " " + buildArgs } - fmt.Println(buildCmd) + if checkDebugMode(buildCmd, true) { + return + } runTerminalCmdInShell(buildCmd) } @@ -145,7 +160,10 @@ func dockerRun(ctx *cli.Context, dockerTag string) { runCmd += " " + dockerTag runCmd += " " + shellCmd - fmt.Println(runCmd) + + if checkDebugMode(runCmd, true) { + return + } runTerminalCmdInShell(runCmd) @@ -189,9 +207,18 @@ func dockerExec(ctx *cli.Context) { if !strings.Contains(result, lastContainerID) { fmt.Println("Last container " + lastContainerID + " is not running.") fmt.Println("Start container ...") + + if checkDebugMode(execCmd, true) { + return + } + getTerminalCmdOut("docker", "start " + lastContainerID) } + if checkDebugMode(execCmd, true) { + return + } + runTerminalCmdInShell(execCmd) } @@ -464,9 +491,9 @@ func main() { &cli.StringFlag{ Name: "shell", Aliases: []string{"s"}, - Usage: "Shell type to run (bash, zsh)", - Value: "zsh", - DefaultText: "zsh", + Usage: "Shell type to run (default, bash, zsh)", + Value: "default", + DefaultText: "default", }, }, Action: func(cCtx *cli.Context) error {