From 9167c49895d3c9bdd0932ace3a6a7e90011ff2f2 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 27 Dec 2024 07:01:30 +0000 Subject: [PATCH] - Move global var declarations from `run()` to `initialize()` --- lib/bashly/views/command/globals.gtx | 29 +++++++++++++++++++++++++ lib/bashly/views/command/initialize.gtx | 2 ++ lib/bashly/views/command/run.gtx | 27 ----------------------- 3 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 lib/bashly/views/command/globals.gtx diff --git a/lib/bashly/views/command/globals.gtx b/lib/bashly/views/command/globals.gtx new file mode 100644 index 00000000..1b98bbbd --- /dev/null +++ b/lib/bashly/views/command/globals.gtx @@ -0,0 +1,29 @@ += view_marker + +> declare -g -A args=() + +if catch_all_used_anywhere? + > declare -g -a other_args=() +end + +if Settings.enabled? :deps_array + > declare -g -A deps=() +end + +if Settings.enabled? :env_var_names_array + > declare -g -a env_var_names=() +end + +> declare -g -a input=() + +if has_unique_args_or_flags? + > declare -g -A unique_lookup=() +end + +> +Settings.var_aliases.each do |original, refname| + if refname + > declare -gn {{ refname }}={{ original }} + end +end +> diff --git a/lib/bashly/views/command/initialize.gtx b/lib/bashly/views/command/initialize.gtx index 3be382b4..3d1502f2 100644 --- a/lib/bashly/views/command/initialize.gtx +++ b/lib/bashly/views/command/initialize.gtx @@ -11,6 +11,8 @@ if root_command? = render(:environment_variables_default).indent 2 end += render(:globals).indent(2) + if user_file_exist?('initialize') > = load_user_file('initialize').indent 2 diff --git a/lib/bashly/views/command/run.gtx b/lib/bashly/views/command/run.gtx index 32d6fc22..c026597b 100644 --- a/lib/bashly/views/command/run.gtx +++ b/lib/bashly/views/command/run.gtx @@ -1,33 +1,6 @@ = view_marker > run() { -> declare -g -A args=() - -if catch_all_used_anywhere? - > declare -g -a other_args=() -end - -if Settings.enabled? :deps_array - > declare -g -A deps=() -end - -if Settings.enabled? :env_var_names_array - > declare -g -a env_var_names=() -end - -> declare -g -a input=() - -if has_unique_args_or_flags? - > declare -g -A unique_lookup=() -end - -> -Settings.var_aliases.each do |original, refname| - if refname - > declare -gn {{ refname }}={{ original }} - end -end -> > normalize_input "$@" > parse_requirements "${input[@]}"