diff --git a/lib/bashly/config_validator.rb b/lib/bashly/config_validator.rb index ea2e3f6d..fce6c759 100644 --- a/lib/bashly/config_validator.rb +++ b/lib/bashly/config_validator.rb @@ -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 diff --git a/spec/approvals/validations/arg_repeatable_more_than_one b/spec/approvals/validations/arg_repeatable_more_than_one new file mode 100644 index 00000000..4921fd63 --- /dev/null +++ b/spec/approvals/validations/arg_repeatable_more_than_one @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/validations/arg_repeatable_not_last b/spec/approvals/validations/arg_repeatable_not_last new file mode 100644 index 00000000..c76646be --- /dev/null +++ b/spec/approvals/validations/arg_repeatable_not_last @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/fixtures/script/validations.yml b/spec/fixtures/script/validations.yml index 1cc306df..bfedf331 100644 --- a/spec/fixtures/script/validations.yml +++ b/spec/fixtures/script/validations.yml @@ -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