Skip to content

Commit

Permalink
Add DUCKER_DEBUG environment variable check to print raw command only…
Browse files Browse the repository at this point in the history
…. Fix ducker exec to use default shell type by default. (#28)
  • Loading branch information
JeiKeiLim authored Jul 2, 2023
1 parent a385508 commit 98e7a26
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.7
0.1.8
37 changes: 32 additions & 5 deletions cmd/ducker/ducker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -83,7 +96,9 @@ func dockerBuild(ctx *cli.Context, dockerTag string) {
buildCmd += " " + buildArgs
}

fmt.Println(buildCmd)
if checkDebugMode(buildCmd, true) {
return
}

runTerminalCmdInShell(buildCmd)
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 98e7a26

Please sign in to comment.