Skip to content

Commit

Permalink
Merge pull request #588 from DannyBen/change/globals-location
Browse files Browse the repository at this point in the history
Move global var declarations from `run()` to `initialize()`
  • Loading branch information
DannyBen authored Dec 27, 2024
2 parents fd54157 + 9167c49 commit 48f6cdd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
29 changes: 29 additions & 0 deletions lib/bashly/views/command/globals.gtx
Original file line number Diff line number Diff line change
@@ -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
>
2 changes: 2 additions & 0 deletions lib/bashly/views/command/initialize.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions lib/bashly/views/command/run.gtx
Original file line number Diff line number Diff line change
@@ -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[@]}"

Expand Down

0 comments on commit 48f6cdd

Please sign in to comment.