Java Code Examples for org.apache.commons.cli.PosixParser

The following are top voted examples for showing how to use org.apache.commons.cli.PosixParser. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: UpdateTopicSubCommandTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testExecute() {
    UpdateTopicSubCommand cmd = new UpdateTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {
        "-b 127.0.0.1:10911",
        "-c default-cluster",
        "-t unit-test",
        "-r 8",
        "-w 8",
        "-p 6",
        "-o false",
        "-u false",
        "-s false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('b').trim()).isEqualTo("127.0.0.1:10911");
    assertThat(commandLine.getOptionValue('c').trim()).isEqualTo("default-cluster");
    assertThat(commandLine.getOptionValue('r').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('w').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('p').trim()).isEqualTo("6");
    assertThat(commandLine.getOptionValue('o').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('u').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("false");
}
 
Example 2
Project: cyberduck   File: CommandLineUriParserTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testParse() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[]{});

    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Arrays.asList(new FTPTLSProtocol() {
        @Override
        public boolean isEnabled() {
            return true;
        }
    }, new S3Protocol() {
        @Override
        public boolean isEnabled() {
            return true;
        }
    })));
    assertTrue(new Host(new S3Protocol(), "s3.amazonaws.com", 443, "/cyberduck-test/key", new Credentials("AWS456", null))
            .compareTo(new CommandLineUriParser(input, factory).parse("s3://[email protected]/key")) == 0);
    assertTrue(new Host(new FTPTLSProtocol(), "cyberduck.io", 55, "/folder", new Credentials("anonymous", null))
            .compareTo(new CommandLineUriParser(input, factory).parse("ftps://cyberduck.io:55/folder")) == 0);
}
 
Example 3
Project: cyberduck   File: CommandLineUriParserTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testProfile() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[]{});
    final Set<Protocol> list = new HashSet<>(Arrays.asList(
            new SwiftProtocol(),
            new ProfilePlistReader(new ProtocolFactory(Collections.singleton(new SwiftProtocol() {
                @Override
                public boolean isEnabled() {
                    return true;
                }
            })))
                    .read(new Local("../profiles/default/Rackspace US.cyberduckprofile"))
    ));
    assertTrue(new Host(new ProtocolFactory(list).forName("rackspace"), "identity.api.rackspacecloud.com", 443, "/cdn.cyberduck.ch/", new Credentials("u", null))
            .compareTo(new CommandLineUriParser(input, new ProtocolFactory(list)).parse("rackspace://[email protected]/")) == 0);

}
 
Example 4
Project: cyberduck   File: TerminalTransferFactoryTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testFilter() throws Exception {
    final CommandLineParser parser = new PosixParser();

    final Transfer transfer = new TerminalTransferFactory().create(parser.parse(TerminalOptionsBuilder.options(), new String[]{"--download", "rackspace://cdn.cyberduck.ch/remote/*.css"}),
            new Host(new SwiftProtocol()), new Path("/remote/*.css", EnumSet.of(Path.Type.directory)), Collections.<TransferItem>emptyList());
    assertEquals(Transfer.Type.download, transfer.getType());
    final PathCache cache = new PathCache(1);
    transfer.withCache(cache);
    cache.clear();
    cache.put(new Path("/remote", EnumSet.of(Path.Type.directory)), new AttributedList<Path>(Collections.singletonList(new Path("/remote/file.css", EnumSet.of(Path.Type.file)))));
    assertFalse(transfer.list(null, null, new Path("/remote", EnumSet.of(Path.Type.directory)), new Local("/tmp"), new DisabledListProgressListener()).isEmpty());
    cache.clear();
    cache.put(new Path("/remote", EnumSet.of(Path.Type.directory)), new AttributedList<Path>(Collections.singletonList(new Path("/remote/file.png", EnumSet.of(Path.Type.file)))));
    assertTrue(transfer.list(null, null, new Path("/remote", EnumSet.of(Path.Type.directory)), new Local("/tmp"), new DisabledListProgressListener()).isEmpty());
}
 
