Skip to content

Commit

Permalink
Merge pull request #455 from DannyBen/fix/repeatable-arg-validation
Browse files Browse the repository at this point in the history
Disallow multiple repeatable args, and a repeatable arg that is not the last one
  • Loading branch information
DannyBen authored Dec 7, 2023
2 parents 12b8cdd + f4ac880 commit 220150d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/bashly/config_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ def assert_command(key, value)
refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
end

if value['args']
repeatable_args = value['args'].count { |a| a['repeatable'] }
assert repeatable_args < 2, "#{key}.args cannot have more than one repeatable args"

if repeatable_args == 1
assert value['args'].last['repeatable'],
"#{key}.args cannot contain a repeatable arg unless it is the last one"
end
end

if value['expose']
assert value['commands'], "#{key}.expose makes no sense without nub`commands`"
end
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/validations/arg_repeatable_more_than_one
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.args cannot have more than one repeatable args>
1 change: 1 addition & 0 deletions spec/approvals/validations/arg_repeatable_not_last
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.args cannot contain a repeatable arg unless it is the last one>
23 changes: 23 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@
- name: ok
- help: there is no name

:arg_repeatable_more_than_one:
name: invalid
help: can only have one repeatable arg
args:
- name: source
required: true
repeatable: true
help: URL to download from
- name: target
repeatable: true
help: Target filename

:arg_repeatable_not_last:
name: invalid
help: can the last arg can be repeatable
args:
- name: source
required: true
repeatable: true
help: URL to download from
- name: target
help: Target filename

:command_catch_all_type:
name: invalid
help: catch_all must be boolean, string, or hash
Expand Down

0 comments on commit 220150d

Please sign in to comment.