Skip to content

Commit 711fd98

Browse files
committed
revert eval removal
1 parent 2c175f9 commit 711fd98

File tree

7 files changed

+198
-10
lines changed

7 files changed

+198
-10
lines changed

lib/bashly/views/argument/validations.gtx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ if validate
33

44
if repeatable
55
> if [[ -v args['{{ name }}'] ]]; then
6-
> read -r -a values <<<"${args['{{ name }}']}"
6+
> values=''
7+
> eval "values=(${args['{{ name }}']})"
78
> for value in "${values[@]}"; do
89
> if [[ -n $(validate_{{ validate }} "$value") ]]; then
910
> printf "{{ strings[:validation_error] }}\n" "{{ name.upcase }}" "$(validate_{{ validate }} "$value")" >&2

lib/bashly/views/command/normalize_input_function.gtx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
= view_marker
22

33
> normalize_input() {
4-
> local arg passthru
54
if Settings.compact_short_flags
6-
> local flags
5+
> local arg passthru flags
6+
else
7+
> local arg passthru
78
end
89
> passthru=false
910
>

lib/bashly/views/command/whitelist_filter.gtx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ if whitelisted_args.any? or whitelisted_flags.any?
33

44
whitelisted_args.each do |arg|
55
if arg.repeatable
6-
> read -r -a input_array <<<"${args['{{ arg.name }}']}"
6+
> input_array=''
7+
> eval "input_array=(${args[{{ arg.name }}]})"
78
> for i in "${input_array[@]}"; do
89
> if [[ ! $i =~ ^({{ arg.allowed.join '|' }})$ ]]; then
910
> printf "%s\n" "{{ strings[:disallowed_argument] % { name: arg.name, allowed: arg.allowed.join(', ') } }}" >&2
@@ -22,7 +23,8 @@ if whitelisted_args.any? or whitelisted_flags.any?
2223

2324
whitelisted_flags.each do |flag|
2425
if flag.repeatable
25-
> read -r -a input_array <<<"${args['{{ flag.name }}']}"
26+
> input_array=''
27+
> eval "input_array=(${args[{{ flag.name }}]})"
2628
> for i in "${input_array[@]}"; do
2729
> if [[ ! $i =~ ^({{ flag.allowed.join '|' }})$ ]]; then
2830
> printf "%s\n" "{{ strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } }}" >&2

lib/bashly/views/flag/validations.gtx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ if validate
33

44
if repeatable
55
> if [[ -v args['{{ long }}'] ]]; then
6-
> read -r -a values <<<"${args['{{ long }}']}"
6+
> values=''
7+
> eval "values=(${args['{{ long }}']})"
78
> for value in "${values[@]}"; do
89
> if [[ -n $(validate_{{ validate }} "$value") ]]; then
910
> printf "{{ strings[:validation_error] }}\n" "{{ usage_string }}" "$(validate_{{ validate }} "$value")" >&2

spec/fixtures/workspaces/lib-custom-source/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#!/usr/bin/env bash
2+
# This script was generated by bashly 0.9.5 (https://bashly.dannyb.co)
3+
# Modifying it manually is not recommended
4+
5+
# :wrapper.bash3_bouncer
6+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
7+
printf "bash version 4 or higher is required\n" >&2
8+
exit 1
9+
fi
10+
11+
# :command.master_script
12+
# :command.root_command
13+
root_command() {
14+
# src/root_command.sh
15+
# Call the lib function to ensure it was included
16+
sample_function
17+
18+
}
19+
20+
# :command.version_command
21+
version_command() {
22+
echo "$version"
23+
}
24+
25+
# :command.usage
26+
cli_usage() {
27+
if [[ -n $long_usage ]]; then
28+
printf "cli - Sample application\n"
29+
echo
30+
31+
else
32+
printf "cli - Sample application\n"
33+
echo
34+
35+
fi
36+
37+
printf "%s\n" "Usage:"
38+
printf " cli\n"
39+
printf " cli --help | -h\n"
40+
printf " cli --version | -v\n"
41+
echo
42+
43+
# :command.long_usage
44+
if [[ -n $long_usage ]]; then
45+
printf "%s\n" "Options:"
46+
47+
# :command.usage_fixed_flags
48+
printf " %s\n" "--help, -h"
49+
printf " Show this help\n"
50+
echo
51+
printf " %s\n" "--version, -v"
52+
printf " Show version number\n"
53+
echo
54+
55+
fi
56+
}
57+
58+
# :command.normalize_input
59+
normalize_input() {
60+
local arg flags
61+
62+
while [[ $# -gt 0 ]]; do
63+
arg="$1"
64+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
65+
input+=("${BASH_REMATCH[1]}")
66+
input+=("${BASH_REMATCH[2]}")
67+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
68+
input+=("${BASH_REMATCH[1]}")
69+
input+=("${BASH_REMATCH[2]}")
70+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
71+
flags="${BASH_REMATCH[1]}"
72+
for ((i = 0; i < ${#flags}; i++)); do
73+
input+=("-${flags:i:1}")
74+
done
75+
else
76+
input+=("$arg")
77+
fi
78+
79+
shift
80+
done
81+
}
82+
# :command.inspect_args
83+
inspect_args() {
84+
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
85+
if ((${#args[@]})); then
86+
echo args:
87+
for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
88+
else
89+
echo args: none
90+
fi
91+
92+
if ((${#other_args[@]})); then
93+
echo
94+
echo other_args:
95+
echo "- \${other_args[*]} = ${other_args[*]}"
96+
for i in "${!other_args[@]}"; do
97+
echo "- \${other_args[$i]} = ${other_args[$i]}"
98+
done
99+
fi
100+
}
101+
102+
# :command.user_lib
103+
# src/lib/database.sh
104+
# dummy
105+
106+
# :command.command_functions
107+
108+
# :command.parse_requirements
109+
parse_requirements() {
110+
# :command.fixed_flags_filter
111+
while [[ $# -gt 0 ]]; do
112+
case "${1:-}" in
113+
--version | -v)
114+
version_command
115+
exit
116+
;;
117+
118+
--help | -h)
119+
long_usage=yes
120+
cli_usage
121+
exit
122+
;;
123+
124+
*)
125+
break
126+
;;
127+
128+
esac
129+
done
130+
131+
# :command.command_filter
132+
action="root"
133+
134+
# :command.parse_requirements_while
135+
while [[ $# -gt 0 ]]; do
136+
key="$1"
137+
case "$key" in
138+
139+
-?*)
140+
printf "invalid option: %s\n" "$key" >&2
141+
exit 1
142+
;;
143+
144+
*)
145+
# :command.parse_requirements_case
146+
# :command.parse_requirements_case_simple
147+
printf "invalid argument: %s\n" "$key" >&2
148+
exit 1
149+
150+
;;
151+
152+
esac
153+
done
154+
155+
}
156+
157+
# :command.initialize
158+
initialize() {
159+
version=""
160+
long_usage=''
161+
set -e
162+
163+
# src/initialize.sh
164+
165+
}
166+
167+
# :command.run
168+
run() {
169+
declare -A args=()
170+
declare -a other_args=()
171+
declare -a input=()
172+
normalize_input "$@"
173+
parse_requirements "${input[@]}"
174+
175+
case "$action" in
176+
"root")
177+
root_command
178+
;;
179+
180+
esac
181+
}
182+
183+
initialize
184+
run "$@"

spec/fixtures/workspaces/repeatable-escaping/src/root_command.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
inspect_args
22

3+
terms=''
34
if [[ -v args[term] ]]; then
4-
read -r -a terms <<<"${args['term']}"
5+
eval "terms=(${args[term]})"
56
for t in "${terms[@]}"; do
67
echo "[TERM] --> ${t}"
78
done
89
fi
910

1011
if [[ -v args[--search] ]]; then
11-
read -r -a terms <<<"${args['--search']}"
12+
eval "terms=(${args[--search]})"
1213
for t in "${terms[@]}"; do
1314
echo "[--serach] --> ${t}"
1415
done

0 commit comments

Comments
 (0)