View Javadoc

1   //
2   //Author       : t.wood
3   //Copyright    : (c) Resilient Networks plc 2012 - All Rights Reserved
4   //
5   package com.lexicalscope.jewel.cli.validation;
6   
7   import com.lexicalscope.jewel.cli.HelpRequestedException;
8   import com.lexicalscope.jewel.cli.specification.OptionsSpecification;
9   import com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification;
10  
11  import org.hamcrest.Description;
12  import org.hamcrest.TypeSafeMatcher;
13  
14  public class RejectHelpOption extends TypeSafeMatcher<ParsedOptionSpecification>
15  {
16     private final OptionsSpecification<?> specification;
17  
18     public RejectHelpOption(final OptionsSpecification<?> specification)
19     {
20        this.specification = specification;
21     }
22  
23     @Override
24     public void describeTo(final Description description)
25     {
26        description.appendText("non help option");
27     }
28  
29     @Override
30     protected boolean matchesSafely(final ParsedOptionSpecification item)
31     {
32        if(item.isHelpOption())
33        {
34           throw new HelpRequestedException(specification);
35        }
36        return true;
37     }
38  }