Skip to content

Commit ac7b053

Browse files
committed
add repeatable arg validations regression test
1 parent ed93445 commit ac7b053

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
+ bundle exec bashly generate
2+
creating user files in src
3+
created src/initialize.sh
4+
created src/root_command.sh
5+
created ./cli
6+
run ./cli --help to test your bash script
7+
+ ./cli
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: none
11+
+ ./cli 1
12+
# this file is located in 'src/root_command.sh'
13+
# you can edit it freely and regenerate (it will not be overwritten)
14+
args:
15+
- ${args[number]} = "1"
16+
+ ./cli 1 2
17+
# this file is located in 'src/root_command.sh'
18+
# you can edit it freely and regenerate (it will not be overwritten)
19+
args:
20+
- ${args[number]} = "1" "2"
21+
+ ./cli 1.1
22+
validation error in NUMBER:
23+
must be an integer
24+
+ ./cli 1.1 2
25+
validation error in NUMBER:
26+
must be an integer
27+
+ ./cli 1 2.2
28+
validation error in NUMBER:
29+
must be an integer
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cli
2+
src/*.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This fixture tests that validations on repeatable args validate all arguments
2+
**regardless of order**.
3+
Reference issue: https://github.com/DannyBen/bashly/issues/311
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: cli
2+
help: all arguments must be integers
3+
4+
args:
5+
- name: number
6+
repeatable: true
7+
validate: integer
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
validate_integer() {
2+
[[ "$1" =~ ^[0-9]+$ ]] || echo "must be an integer"
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f ./cli
4+
rm -f ./src/initialize.sh
5+
rm -f ./src/root_command.sh
6+
7+
set -x
8+
9+
bundle exec bashly generate
10+
11+
./cli
12+
./cli 1
13+
./cli 1 2
14+
./cli 1.1
15+
./cli 1.1 2
16+
./cli 1 2.2

0 commit comments

Comments
 (0)