@@ -18,7 +18,7 @@ create_bare_wrapper_layout() {
1818create_wrapper_layout () {
1919 local layout_root=" $1 "
2020 local command_name=" $2 "
21- local command_script_name=" ${3:- main .sh} "
21+ local command_script_name=" ${3:- $command_name .sh} "
2222
2323 create_bare_wrapper_layout " $layout_root "
2424 mkdir -p " $layout_root /commands/$command_name "
4242 chmod +x " $layout_root /commands/$command_name /$command_script_name "
4343}
4444
45- @test " bash-wrapper dispatches directly to commands/<name>/main .sh" {
45+ @test " bash-wrapper dispatches directly to commands/<name>/<name> .sh" {
4646 local repo_root=" $BATS_TEST_TMPDIR /repo"
4747 local layout=" $repo_root /cli/bash"
4848 local expected_repo_root expected_bash_root expected_bin_dir expected_env_script expected_script_path
5454 expected_bin_dir=" $( cd " $layout /bin" && pwd -P) "
5555 expected_env_script=" $( cd " $repo_root /cli/env" && pwd -P) /banyanenv.sh"
5656 expected_command_dir=" $( cd " $layout /commands/demo" && pwd -P) "
57- expected_script_path=" $( cd " $layout /commands/demo" && pwd -P) /main .sh"
57+ expected_script_path=" $( cd " $layout /commands/demo" && pwd -P) /demo .sh"
5858
59- run " $layout /bin/bash-wrapper" demo --debug-wrapper alpha beta
59+ run " $layout /bin/bash-wrapper" demo.sh --debug-wrapper alpha beta
6060
6161 [ " $status " -eq 0 ]
6262 [[ " $output " == * " script_dir=$expected_command_dir " * ]]
7171 [[ " $output " == * " argv=alpha beta" * ]]
7272}
7373
74- @test " symlink name selects the command" {
74+ @test " symlink name with .sh suffix selects the command" {
7575 local repo_root=" $BATS_TEST_TMPDIR /repo"
7676 local layout=" $repo_root /cli/bash"
7777 local expected_script_path
7878 local expected_command_dir
7979
8080 create_wrapper_layout " $layout " greet
81- ln -s bash-wrapper " $layout /bin/greet"
81+ ln -s bash-wrapper " $layout /bin/greet.sh "
8282 expected_command_dir=" $( cd " $layout /commands/greet" && pwd -P) "
83- expected_script_path=" $( cd " $layout /commands/greet" && pwd -P) /main .sh"
83+ expected_script_path=" $( cd " $layout /commands/greet" && pwd -P) /greet .sh"
8484
85- run " $layout /bin/greet" hello world
85+ run " $layout /bin/greet.sh " hello world
8686
8787 [ " $status " -eq 0 ]
8888 [[ " $output " == * " script_dir=$expected_command_dir " * ]]
9191 [[ " $output " == * " argv=hello world" * ]]
9292}
9393
94- @test " wrapper supports the fallback commands/<name>/<name>.sh layout" {
95- local repo_root=" $BATS_TEST_TMPDIR /repo"
96- local layout=" $repo_root /cli/bash"
97- local expected_script_path
98- local expected_command_dir
99-
100- create_wrapper_layout " $layout " legacy " legacy.sh"
101- expected_command_dir=" $( cd " $layout /commands/legacy" && pwd -P) "
102- expected_script_path=" $( cd " $layout /commands/legacy" && pwd -P) /legacy.sh"
103-
104- run " $layout /bin/bash-wrapper" legacy arg1
105-
106- [ " $status " -eq 0 ]
107- [[ " $output " == * " script_dir=$expected_command_dir " * ]]
108- [[ " $output " == * " command=legacy" * ]]
109- [[ " $output " == * " script=$expected_script_path " * ]]
110- [[ " $output " == * " argv=arg1" * ]]
111- }
112-
11394@test " wrapper prints usage when no command is provided" {
11495 local repo_root=" $BATS_TEST_TMPDIR /repo"
11596 local layout=" $repo_root /cli/bash"
@@ -149,13 +130,20 @@ EOF
149130echo "legacy"
150131EOF
151132 chmod +x " $layout /commands/legacy/legacy.sh"
133+ mkdir -p " $layout /commands/main-only"
134+ cat > " $layout /commands/main-only/main.sh" << 'EOF '
135+ #!/usr/bin/env bash
136+ echo "main-only"
137+ EOF
138+ chmod +x " $layout /commands/main-only/main.sh"
152139
153140 run " $layout /bin/bash-wrapper" --list
154141
155142 [ " $status " -eq 0 ]
156- [[ " $output " == * " alpha" * ]]
157- [[ " $output " == * " legacy" * ]]
143+ [[ " $output " == * " alpha.sh " * ]]
144+ [[ " $output " == * " legacy.sh " * ]]
158145 [[ " $output " != * " empty-dir" * ]]
146+ [[ " $output " != * " main-only" * ]]
159147 [[ " $output " != * " readme-only" * ]]
160148}
161149
@@ -189,12 +177,30 @@ EOF
189177
190178 create_bare_wrapper_layout " $layout "
191179
192- run " $layout /bin/bash-wrapper" missing
180+ run " $layout /bin/bash-wrapper" missing.sh
193181
194182 [ " $status " -eq 1 ]
195183 [[ " $output " == * " Command 'missing' was not found" * ]]
196184}
197185
186+ @test " wrapper rejects main.sh-only command directories" {
187+ local repo_root=" $BATS_TEST_TMPDIR /repo"
188+ local layout=" $repo_root /cli/bash"
189+
190+ create_bare_wrapper_layout " $layout "
191+ mkdir -p " $layout /commands/legacy"
192+ cat > " $layout /commands/legacy/main.sh" << 'EOF '
193+ #!/usr/bin/env bash
194+ echo "legacy"
195+ EOF
196+ chmod +x " $layout /commands/legacy/main.sh"
197+
198+ run " $layout /bin/bash-wrapper" legacy.sh
199+
200+ [ " $status " -eq 1 ]
201+ [[ " $output " == * " Command 'legacy' was not found" * ]]
202+ }
203+
198204@test " wrapper errors when the stdlib is missing" {
199205 local repo_root=" $BATS_TEST_TMPDIR /repo"
200206 local layout=" $repo_root /cli/bash"
@@ -227,14 +233,14 @@ EOF
227233
228234 create_bare_wrapper_layout " $layout "
229235 mkdir -p " $layout /commands/stdlib-demo"
230- cat > " $layout /commands/stdlib-demo/main .sh" << 'EOF '
236+ cat > " $layout /commands/stdlib-demo/stdlib-demo .sh" << 'EOF '
231237#!/usr/bin/env bash
232238set_log_level DEBUG
233239run echo "wrapped output"
234240safe_touch "$BATS_TEST_TMPDIR/stdout.txt"
235241printf 'touched=%s\n' "$BATS_TEST_TMPDIR/stdout.txt"
236242EOF
237- chmod +x " $layout /commands/stdlib-demo/main .sh"
243+ chmod +x " $layout /commands/stdlib-demo/stdlib-demo .sh"
238244
239245 run " $layout /bin/bash-wrapper" stdlib-demo
240246
@@ -250,14 +256,14 @@ EOF
250256
251257 create_bare_wrapper_layout " $layout "
252258 mkdir -p " $layout /commands/flags"
253- cat > " $layout /commands/flags/main .sh" << 'EOF '
259+ cat > " $layout /commands/flags/flags .sh" << 'EOF '
254260#!/usr/bin/env bash
255261printf 'orig=%s\n' "${__SCRIPT_ARGS__[*]}"
256262printf 'argv=%s\n' "$*"
257263printf 'log_debug=%s\n' "${LOG_DEBUG:-}"
258264printf 'log_utc=%s\n' "${LOG_UTC:-}"
259265EOF
260- chmod +x " $layout /commands/flags/main .sh"
266+ chmod +x " $layout /commands/flags/flags .sh"
261267
262268 run " $layout /bin/bash-wrapper" flags --verbose-wrapper --utc-wrapper --color one two
263269
@@ -273,10 +279,10 @@ EOF
273279 local layout=" $repo_root /cli/bash"
274280
275281 create_bare_wrapper_layout " $layout "
276- ln -s bash-wrapper " $layout /bin/orphan"
282+ ln -s bash-wrapper " $layout /bin/orphan.sh "
277283 mkdir -p " $layout /commands/orphan"
278284
279- run " $layout /bin/orphan"
285+ run " $layout /bin/orphan.sh "
280286
281287 [ " $status " -eq 1 ]
282288 [[ " $output " == * " Command 'orphan' was not found" * ]]
0 commit comments