Java Code Examples for org.apache.commons.cli.Options#getOption()

The following examples show how to use org.apache.commons.cli.Options#getOption() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testDeduceFromMameRuntimeWithBooleanOption ()
        throws FileNotFoundException,
               IOException,
               InterruptedException,
               MameExecutionException {
    
    FakeMameRuntime mame = new FakeMameRuntime();
    List<InputStream> inputStreams = new ArrayList<>();
    inputStreams.add(
        new FileInputStream("src/test/resources/showconfig.txt"));
    inputStreams.add(
        new FileInputStream("src/test/resources/showusage.txt"));
    mame.setInputStreamsToReturn(inputStreams);
    CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
    Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();

    assertTrue(mameOpts.hasOption("waitvsync"));

    Option opt = mameOpts.getOption("waitvsync");

    assertFalse(opt.hasArg());

}
 
Example 2
@Test
public void testDeduceFromMameRuntimeWithNegativeBooleanOption ()
        throws FileNotFoundException,
               IOException,
               InterruptedException,
               MameExecutionException {
    
    FakeMameRuntime mame = new FakeMameRuntime();
    List<InputStream> inputStreams = new ArrayList<>();
    inputStreams.add(
        new FileInputStream("src/test/resources/showconfig.txt"));
    inputStreams.add(
        new FileInputStream("src/test/resources/showusage.txt"));
    mame.setInputStreamsToReturn(inputStreams);
    CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
    Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();

    assertTrue(mameOpts.hasOption("nowaitvsync"));

    Option opt = mameOpts.getOption("nowaitvsync");

    assertFalse(opt.hasArg());

}
 
Example 3
@Test
public void testDeduceFromMameRuntimeWithNonBooleanOption ()
        throws FileNotFoundException,
               IOException,
               InterruptedException,
               MameExecutionException {
    
    FakeMameRuntime mame = new FakeMameRuntime();
    List<InputStream> inputStreams = new ArrayList<>();
    inputStreams.add(
        new FileInputStream("src/test/resources/showconfig.txt"));
    inputStreams.add(
        new FileInputStream("src/test/resources/showusage.txt"));
    mame.setInputStreamsToReturn(inputStreams);
    CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
    Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();

    assertTrue(mameOpts.hasOption("rompath"));
    assertFalse(mameOpts.hasOption("norompath"));

    Option opt = mameOpts.getOption("rompath");

    assertTrue(opt.hasArg());

}
 
Example 4
@Test
public void testDeduceFromMameRuntimeWithNonBooleanOptionHavingDefaultValueLikeBoolean ()
        throws FileNotFoundException,
               IOException,
               InterruptedException,
               MameExecutionException {
    
    FakeMameRuntime mame = new FakeMameRuntime();
    List<InputStream> inputStreams = new ArrayList<>();
    inputStreams.add(
        new FileInputStream("src/test/resources/showconfig.txt"));
    inputStreams.add(
        new FileInputStream("src/test/resources/showusage.txt"));
    mame.setInputStreamsToReturn(inputStreams);
    CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
    Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();

    assertTrue(mameOpts.hasOption("prescale"));
    assertFalse(mameOpts.hasOption("noprescale"));

    Option opt = mameOpts.getOption("prescale");

    assertTrue(opt.hasArg());

}
 
Example 5
@Test
public void testDeduceFromMameRuntimeWithCommandOption ()
        throws FileNotFoundException,
               IOException,
               InterruptedException,
               MameExecutionException {
    
    FakeMameRuntime mame = new FakeMameRuntime();
    List<InputStream> inputStreams = new ArrayList<>();
    inputStreams.add(
        new FileInputStream("src/test/resources/showconfig.txt"));
    inputStreams.add(
        new FileInputStream("src/test/resources/showusage.txt"));
    mame.setInputStreamsToReturn(inputStreams);
    CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
    Options commands 
        = clof.deduceFromMameRuntime(mame).getCommands();

    assertTrue(commands.hasOption("help"));

    Option command = commands.getOption("help");

    assertFalse(command.hasArg());

}
 
Example 6
@Test
public void testDeduceFromMameRuntimeWithMediaTypeOption ()
        throws FileNotFoundException,
               IOException,
               InterruptedException,
               MameExecutionException {
    
    FakeMameRuntime mame = new FakeMameRuntime();
    List<InputStream> inputStreams = new ArrayList<>();
    inputStreams.add(
        new FileInputStream("src/test/resources/showconfig.txt"));
    inputStreams.add(
        new FileInputStream("src/test/resources/showusage.txt"));
    mame.setInputStreamsToReturn(inputStreams);
    CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
    Options mediaTypes 
        = clof.deduceFromMameRuntime(mame).getMediaTypes();

    assertTrue(mediaTypes.hasOption("cart"));

    Option opt = mediaTypes.getOption("cart");

    assertTrue(opt.hasArg());

}
 
Example 7
protected void assertOption(Options options, String optionName, boolean isRequired, boolean hasArgument) {
    Option option = options.getOption(optionName);
    assertNotNull(option);
    assertEquals(isRequired, option.isRequired());
    assertEquals(hasArgument, option.hasArg());
}