Skip to content

Commit

Permalink
- Disallow multiple repeatable args, and a repeatable arg that is not…
Browse files Browse the repository at this point in the history
… the last one
  • Loading branch information
DannyBen committed Dec 7, 2023
1 parent 12b8cdd commit 25431c9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/bashly/config_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ 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 25431c9

Please sign in to comment.