Skip to content

Commit

Permalink
Merge pull request #570 from DannyBen/fix/variables-scope
Browse files Browse the repository at this point in the history
Fix array variables scope
  • Loading branch information
DannyBen authored Nov 3, 2024
2 parents bb9424b + ed7f240 commit a42e547
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
21 changes: 19 additions & 2 deletions examples/variables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ name: cli
help: Sample application demonstrating the use of variables
version: 0.1.0

# The `build_number` variable will be available globally
# The `build_number` and `environments` variables will be available globally
variables:
- name: build_number
value: 1337
- name: environments
value: [dev, stage, production]

commands:
- name: download
Expand Down Expand Up @@ -70,6 +72,10 @@ echo "download_sources:"
for value in "${download_sources[@]}"; do
echo "- $value"
done
echo "environments:"
for value in "${environments[@]}"; do
echo "- $value"
done
````

## `src/compress_command.sh`
Expand All @@ -80,7 +86,10 @@ echo "zip_options:"
for key in "${!zip_options[@]}"; do
echo " $key: ${zip_options[$key]}"
done

echo "environments:"
for value in "${environments[@]}"; do
echo "- $value"
done
````


Expand All @@ -94,6 +103,10 @@ output_folder: output
download_sources:
- youtube
- instagram
environments:
- dev
- stage
- production


````
Expand All @@ -105,6 +118,10 @@ build_number: 1337
zip_options:
compression_level: fast
pattern: *.json
environments:
- dev
- stage
- production


````
Expand Down
4 changes: 3 additions & 1 deletion examples/variables/src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: cli
help: Sample application demonstrating the use of variables
version: 0.1.0

# The `build_number` variable will be available globally
# The `build_number` and `environments` variables will be available globally
variables:
- name: build_number
value: 1337
- name: environments
value: [dev, stage, production]

commands:
- name: download
Expand Down
4 changes: 4 additions & 0 deletions examples/variables/src/compress_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ echo "zip_options:"
for key in "${!zip_options[@]}"; do
echo " $key: ${zip_options[$key]}"
done
echo "environments:"
for value in "${environments[@]}"; do
echo "- $value"
done
4 changes: 4 additions & 0 deletions examples/variables/src/download_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ echo "output_folder: $output_folder"
echo "download_sources:"
for value in "${download_sources[@]}"; do
echo "- $value"
done
echo "environments:"
for value in "${environments[@]}"; do
echo "- $value"
done
12 changes: 6 additions & 6 deletions lib/bashly/views/command/run.gtx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
= view_marker

> run() {
> declare -A args=()
> declare -A deps=()
> declare -a other_args=()
> declare -a env_var_names=()
> declare -a input=()
> declare -g -A args=()
> declare -g -A deps=()
> declare -g -a other_args=()
> declare -g -a env_var_names=()
> declare -g -a input=()
if has_unique_args_or_flags?
> declare -A unique_lookup=()
> declare -g -A unique_lookup=()
end
> normalize_input "$@"
> parse_requirements "${input[@]}"
Expand Down
12 changes: 6 additions & 6 deletions lib/bashly/views/variable/definition.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
case value
when Array
if value.empty?
> declare -a {{ name }}=()
> declare -g -a {{ name }}=()
else
> declare -a {{ name }}=(
> declare -g -a {{ name }}=(
value.each do |v|
> "{{ v }}"
end
> )
end
when Hash
if value.empty?
> declare -A {{ name }}=()
> declare -g -A {{ name }}=()
else
> declare -A {{ name }}=(
> declare -g -A {{ name }}=(
value.each do |k, v|
> ["{{ k }}"]="{{ v }}"
end
> )
end
when String, NilClass
> {{ name }}="{{ value }}"
> declare -g {{ name }}="{{ value }}"
else
> {{ name }}={{ value }}
> declare -g {{ name }}={{ value }}
end
8 changes: 8 additions & 0 deletions spec/approvals/examples/variables
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ output_folder: output
download_sources:
- youtube
- instagram
environments:
- dev
- stage
- production
+ ./cli compress
build_number: 1337
zip_options:
compression_level: fast
pattern: *.json
environments:
- dev
- stage
- production

0 comments on commit a42e547

Please sign in to comment.