main
main copied to clipboard
arity=1 is not enforced for options
An option with arity 1 does not fail if 2 values are passed. See the example below:
require 'main'
ARGV.replace %w(--foo=bar --foo=baz)
Main {
option('foo', 'f'){
required
arity 1
argument_required
}
def run
p "Did you pass --foo ? #{params['foo'].given? == true}"
p params['foo'].value
p params['foo'].values
end
}
Expected result: failure 2!=1 Output: failure
"Did you pass --foo ? true"
"bar"
["bar", "baz"]
However for an option with arity>1, the check is correctly done
require 'main'
ARGV.replace %w(--foo=bar --foo=baz)
Main {
option('foo', 'f'){
required
arity 3 # arity is now 3!
argument_required
}
def run
p "Did you pass --foo ? #{params['foo'].given? == true}"
p params['foo'].value
p params['foo'].values
end
}
Expected result: fail because 2 values are set instead of 3 Ouput: OK
option(--foo)) 2/3
Is that the expected behavior? I'm also surprised.
If yes, what about introducing a range or the use of two parameters for #arity
?
https://github.com/ahoward/main/blob/9133795315c0c8fbc05da3cbb83cbadbd02ddaf3/lib/main/parameter.rb#L204