diff --git a/examples/variables/README.md b/examples/variables/README.md index 73f6ec17..041cc81d 100644 --- a/examples/variables/README.md +++ b/examples/variables/README.md @@ -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 @@ -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` @@ -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 ```` @@ -94,6 +103,10 @@ output_folder: output download_sources: - youtube - instagram +environments: +- dev +- stage +- production ```` @@ -105,6 +118,10 @@ build_number: 1337 zip_options: compression_level: fast pattern: *.json +environments: +- dev +- stage +- production ```` diff --git a/examples/variables/src/bashly.yml b/examples/variables/src/bashly.yml index 5cb332a2..d9975a5d 100644 --- a/examples/variables/src/bashly.yml +++ b/examples/variables/src/bashly.yml @@ -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 diff --git a/examples/variables/src/compress_command.sh b/examples/variables/src/compress_command.sh index 14cc9240..21712fef 100644 --- a/examples/variables/src/compress_command.sh +++ b/examples/variables/src/compress_command.sh @@ -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 \ No newline at end of file diff --git a/examples/variables/src/download_command.sh b/examples/variables/src/download_command.sh index c2aa5cc3..d4050ece 100644 --- a/examples/variables/src/download_command.sh +++ b/examples/variables/src/download_command.sh @@ -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 \ No newline at end of file diff --git a/lib/bashly/views/command/run.gtx b/lib/bashly/views/command/run.gtx index 8dda6762..6afedb5f 100644 --- a/lib/bashly/views/command/run.gtx +++ b/lib/bashly/views/command/run.gtx @@ -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[@]}" diff --git a/lib/bashly/views/variable/definition.gtx b/lib/bashly/views/variable/definition.gtx index d950bf26..cf58e919 100644 --- a/lib/bashly/views/variable/definition.gtx +++ b/lib/bashly/views/variable/definition.gtx @@ -3,9 +3,9 @@ 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 @@ -13,16 +13,16 @@ when Array 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 diff --git a/spec/approvals/examples/variables b/spec/approvals/examples/variables index 080791a5..227af4af 100644 --- a/spec/approvals/examples/variables +++ b/spec/approvals/examples/variables @@ -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