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

OptionSet.hasOptions() returning true when no options passed in #53

Closed
rmarianski opened this Issue Feb 4, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@rmarianski

rmarianski commented Feb 4, 2014

I may be misunderstanding what OptionSet.hasOptions() is intended to return, but my expectation would be for it to return true if no options were detected during the parse. Here is some code that illustrates my confusion:

OptionParser optionParser = new OptionParser();
OptionSpec<Void> fooOption = optionParser.acceptsAll(Arrays.asList("f", "foo"));

OptionSet options = optionParser.parse(); // no args passed, expecting hasOptions() to return false

System.out.println("Has options: " + options.hasOptions()); //  true, expecting false
System.out.println("Has foo option: " + options.has(fooOption)); // false, as expected
System.out.println("Has '[arguments]' (NonOptionArgumentSpec.NAME) option: "
                + options.has("[arguments]")); // true, this is the option that leads .hasOptions() to return true

I was using version 4.5, but I peeked at master and it looks like it would also exhibit the same behavior.
https://github.com/pholser/jopt-simple/blob/master/src/main/java/joptsimple/OptionParser.java#L376

@pholser

This comment has been minimized.

Show comment
Hide comment
@pholser

pholser Feb 5, 2014

Collaborator

I think this probably broke when we added NonArgumentOptionSpec. It's a bug.

Collaborator

pholser commented Feb 5, 2014

I think this probably broke when we added NonArgumentOptionSpec. It's a bug.

pholser added a commit that referenced this issue Feb 5, 2014

@rmarianski

This comment has been minimized.

Show comment
Hide comment
@rmarianski

rmarianski Feb 5, 2014

I've confirmed that the branch with the fix works for me. Thanks for the quick fix!

rmarianski commented Feb 5, 2014

I've confirmed that the branch with the fix works for me. Thanks for the quick fix!

pholser added a commit that referenced this issue Feb 5, 2014

Merge pull request #54 from pholser/option-set-has-options
Resolving #53 -- correcting behavior of OptionSet.hasOptions()...

@pholser pholser closed this Feb 5, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment