Skip to content

Commit 994e2e6

Browse files
fix: --shell option not working for all dockerized commands (#9)
1 parent 3f9a502 commit 994e2e6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@ name: Compile and Test
22
on: [push]
33

44
jobs:
5+
ShellTest:
6+
strategy:
7+
fail-fast: true
8+
matrix:
9+
command:
10+
- go
11+
- aws
12+
- python
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Dockerized
16+
uses: actions/checkout@v2
17+
- name: Compile
18+
run: bin/dockerized --compile
19+
- name: "Test: dockerized --shell ${{matrix.command}}"
20+
env:
21+
COMMAND: "${{matrix.command}}"
22+
run: |
23+
bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | tee ~/shell.log
24+
grep $(hostname) ~/shell.log
525
CompileAndTest:
626
runs-on: ${{ matrix.os }}
727
strategy:
@@ -40,6 +60,7 @@ jobs:
4060
../bin/dockerized go version | grep "1.17.8"
4161
shell: bash
4262

63+
4364
# region windows
4465
- if: runner.os == 'windows'
4566
name: "dockerized --compile (cmd)"

lib/dockerized.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func main() {
122122
fmt.Printf("Opening shell in container for %s...\n", commandName)
123123

124124
if len(commandArgs) > 0 {
125-
fmt.Printf("Ignoring arguments: %s\n", commandArgs[0])
125+
fmt.Printf("Passing arguments to shell: %s\n", commandArgs)
126126
}
127127
}
128128

@@ -145,12 +145,13 @@ func main() {
145145
}
146146
welcomeMessage = strings.ReplaceAll(welcomeMessage, "\\", "\\\\")
147147

148+
preferredShells := "bash zsh sh"
148149
var cmdPrintWelcome = fmt.Sprintf("echo '%s'", color.YellowString(welcomeMessage))
149-
var cmdLaunchShell = "$(which bash || which zsh || which sh || command -v bash || command -v zsh || command -v | head -n 1)"
150+
var cmdLaunchShell = fmt.Sprintf("$(command -v %[1]s | head -n1 || which %[1]s | head -n1)", preferredShells)
150151

151152
runOptions.Environment = append(runOptions.Environment, "PS1="+ps1)
152153
runOptions.Entrypoint = []string{"/bin/sh"}
153-
runOptions.Command = []string{"-c", fmt.Sprintf("%s; %s", cmdPrintWelcome, cmdLaunchShell)}
154+
runOptions.Command = []string{"-c", fmt.Sprintf("%s; %s \"%s\"", cmdPrintWelcome, cmdLaunchShell, strings.Join(commandArgs, "\" \""))}
154155
}
155156

156157
if !contains(project.ServiceNames(), commandName) {

0 commit comments

Comments
 (0)