Example 5
Project: cyberduck   File: CommandLinePathParserTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testParseProfile() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new SwiftProtocol() {
        @Override
        public boolean isEnabled() {
            return true;
        }
    })));
    final ProfilePlistReader reader = new ProfilePlistReader(factory, new DeserializerFactory(PlistDeserializer.class.getName()));
    final Profile profile = reader.read(
            new Local("../profiles/default/Rackspace US.cyberduckprofile")
    );
    assertNotNull(profile);

    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[]{});

    assertEquals(new Path("/cdn.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)),
            new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))).parse("rackspace://[email protected]/"));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)),
            new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))).parse("rackspace:///"));
}
 
Example 6
Project: https-github.com-apache-zookeeper   File: AddAuthCommand.java   Source Code and License 6 votes vote down vote up
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    CommandLine cl;
    try {
        cl = parser.parse(options, cmdArgs);
    } catch (ParseException ex) {
        throw new CliParseException(ex);
    }

    args = cl.getArgs();
    if (args.length < 2) {
        throw new CliParseException(getUsageStr());
    }

    return this;
}
 
Example 7
Project: https-github.com-apache-zookeeper   File: DeleteAllCommand.java   Source Code and License 6 votes vote down vote up
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    CommandLine cl;
    try {
        cl = parser.parse(options, cmdArgs);
    } catch (ParseException ex) {
        throw new CliParseException(ex);
    }
    args = cl.getArgs();
    if (args.length < 2) {
        throw new CliParseException(getUsageStr());
    }

    return this;
}
 
Example 8
Project: https-github.com-apache-zookeeper   File: SyncCommand.java   Source Code and License 6 votes vote down vote up
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    CommandLine cl;
    try {
        cl = parser.parse(options, cmdArgs);
    } catch (ParseException ex) {
        throw new CliParseException(ex);
    }
    args = cl.getArgs();
    if (args.length < 2) {
        throw new CliParseException(getUsageStr());
    }

    return this;
}
 
Example 9
Project: hadoop   File: DFSUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Parse the arguments for commands
 * 
 * @param args the argument to be parsed
 * @param helpDescription help information to be printed out
 * @param out Printer
 * @param printGenericCommandUsage whether to print the 
 *              generic command usage defined in ToolRunner
 * @return true when the argument matches help option, false if not
 */
public static boolean parseHelpArgument(String[] args,
    String helpDescription, PrintStream out, boolean printGenericCommandUsage) {
  if (args.length == 1) {
    try {
      CommandLineParser parser = new PosixParser();
      CommandLine cmdLine = parser.parse(helpOptions, args);
      if (cmdLine.hasOption(helpOpt.getOpt())
          || cmdLine.hasOption(helpOpt.getLongOpt())) {
        // should print out the help information
        out.println(helpDescription + "\n");
        if (printGenericCommandUsage) {
          ToolRunner.printGenericCommandUsage(out);
        }
        return true;
      }
    } catch (ParseException pe) {
      return false;
    }
  }
  return false;
}
 
Example 10
Project: rmq4note   File: UpdateTopicSubCommandTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testExecute() {
    UpdateTopicSubCommand cmd = new UpdateTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {
        "-b 127.0.0.1:10911",
        "-c default-cluster",
        "-t unit-test",
        "-r 8",
        "-w 8",
        "-p 6",
        "-o false",
        "-u false",
        "-s false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('b').trim()).isEqualTo("127.0.0.1:10911");
    assertThat(commandLine.getOptionValue('c').trim()).isEqualTo("default-cluster");
    assertThat(commandLine.getOptionValue('r').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('w').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('p').trim()).isEqualTo("6");
    assertThat(commandLine.getOptionValue('o').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('u').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("false");
}
 
Example 11
Project: aliyun-oss-hadoop-fs   File: DFSUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Parse the arguments for commands
 * 
 * @param args the argument to be parsed
 * @param helpDescription help information to be printed out
 * @param out Printer
 * @param printGenericCommandUsage whether to print the 
 *              generic command usage defined in ToolRunner
 * @return true when the argument matches help option, false if not
 */
public static boolean parseHelpArgument(String[] args,
    String helpDescription, PrintStream out, boolean printGenericCommandUsage) {
  if (args.length == 1) {
    try {
      CommandLineParser parser = new PosixParser();
      CommandLine cmdLine = parser.parse(helpOptions, args);
      if (cmdLine.hasOption(helpOpt.getOpt())
          || cmdLine.hasOption(helpOpt.getLongOpt())) {
        // should print out the help information
        out.println(helpDescription + "\n");
        if (printGenericCommandUsage) {
          ToolRunner.printGenericCommandUsage(out);
        }
        return true;
      }
    } catch (ParseException pe) {
      return false;
    }
  }
  return false;
}
 
Example 12
Project: GeoCrawler   File: NutchServer.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws ParseException {
  CommandLineParser parser = new PosixParser();
  Options options = createOptions();
  CommandLine commandLine = parser.parse(options, args);
  if (commandLine.hasOption(CMD_HELP)) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("NutchServer", options, true);
    return;
  }

  if (commandLine.hasOption(CMD_PORT)) {
    port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT));
  }

  if (commandLine.hasOption(CMD_HOST)) {
    host = commandLine.getOptionValue(CMD_HOST);
  }

  startServer();
}
 
