Skip to content

Commit

Permalink
declare other_args only if catch_all is used anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Dec 20, 2024
1 parent f78c6e9 commit 427ea50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/bashly/script/introspection/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module Bashly
module Script
module Introspection
module Commands
def catch_all_used_anywhere?
deep_commands(include_self: true).any? { |x| x.catch_all.enabled? }
end

# Returns a full list of the Command names and aliases combined
def command_aliases
commands.map(&:aliases).flatten
Expand Down
5 changes: 5 additions & 0 deletions lib/bashly/views/command/inspect_args.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
> echo args: none
> fi
>

if catch_all_used_anywhere?
> if ((${#other_args[@]})); then
> echo
> echo other_args:
Expand All @@ -20,6 +22,8 @@
> done
> fi
>
end

if Settings.enabled? :deps_array
> if ((${#deps[@]})); then
> readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort)
Expand All @@ -31,6 +35,7 @@ if Settings.enabled? :deps_array
> fi
>
end

if Settings.enabled? :env_var_names_array
> if ((${#env_var_names[@]})); then
> readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort)
Expand Down
6 changes: 3 additions & 3 deletions lib/bashly/views/command/run.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

> run() {
> declare -g -A args=()
unless Settings.enabled? :inspect_args
> # shellcheck disable=SC2034

if catch_all_used_anywhere?
> declare -g -a other_args=()
end
> declare -g -a other_args=()

if Settings.enabled? :deps_array
> declare -g -A deps=()
Expand Down

0 comments on commit 427ea50

Please sign in to comment.