Skip to content

Commit 427ea50

Browse files
committed
declare other_args only if catch_all is used anywhere
1 parent f78c6e9 commit 427ea50

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lib/bashly/script/introspection/commands.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ module Bashly
22
module Script
33
module Introspection
44
module Commands
5+
def catch_all_used_anywhere?
6+
deep_commands(include_self: true).any? { |x| x.catch_all.enabled? }
7+
end
8+
59
# Returns a full list of the Command names and aliases combined
610
def command_aliases
711
commands.map(&:aliases).flatten

lib/bashly/views/command/inspect_args.gtx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
> echo args: none
1212
> fi
1313
>
14+
15+
if catch_all_used_anywhere?
1416
> if ((${#other_args[@]})); then
1517
> echo
1618
> echo other_args:
@@ -20,6 +22,8 @@
2022
> done
2123
> fi
2224
>
25+
end
26+
2327
if Settings.enabled? :deps_array
2428
> if ((${#deps[@]})); then
2529
> readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort)
@@ -31,6 +35,7 @@ if Settings.enabled? :deps_array
3135
> fi
3236
>
3337
end
38+
3439
if Settings.enabled? :env_var_names_array
3540
> if ((${#env_var_names[@]})); then
3641
> readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort)

lib/bashly/views/command/run.gtx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
> run() {
44
> declare -g -A args=()
5-
unless Settings.enabled? :inspect_args
6-
> # shellcheck disable=SC2034
5+
6+
if catch_all_used_anywhere?
7+
> declare -g -a other_args=()
78
end
8-
> declare -g -a other_args=()
99

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

0 commit comments

Comments
 (0)