Example 13
Project: big-c   File: DFSUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Parse the arguments for commands
 * 
 * @param args the argument to be parsed
 * @param helpDescription help information to be printed out
 * @param out Printer
 * @param printGenericCommandUsage whether to print the 
 *              generic command usage defined in ToolRunner
 * @return true when the argument matches help option, false if not
 */
public static boolean parseHelpArgument(String[] args,
    String helpDescription, PrintStream out, boolean printGenericCommandUsage) {
  if (args.length == 1) {
    try {
      CommandLineParser parser = new PosixParser();
      CommandLine cmdLine = parser.parse(helpOptions, args);
      if (cmdLine.hasOption(helpOpt.getOpt())
          || cmdLine.hasOption(helpOpt.getLongOpt())) {
        // should print out the help information
        out.println(helpDescription + "\n");
        if (printGenericCommandUsage) {
          ToolRunner.printGenericCommandUsage(out);
        }
        return true;
      }
    } catch (ParseException pe) {
      return false;
    }
  }
  return false;
}
 
Example 14
Project: rocketmq   File: UpdateTopicSubCommandTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testExecute() {
    UpdateTopicSubCommand cmd = new UpdateTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {
        "-b 127.0.0.1:10911",
        "-c default-cluster",
        "-t unit-test",
        "-r 8",
        "-w 8",
        "-p 6",
        "-o false",
        "-u false",
        "-s false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('b').trim()).isEqualTo("127.0.0.1:10911");
    assertThat(commandLine.getOptionValue('c').trim()).isEqualTo("default-cluster");
    assertThat(commandLine.getOptionValue('r').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('w').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('p').trim()).isEqualTo("6");
    assertThat(commandLine.getOptionValue('o').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('u').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("false");
}
 
Example 15
Project: SparkToParquet   File: Flags.java   Source Code and License 6 votes vote down vote up
public static void setFromCommandLineArgs(Options options, String[] args) {
	CommandLineParser parser = new PosixParser();
	try {
		CommandLine cl = parser.parse(options, args);
		// 参数默认值
		THE_INSTANCE.windowLength = new Duration(
				Integer.parseInt(cl.getOptionValue(AppMain.WINDOW_LENGTH, "30")) * 1000);
		THE_INSTANCE.slideInterval = new Duration(
				Integer.parseInt(cl.getOptionValue(AppMain.SLIDE_INTERVAL, "5")) * 1000);
		THE_INSTANCE.kafka_broker = cl.getOptionValue(AppMain.KAFKA_BROKER, "kafka:9092");
		THE_INSTANCE.kafka_topic = cl.getOptionValue(AppMain.KAFKA_TOPIC, "apache");
		THE_INSTANCE.parquet_file = cl.getOptionValue(AppMain.PARQUET_FILE, "/user/spark/");
		THE_INSTANCE.initialized = true;
	} catch (ParseException e) {
		THE_INSTANCE.initialized = false;
		System.err.println("Parsing failed.  Reason: " + e.getMessage());
	}
}
 
Example 16
Project: TopPI   File: TopPIcli.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	Options options = getOptions();
	
	try {
		CommandLineParser parser = new PosixParser();
		GenericOptionsParser hadoopCmd = new GenericOptionsParser(args);
		CommandLine cmd = parser.parse(options, hadoopCmd.getRemainingArgs());

		if (cmd.getArgs().length < 2 || cmd.getArgs().length > 3 || cmd.hasOption('h')) {
			printMan(options);
		} else if (!cmd.hasOption('k')) {
			System.err.println("-k parameter is mandatory");
			System.exit(1);
		} else if (cmd.hasOption('g')) {
			hadoop(args);
		} else {
			standalone(cmd);
		}
	} catch (ParseException e) {
		printMan(options);
	}
}
 
Example 17
Project: mesfavoris   File: BugCLI13Test.java   Source Code and License 6 votes vote down vote up
@Test
public void testCLI13() throws ParseException
{
    final String debugOpt = "debug";
    @SuppressWarnings("static-access")
    Option debug = OptionBuilder
        .withArgName( debugOpt )
        .withDescription( "turn on debugging" )
        .withLongOpt( debugOpt )
        .hasArg()
        .create( 'd' );
    Options options = new Options();
    options.addOption( debug );
    CommandLine commandLine = new PosixParser().parse( options, new String[]{"-d", "true"} );

    assertEquals("true", commandLine.getOptionValue( debugOpt ));
    assertEquals("true", commandLine.getOptionValue( 'd' ));
    assertTrue(commandLine.hasOption( 'd'));
    assertTrue(commandLine.hasOption( debugOpt));
}
 
Example 18
Project: mesfavoris   File: BugsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void test15046() throws Exception
{
    CommandLineParser parser = new PosixParser();
    String[] CLI_ARGS = new String[] {"-z", "c"};

    Options options = new Options();
    options.addOption(new Option("z", "timezone", true, "affected option"));

    parser.parse(options, CLI_ARGS);
    
    //now add conflicting option
    options.addOption("c", "conflict", true, "conflict option");
    CommandLine line = parser.parse(options, CLI_ARGS);
    assertEquals( line.getOptionValue('z'), "c" );
    assertTrue( !line.hasOption("c") );
}
 
Example 19
Project: mesfavoris   File: BugsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void test31148() throws ParseException
{
    Option multiArgOption = new Option("o","option with multiple args");
    multiArgOption.setArgs(1);
    
    Options options = new Options();
    options.addOption(multiArgOption);
    
    Parser parser = new PosixParser();
    String[] args = new String[]{};
    Properties props = new Properties();
    props.setProperty("o","ovalue");
    CommandLine cl = parser.parse(options,args,props);
    
    assertTrue(cl.hasOption('o'));
    assertEquals("ovalue",cl.getOptionValue('o'));
}
 
Example 20
Project: mesfavoris   File: BugCLI13Test.java   Source Code and License 6 votes vote down vote up
@Test
public void testCLI13() throws ParseException
{
    final String debugOpt = "debug";
    @SuppressWarnings("static-access")
    Option debug = OptionBuilder
        .withArgName( debugOpt )
        .withDescription( "turn on debugging" )
        .withLongOpt( debugOpt )
        .hasArg()
        .create( 'd' );
    Options options = new Options();
    options.addOption( debug );
    CommandLine commandLine = new PosixParser().parse( options, new String[]{"-d", "true"} );

    assertEquals("true", commandLine.getOptionValue( debugOpt ));
    assertEquals("true", commandLine.getOptionValue( 'd' ));
    assertTrue(commandLine.hasOption( 'd'));
    assertTrue(commandLine.hasOption( debugOpt));
}
 
Example 21
Project: mesfavoris   File: BugsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void test15046() throws Exception
{
    CommandLineParser parser = new PosixParser();
    String[] CLI_ARGS = new String[] {"-z", "c"};

    Options options = new Options();
    options.addOption(new Option("z", "timezone", true, "affected option"));

    parser.parse(options, CLI_ARGS);
    
    //now add conflicting option
    options.addOption("c", "conflict", true, "conflict option");
    CommandLine line = parser.parse(options, CLI_ARGS);
    assertEquals( line.getOptionValue('z'), "c" );
    assertTrue( !line.hasOption("c") );
}
 
Example 22
Project: mesfavoris   File: BugCLI13Test.java   Source Code and License 6 votes vote down vote up
@Test
public void testCLI13() throws ParseException
{
    final String debugOpt = "debug";
    @SuppressWarnings("static-access")
    Option debug = OptionBuilder
        .withArgName( debugOpt )
        .withDescription( "turn on debugging" )
        .withLongOpt( debugOpt )
        .hasArg()
        .create( 'd' );
    Options options = new Options();
    options.addOption( debug );
    CommandLine commandLine = new PosixParser().parse( options, new String[]{"-d", "true"} );

    assertEquals("true", commandLine.getOptionValue( debugOpt ));
    assertEquals("true", commandLine.getOptionValue( 'd' ));
    assertTrue(commandLine.hasOption( 'd'));
    assertTrue(commandLine.hasOption( debugOpt));
}
 
Example 23
Project: mesfavoris   File: BugsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void test15046() throws Exception
{
    CommandLineParser parser = new PosixParser();
    String[] CLI_ARGS = new String[] {"-z", "c"};

    Options options = new Options();
    options.addOption(new Option("z", "timezone", true, "affected option"));

    parser.parse(options, CLI_ARGS);
    
    //now add conflicting option
    options.addOption("c", "conflict", true, "conflict option");
    CommandLine line = parser.parse(options, CLI_ARGS);
    assertEquals( line.getOptionValue('z'), "c" );
    assertTrue( !line.hasOption("c") );
}
 
Example 24
Project: mesfavoris   File: BugsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void test31148() throws ParseException
{
    Option multiArgOption = new Option("o","option with multiple args");
    multiArgOption.setArgs(1);
    
    Options options = new Options();
    options.addOption(multiArgOption);
    
    Parser parser = new PosixParser();
    String[] args = new String[]{};
    Properties props = new Properties();
    props.setProperty("o","ovalue");
    CommandLine cl = parser.parse(options,args,props);
    
    assertTrue(cl.hasOption('o'));
    assertEquals("ovalue",cl.getOptionValue('o'));
}
 
Example 25
Project: mesfavoris   File: BugCLI13Test.java   Source Code and License 6 votes vote down vote up
@Test
public void testCLI13() throws ParseException
{
    final String debugOpt = "debug";
    @SuppressWarnings("static-access")
    Option debug = OptionBuilder
        .withArgName( debugOpt )
        .withDescription( "turn on debugging" )
        .withLongOpt( debugOpt )
        .hasArg()
        .create( 'd' );
    Options options = new Options();
    options.addOption( debug );
    CommandLine commandLine = new PosixParser().parse( options, new String[]{"-d", "true"} );

    assertEquals("true", commandLine.getOptionValue( debugOpt ));
    assertEquals("true", commandLine.getOptionValue( 'd' ));
    assertTrue(commandLine.hasOption( 'd'));
    assertTrue(commandLine.hasOption( debugOpt));
}
 
Example 26
Project: mesfavoris   File: BugsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void test15046() throws Exception
{
    CommandLineParser parser = new PosixParser();
    String[] CLI_ARGS = new String[] {"-z", "c"};

    Options options = new Options();
    options.addOption(new Option("z", "timezone", true, "affected option"));

    parser.parse(options, CLI_ARGS);
    
    //now add conflicting option
    options.addOption("c", "conflict", true, "conflict option");
    CommandLine line = parser.parse(options, CLI_ARGS);
    assertEquals( line.getOptionValue('z'), "c" );
    assertTrue( !line.hasOption("c") );
}
 
Example 27
Project: mesfavoris   File: BugsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void test31148() throws ParseException
{
    Option multiArgOption = new Option("o","option with multiple args");
    multiArgOption.setArgs(1);
    
    Options options = new Options();
    options.addOption(multiArgOption);
    
    Parser parser = new PosixParser();
    String[] args = new String[]{};
    Properties props = new Properties();
    props.setProperty("o","ovalue");
    CommandLine cl = parser.parse(options,args,props);
    
    assertTrue(cl.hasOption('o'));
    assertEquals("ovalue",cl.getOptionValue('o'));
}
 
Example 28
Project: flink   File: MesosSessionClusterEntrypoint.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) {
	// startup checks and logging
	EnvironmentInformation.logEnvironmentInfo(LOG, MesosSessionClusterEntrypoint.class.getSimpleName(), args);
	SignalHandler.register(LOG);
	JvmShutdownSafeguard.installAsShutdownHook(LOG);

	// load configuration incl. dynamic properties
	CommandLineParser parser = new PosixParser();
	CommandLine cmd;
	try {
		cmd = parser.parse(ALL_OPTIONS, args);
	}
	catch (Exception e){
		LOG.error("Could not parse the command-line options.", e);
		System.exit(STARTUP_FAILURE_RETURN_CODE);
		return;
	}

	Configuration dynamicProperties = BootstrapTools.parseDynamicProperties(cmd);
	Configuration configuration = MesosEntrypointUtils.loadConfiguration(dynamicProperties, LOG);

	MesosSessionClusterEntrypoint clusterEntrypoint = new MesosSessionClusterEntrypoint(configuration, dynamicProperties);

	clusterEntrypoint.startCluster();
}
 
