Skip to content

Commit

Permalink
Add default type selection in .ducker.yaml and --run-cmd will implici…
Browse files Browse the repository at this point in the history
…tly make no shell to run. (#20)
  • Loading branch information
JeiKeiLim authored Feb 7, 2023
1 parent f3019dc commit a583269
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.3
0.1.4
35 changes: 24 additions & 11 deletions cmd/ducker/ducker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func dockerRun(ctx *cli.Context, dockerTag string) {
dockerArgs := ctx.String("docker-args")
shellType := ctx.String("shell")
mountPWD := ctx.Bool("mount-pwd")
shellCmd := "/bin/bash"
dockerOpt := "-tid"

runOption := ""
Expand All @@ -87,12 +86,20 @@ func dockerRun(ctx *cli.Context, dockerTag string) {
runOption += localConfig.GetRunArg()
}

if shellType == "zsh" {
shellCmd := "/bin/bash"

if shellType == "default" {
shellType = localConfig.Default_Shell
}
if shellType == "zsh" {
shellCmd = "/usr/bin/zsh"
} else if shellType == "nosh" {
shellCmd = ctx.String("run-cmd")
dockerOpt = "-ti"
} else if shellType == "bash" {
shellCmd = "/bin/bash"
}
if ctx.String("run-cmd") != "" {
shellCmd = ctx.String("run-cmd")
dockerOpt = "-ti"
}

runCmd := "docker run " + dockerOpt + " "
runCmd += runOption
Expand Down Expand Up @@ -133,7 +140,7 @@ func dockerRun(ctx *cli.Context, dockerTag string) {
localConfig.LastExecID = lastContainerID
localConfig.Write(getDefaultLocalConfigPath())

if shellType != "nosh" {
if ctx.String("run-cmd") == "" {
dockerExec(ctx)
}
}
Expand All @@ -144,8 +151,14 @@ func dockerExec(ctx *cli.Context) {
shellType := ctx.String("shell")
shellCmd := "/bin/bash"

if shellType == "zsh" {
if shellType == "default" {
shellType = localConfig.Default_Shell
}

if shellType == "zsh" {
shellCmd = "/usr/bin/zsh"
} else if shellType == "bash" {
shellCmd = "/bin/bash"
}

lastContainerID := localConfig.LastExecID
Expand Down Expand Up @@ -400,9 +413,9 @@ func main() {
&cli.StringFlag{
Name: "shell",
Aliases: []string{"s"},
Usage: "Shell type to run (bash, zsh, nosh)",
Value: "zsh",
DefaultText: "zsh",
Usage: "Shell type to run (default, bash, zsh)",
Value: "default",
DefaultText: "default",
},
&cli.BoolFlag{
Name: "mount-pwd",
Expand All @@ -412,7 +425,7 @@ func main() {
&cli.StringFlag{
Name: "run-cmd",
Aliases: []string{"r"},
Usage: "Running command (only applies when shell=nosh)",
Usage: "Running command (Shell will not be executed)",
Value: "",
DefaultText: "",
},
Expand Down
2 changes: 2 additions & 0 deletions cmd/ducker/local_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type LocalConfig struct {
Run_Arg []string
Build_Arg []string
Mount_PWD bool
Default_Shell string
LastExecID string
}

Expand All @@ -34,6 +35,7 @@ func getDefaultLocalConfig() LocalConfig {
"--build-arg UID=" + getTerminalCmdOut("id", "-u"),
"--build-arg GID=" + getTerminalCmdOut("id", "-g"),
},
Default_Shell: "zsh",
Mount_PWD: true,
}

Expand Down

0 comments on commit a583269

Please sign in to comment.