Skip to content

Commit 4486788

Browse files
committed
- Add support for unique in repeatable args
1 parent 220150d commit 4486788

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

examples/repeatable-arg/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ args:
3434
# needs to be converted to an array with `eval "data=(${args[file]})"`
3535
repeatable: true
3636

37+
# Setting unique to true will ignore non-unique repeating values
38+
unique: true
39+
3740
examples:
3841
- upcase README.md LICENSE
3942
- upcase *.md
@@ -125,5 +128,23 @@ args:
125128

126129
````
127130

131+
### `$ ./upcase file1 file2 file1`
132+
133+
````shell
134+
135+
files:
136+
path: file1:
137+
content: content of file1
138+
upcase: CONTENT OF FILE1
139+
path: file2:
140+
content: content of file2
141+
upcase: CONTENT OF FILE2
142+
143+
args:
144+
- ${args[file]} = "file1" "file2"
145+
146+
147+
````
148+
128149

129150

examples/repeatable-arg/src/bashly.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ args:
1313
# needs to be converted to an array with `eval "data=(${args[file]})"`
1414
repeatable: true
1515

16+
# Setting unique to true will ignore non-unique repeating values
17+
unique: true
18+
1619
examples:
1720
- upcase README.md LICENSE
1821
- upcase *.md

examples/repeatable-arg/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ bashly generate
99
./upcase -h
1010
./upcase file1
1111
./upcase file*
12+
./upcase file1 file2 file1

lib/bashly/script/argument.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Argument < Base
44
class << self
55
def option_keys
66
@option_keys ||= %i[
7-
allowed default help name repeatable required validate
7+
allowed default help name repeatable required unique validate
88
]
99
end
1010
end

lib/bashly/views/command/parse_requirements_case_repeatable.gtx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ args.each do |arg|
77
if arg.repeatable
88
> args['{{ arg.name }}']="\"$1\""
99
> shift
10-
> else
11-
> args['{{ arg.name }}']="${args[{{ arg.name }}]} \"$1\""
12-
> shift
10+
if arg.unique
11+
> elif [[ ! "${args['{{ arg.name }}']}" =~ \"$1\" ]]; then
12+
> args['{{ arg.name }}']="${args[{{ arg.name }}]} \"$1\""
13+
> shift
14+
> else
15+
> shift
16+
else
17+
> else
18+
> args['{{ arg.name }}']="${args[{{ arg.name }}]} \"$1\""
19+
> shift
20+
end
1321

1422
else
1523
> args['{{ arg.name }}']=$1

spec/approvals/examples/repeatable-arg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ files:
4747

4848
args:
4949
- ${args[file]} = "file1" "file2"
50+
+ ./upcase file1 file2 file1
51+
52+
files:
53+
path: file1:
54+
content: content of file1
55+
upcase: CONTENT OF FILE1
56+
path: file2:
57+
content: content of file2
58+
upcase: CONTENT OF FILE2
59+
60+
args:
61+
- ${args[file]} = "file1" "file2"

0 commit comments

Comments
 (0)