Example 29
Project: flink   File: MesosJobClusterEntrypoint.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) {
	// startup checks and logging
	EnvironmentInformation.logEnvironmentInfo(LOG, MesosJobClusterEntrypoint.class.getSimpleName(), args);
	SignalHandler.register(LOG);
	JvmShutdownSafeguard.installAsShutdownHook(LOG);

	// load configuration incl. dynamic properties
	CommandLineParser parser = new PosixParser();
	CommandLine cmd;
	try {
		cmd = parser.parse(ALL_OPTIONS, args);
	}
	catch (Exception e){
		LOG.error("Could not parse the command-line options.", e);
		System.exit(STARTUP_FAILURE_RETURN_CODE);
		return;
	}

	Configuration dynamicProperties = BootstrapTools.parseDynamicProperties(cmd);
	Configuration configuration = MesosEntrypointUtils.loadConfiguration(dynamicProperties, LOG);

	MesosJobClusterEntrypoint clusterEntrypoint = new MesosJobClusterEntrypoint(configuration, dynamicProperties);

	clusterEntrypoint.startCluster();
}
 
Example 30
Project: s3-inventory-usage-examples   File: ArgumentParser.java   Source Code and License 5 votes vote down vote up
public ArgumentParser() {
    final Option input =
            new Option(KEY_INPUT, longOptInput, true,
                    "read in this S3 URI to get inventory manifest files");
    final Option output =
            new Option(KEY_OUTPUT, longOptOutput, true,
                    "write new files back to this output S3 URI prefix");
    this.options = new Options();
    input.setRequired(true);
    this.options.addOption(input);
    output.setRequired(true);
    this.options.addOption(output);
    this.parser = new PosixParser();
}
 
