Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DUCKER_DEBUG environment variable check to print raw command only… #28

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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