Skip to content

Commit 4da5054

Browse files
authored
Merge pull request #191 from DannyBen/fix/repeatable-whitelist
Fix whitelist filter on repeatable flags
2 parents 1054e90 + 3af73d9 commit 4da5054

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

lib/bashly/views/command/whitelist_filter.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ if [[ ! ${args[<%= arg.name %>]} =~ ^(<%= arg.allowed.join '|' %>)$ ]]; then
66
fi
77
% end
88
% whitelisted_flags.each do |flag|
9+
% if flag.repeatable
10+
eval "input_array=(${args[<%= flag.name %>]})"
11+
for i in "${input_array[@]}"; do
12+
if [[ ! $i =~ ^(<%= flag.allowed.join '|' %>)$ ]]; then
13+
printf "%s\n" "<%= strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } %>"
14+
exit 1
15+
fi
16+
done
17+
% else
918
if [[ ! ${args[<%= flag.name %>]} =~ ^(<%= flag.allowed.join '|' %>)$ ]]; then
1019
printf "%s\n" "<%= strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } %>"
1120
exit 1
1221
fi
22+
% end
1323
% end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
+ bundle exec bashly generate
2+
creating user files in src
3+
created src/initialize.sh
4+
created src/root_command.sh
5+
created ./download
6+
run ./download --help to test your bash script
7+
+ ./download
8+
# this file is located in 'src/root_command.sh'
9+
# you can edit it freely and regenerate (it will not be overwritten)
10+
args:
11+
- ${args[--protocol]} = ftp
12+
+ ./download -p ssh
13+
# this file is located in 'src/root_command.sh'
14+
# you can edit it freely and regenerate (it will not be overwritten)
15+
args:
16+
- ${args[--protocol]} = "ssh"
17+
+ ./download -p ssh -p ftp
18+
# this file is located in 'src/root_command.sh'
19+
# you can edit it freely and regenerate (it will not be overwritten)
20+
args:
21+
- ${args[--protocol]} = "ssh" "ftp"
22+
+ ./download -p sftp -p https
23+
--protocol must be one of: ssh, ftp, sftp
24+
+ ./download -p http -p ftp
25+
--protocol must be one of: ssh, ftp, sftp
26+
+ ./download --protocol telnet
27+
--protocol must be one of: ssh, ftp, sftp
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
download
2+
src/*.sh
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This fixture tests that `flag.repeatable` does not break `flag.allowed`
2+
Reference issue: https://github.com/DannyBen/bashly/issues/187
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: download
2+
help: Test that repeatable does not break allowed
3+
version: 0.1.0
4+
5+
flags:
6+
- long: --protocol
7+
short: -p
8+
help: Choose protocol
9+
arg: protocol
10+
allowed: [ssh, ftp, sftp]
11+
default: ftp
12+
repeatable: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
# This fixture tests that the config lib scope bug
4+
# It is executed as part of the Runfile examples test
5+
# Reference issue: https://github.com/DannyBen/bashly/issues/107
6+
7+
rm -f ./download
8+
rm -f ./src/initialize.sh
9+
rm -f ./src/root_command.sh
10+
11+
set -x
12+
13+
bundle exec bashly generate
14+
15+
./download
16+
./download -p ssh
17+
./download -p ssh -p ftp
18+
./download -p sftp -p https
19+
./download -p http -p ftp
20+
./download --protocol telnet

0 commit comments

Comments
 (0)