Help option is designated but not present on CL while another option is required #19

Closed
elkodus opened this Issue Sep 27, 2012 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

elkodus commented Sep 27, 2012

I suppose the RequiredOptionsTest example should pass additional test case, but it fails:

    @Test( expected = OptionException.class )
    public void missingHelpOptionMeansRequiredOptionsMustBePresent() {
        OptionParser parser = new OptionParser() {
            {
                accepts( "userid" ).withRequiredArg().required();
                accepts( "password" ).withRequiredArg().required();
                accepts( "help" ).forHelp();
            }
        };

        parser.parse( "" );
    }

Simple fix at OptionParser works fine for me:

    private void ensureRequiredOptions( OptionSet options ) {
    //...
        boolean helpOptionPresent = false;
        for ( AbstractOptionSpec<?> each : recognizedOptions.toJavaUtilMap().values() ) {
            //fix here, added condition: && options.has( each )
            if ( each.isForHelp() && options.has( each ) ) {
                helpOptionPresent = true;
                break;
            }
        }
    //...
    }

Thanks for your library - using it is a pleasure-simple.

Collaborator

pholser commented Sep 27, 2012

Thanks for detecting the issue. Would you be willing to issue a pull request to fix?

@pholser pholser added a commit that referenced this issue Sep 27, 2012

@pholser pholser Merge pull request #20 from elkodus/master
Fix for #19, Help option is designated but not present on CL while another option is required
824139a

elkodus closed this Sep 27, 2012

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