Example 31
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: QueryConsumeQueueCommand.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
    QueryConsumeQueueCommand cmd = new QueryConsumeQueueCommand();

    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[]{"-t TopicTest", "-q 0", "-i 6447", "-b 100.81.165.119:10911"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options),
            new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example 32
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: ConsumerStatusSubCommandTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ConsumerStatusSubCommand cmd = new ConsumerStatusSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-i cid_one"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example 33
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: ConsumerProgressSubCommandTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ConsumerProgressSubCommand cmd = new ConsumerProgressSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example 34
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: ResetOffsetByTimeOldCommandTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testExecute() {
    ResetOffsetByTimeOldCommand cmd = new ResetOffsetByTimeOldCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('g').trim()).isEqualTo("default-group");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("1412131213231");
}
 
Example 35
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: GetConsumerStatusCommandTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    GetConsumerStatusCommand cmd = new GetConsumerStatusCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-i clientid"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example 36
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: ResetOffsetByTimeCommandTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ResetOffsetByTimeCommand cmd = new ResetOffsetByTimeCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example 37
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: BrokerConsumeStatsSubCommadTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    BrokerConsumeStatsSubCommad cmd = new BrokerConsumeStatsSubCommad();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-t 3000", "-l 5", "-o true"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example 38
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: GetBrokerConfigCommandTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    GetBrokerConfigCommand cmd = new GetBrokerConfigCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example 39
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: SendMsgStatusCommandTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testExecute() {
    SendMsgStatusCommand cmd = new SendMsgStatusCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-s 1024 -c 10"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    //cmd.execute(commandLine, options, null);
}
 
Example 40
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: UpdateBrokerConfigSubCommandTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    UpdateBrokerConfigSubCommand cmd = new UpdateBrokerConfigSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster", "-k topicname", "-v unit_test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}