Skip to content

Commit

Permalink
- Add support for unique in repeatable args
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Dec 7, 2023
1 parent 220150d commit 4486788
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
21 changes: 21 additions & 0 deletions examples/repeatable-arg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ args:
# needs to be converted to an array with `eval "data=(${args[file]})"`
repeatable: true

# Setting unique to true will ignore non-unique repeating values
unique: true

examples:
- upcase README.md LICENSE
- upcase *.md
Expand Down Expand Up @@ -125,5 +128,23 @@ args:

````

### `$ ./upcase file1 file2 file1`

````shell

files:
path: file1:
content: content of file1
upcase: CONTENT OF FILE1
path: file2:
content: content of file2
upcase: CONTENT OF FILE2

args:
- ${args[file]} = "file1" "file2"


````



3 changes: 3 additions & 0 deletions examples/repeatable-arg/src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ args:
# needs to be converted to an array with `eval "data=(${args[file]})"`
repeatable: true

# Setting unique to true will ignore non-unique repeating values
unique: true

examples:
- upcase README.md LICENSE
- upcase *.md
1 change: 1 addition & 0 deletions examples/repeatable-arg/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ bashly generate
./upcase -h
./upcase file1
./upcase file*
./upcase file1 file2 file1
2 changes: 1 addition & 1 deletion lib/bashly/script/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Argument < Base
class << self
def option_keys
@option_keys ||= %i[
allowed default help name repeatable required validate
allowed default help name repeatable required unique validate
]
end
end
Expand Down
14 changes: 11 additions & 3 deletions lib/bashly/views/command/parse_requirements_case_repeatable.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ args.each do |arg|
if arg.repeatable
> args['{{ arg.name }}']="\"$1\""
> shift
> else
> args['{{ arg.name }}']="${args[{{ arg.name }}]} \"$1\""
> shift
if arg.unique
> elif [[ ! "${args['{{ arg.name }}']}" =~ \"$1\" ]]; then
> args['{{ arg.name }}']="${args[{{ arg.name }}]} \"$1\""
> shift
> else
> shift
else
> else
> args['{{ arg.name }}']="${args[{{ arg.name }}]} \"$1\""
> shift
end

else
> args['{{ arg.name }}']=$1
Expand Down
12 changes: 12 additions & 0 deletions spec/approvals/examples/repeatable-arg
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ files:

args:
- ${args[file]} = "file1" "file2"
+ ./upcase file1 file2 file1

files:
path: file1:
content: content of file1
upcase: CONTENT OF FILE1
path: file2:
content: content of file2
upcase: CONTENT OF FILE2

args:
- ${args[file]} = "file1" "file2"

0 comments on commit 4486788

Please sign in to comment.