Skip to content
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
6 changes: 4 additions & 2 deletions lib/bashly/views/command/inspect_args.gtx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
= view_marker

> inspect_args() {
> local k
>
> if ((${#args[@]})); then
> readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
> echo args:
Expand All @@ -17,8 +19,8 @@ if catch_all_used_anywhere?
> echo
> echo other_args:
> echo "- \${other_args[*]} = ${other_args[*]}"
> for i in "${!other_args[@]}"; do
> echo "- \${other_args[$i]} = ${other_args[$i]}"
> for k in "${!other_args[@]}"; do
> echo "- \${other_args[$k]} = ${other_args[$k]}"
> done
> fi
>
Expand Down
2 changes: 2 additions & 0 deletions lib/bashly/views/command/parse_requirements.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ if root_command?
else
> {{ function_name }}_parse_requirements() {
end
> local key
>

= render(:fixed_flags_filter).indent 2
= render(:environment_variables_filter).indent 2
Expand Down
16 changes: 16 additions & 0 deletions spec/approvals/fixtures/local-var-leak
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
+ bundle exec bashly generate
creating user files in src
skipped src/one_command.sh (exists)
skipped src/two_command.sh (exists)
skipped src/noop_command.sh (exists)
created ./cli
run ./cli --help to test your bash script
+ ./cli 1
Before key=THIS IS MY VALUE
noop called
After key=THIS IS MY VALUE
+ ./cli 2
Before k=THIS IS MY VALUE
args:
- ${args[--user]} = admin
After k=THIS IS MY VALUE
1 change: 1 addition & 0 deletions spec/fixtures/workspaces/local-var-leak/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cli
4 changes: 4 additions & 0 deletions spec/fixtures/workspaces/local-var-leak/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This fixture tests that variables that are supposed to be local, internal to
bashly, are indeed defined as local and do not leak to the global scope.

Reference issue: https://github.com/bashly-framework/bashly/issues/681
19 changes: 19 additions & 0 deletions spec/fixtures/workspaces/local-var-leak/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: cli
help: Testing that bashly-defined variables do not leak to the global scope
version: 0.1.0

commands:
- name: one
alias: "1"
help: Testing 'key' leakage when calling 'run' internally

- name: two
alias: "2"
help: Testing 'k' leak when calling 'inspect_args'
flags:
- long: --user
arg: name
default: admin

- name: noop
help: Does nothing except declare it was called
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "noop called"
4 changes: 4 additions & 0 deletions spec/fixtures/workspaces/local-var-leak/src/one_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
key="THIS IS MY VALUE"
echo "Before key=$key"
run noop
echo "After key=$key"
4 changes: 4 additions & 0 deletions spec/fixtures/workspaces/local-var-leak/src/two_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
k="THIS IS MY VALUE"
echo "Before k=$k"
inspect_args
echo "After k=$k"
8 changes: 8 additions & 0 deletions spec/fixtures/workspaces/local-var-leak/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -x

bundle exec bashly generate

./cli 1
./cli 2