Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arity=1 is not enforced for options #27

Open
alexism opened this issue Sep 13, 2012 · 1 comment
Open

arity=1 is not enforced for options #27

alexism opened this issue Sep 13, 2012 · 1 comment

Comments

@alexism
Copy link

alexism commented Sep 13, 2012

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
@jgburet
Copy link

jgburet commented Dec 4, 2016

Is that the expected behavior? I'm also surprised.
If yes, what about introducing a range or the use of two parameters for #arity?

if values.size < arity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants