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

The following are top voted examples for showing how to use org.apache.commons.cli.Options. 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: rmq4note   File: ConsumerProgressSubCommand.java   Source Code and License 9 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "groupName", true, "consumer group name");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}
 
Example 2
Project: smaph   File: ServerMain.java   Source Code and License 7 votes vote down vote up
/**
 * Main method.
 * 
 * @param args
 * @throws IOException
 * @throws ParseException
 */
public static void main(String[] args) throws Exception {
	java.util.logging.Logger l = java.util.logging.Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler");
	l.setLevel(java.util.logging.Level.FINE);
	l.setUseParentHandlers(false);
	java.util.logging.ConsoleHandler ch = new java.util.logging.ConsoleHandler();
	ch.setLevel(java.util.logging.Level.ALL);
	l.addHandler(ch);

	CommandLineParser parser = new GnuParser();
	Options options = new Options();
	options.addOption("h", "host", true, "Server hostname.");
	options.addOption("p", "port", true, "TCP port to listen.");
	options.addOption("s", "storage_path", true, "Storage path.");
	options.addOption("w", "wat_gcube_token", true, "WAT gcube authentication token");
	CommandLine line = parser.parse(options, args);

	String serverUri = String.format("http://%s:%d/smaph", line.getOptionValue("host", "localhost"),
	        Integer.parseInt(line.getOptionValue("port", "8080")));
	Path storage = Paths.get(line.getOptionValue("storage_path"));
	startServer(serverUri, storage, line.getOptionValue("wat_gcube_token"));
}
 
Example 3
Project: hadoop-oss   File: TestGenericOptionsParser.java   Source Code and License 7 votes vote down vote up
/**
 * Test that options passed to the constructor are used.
 */
@SuppressWarnings("static-access")
public void testCreateWithOptions() throws Exception {
  // Create new option newOpt
  Option opt = OptionBuilder.withArgName("int")
  .hasArg()
  .withDescription("A new option")
  .create("newOpt");
  Options opts = new Options();
  opts.addOption(opt);

  // Check newOpt is actually used to parse the args
  String[] args = new String[2];
  args[0] = "--newOpt";
  args[1] = "7";
  GenericOptionsParser g = new GenericOptionsParser(opts, args);
  assertEquals("New option was ignored",
    "7", g.getCommandLine().getOptionValues("newOpt")[0]);
}
 
Example 4
Project: pm-home-station   File: Start.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    try {
        Options options = getOptions();
        CommandLine line = parser.parse(options, args );
        if (line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            System.out.println(Constants.PROJECT_NAME + ", " + Constants.PROJECT_URL);
            formatter.printHelp(Constants.PROJECT_NAME, options, true);
        } else if (line.hasOption("version")) {
            System.out.println("version: " + Constants.VERSION);
        } else {
            logger.info("Starting pm-home-station ({} v.{})...", Constants.PROJECT_URL, Constants.VERSION);
            setLookAndFeel();
            PlanTowerSensor planTowerSensor = new PlanTowerSensor();
            Station station = new Station(planTowerSensor);
            SwingUtilities.invokeLater(() -> { station.showUI(); });
        }
    } catch (ParseException e) {
        logger.error("Ooops", e);
        return;
    }
}
 
Example 5
Project: nn_nex_logging_and_research   File: StarterFunctionFinder.java   Source Code and License 6 votes vote down vote up
private static Options getOptions() {
    Options options = new Options();
    options.addOption(
            Option.builder("in").longOpt(PARAMETER_INPUT_FILE).argName("input file").hasArg().desc("Input file. Can be a .rpx or .rpx").required().build());
    options.addOption(Option.builder("f").longOpt(PARAMETER_FUNCTION_NAME).argName("The function name to be searched in the input file").hasArg().desc("").build());
    options.addOption(Option.builder("m").longOpt(PARAMETER_MAX_SIGNATURE_LENGTH).hasArg()
            .desc("Maximum length of the signature that will be checked. Default is " + SIGNATURE_LENGTH).optionalArg(true).build());
    options.addOption(Option.builder("t").longOpt(PARAMETER_FILTER_FILE).hasArg().argName("file").desc("A file containing a list of Hex Strings representing a list of TitleIDs in the folder " + RPX_WITH_SYMBOLS_FOLDER + " that should be used.").build());
    options.addOption(Option.builder("v").longOpt(PARAMETER_VERBOSE_LOGGING).desc("Enables verbose logging").build());
    options.addOption(Option.builder("e").longOpt(PARAMETER_EXTRA_FUNCTIONS).argName("filename").hasArg().desc("A file contains a list of functions that should be checked.").build());
    options.addOption(Option.builder("s").longOpt(PARAMETER_RPX_WITH_SYMBOLS_FOLDER).hasArg().argName("filename").desc("Sets the path to the folder which contains folders (named the TITLEID) which contain the RPX files with symbols.=> A folder containing this: /1234567812345678/test.rpx /1234567812345698/test2.rpx").build());

    options.addOption("help", false, "Shows this text");

    return options;
}
 
Example 6
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: TopicRouteSubCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
        String json = topicRouteData.toJson(true);
        System.out.printf("%s%n", json);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 7
Project: ripme   File: App.java   Source Code and License 6 votes vote down vote up
/**
 * Creates an Options object, returns it.
 * @return Returns all acceptable command-line options.
 */
private static Options getOptions() {
    Options opts = new Options();
    opts.addOption("h", "help", false, "Print the help");
    opts.addOption("u", "url", true, "URL of album to rip");
    opts.addOption("t", "threads", true, "Number of download threads per rip");
    opts.addOption("w", "overwrite", false, "Overwrite existing files");
    opts.addOption("r", "rerip", false, "Re-rip all ripped albums");
    opts.addOption("R", "rerip-selected", false, "Re-rip all selected albums");
    opts.addOption("d", "saveorder", false, "Save the order of images in album");
    opts.addOption("D", "nosaveorder", false, "Don't save order of images");
    opts.addOption("4", "skip404", false, "Don't retry after a 404 (not found) error");
    opts.addOption("l", "ripsdirectory", true, "Rips Directory (Default: ./rips)");
    opts.addOption("n", "no-prop-file", false, "Do not create properties file.");
    opts.addOption("f", "urls-file", true, "Rip URLs from a file.");
    opts.addOption("v", "version", false, "Show current version");
    return opts;
}
 
Example 8
Project: rmq4note   File: TopicClusterSubCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    String topic = commandLine.getOptionValue('t').trim();
    try {
        defaultMQAdminExt.start();
        Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic);
        for (String value : clusters) {
            System.out.printf("%s%n", value);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 9
Project: rmq4note   File: QueryMsgByKeySubCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        final String topic = commandLine.getOptionValue('t').trim();
        final String key = commandLine.getOptionValue('k').trim();

        this.queryByKey(defaultMQAdminExt, topic, key);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 10
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: DeleteTopicSubCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String topic = commandLine.getOptionValue('t').trim();

        if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();

            adminExt.start();
            deleteTopic(adminExt, clusterName, topic);
            return;
        }

        ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        adminExt.shutdown();
    }
}
 
Example 11
Project: reading-and-annotate-rocketmq-3.4.6   File: TopicClusterSubCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    String topic = commandLine.getOptionValue('t').trim();
    try {
        defaultMQAdminExt.start();
        Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic);
        for (String value : clusters){
            System.out.println(value);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 12
Project: reading-and-annotate-rocketmq-3.4.6   File: UpdateKvConfigCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        // namespace
        String namespace = commandLine.getOptionValue('s').trim();
        // key name
        String key = commandLine.getOptionValue('k').trim();
        // key name
        String value = commandLine.getOptionValue('v').trim();

        defaultMQAdminExt.start();
        defaultMQAdminExt.createAndUpdateKvConfig(namespace, key, value);
        System.out.printf("create or update kv config to namespace success.\n");
        return;
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 13
Project: hadoop-oss   File: TestTFileSeqFileComparison.java   Source Code and License 6 votes vote down vote up
public MyOptions(String[] args) {
  seed = System.nanoTime();

  try {
    Options opts = buildOptions();
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(opts, args, true);
    processOptions(line, opts);
    validateOptions();
  }
  catch (ParseException e) {
    System.out.println(e.getMessage());
    System.out.println("Try \"--help\" option for details.");
    setStopProceed();
  }
}
 
Example 14
Project: pm-home-station   File: Start.java   Source Code and License 6 votes vote down vote up
private static Options getOptions() {
    Options options = new Options();
    //options.addOption("noui", false, "no UI, console only");
    options.addOption("h", "help", false, "print this message and exit");
    options.addOption("v", "version", false, "print the version information and exit");
    return options;
}
 
Example 15
Project: rmq4note   File: CleanUnusedTopicCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        boolean result = false;
        defaultMQAdminExt.start();
        if (commandLine.hasOption('b')) {
            String addr = commandLine.getOptionValue('b').trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(addr);

        } else {
            String cluster = commandLine.getOptionValue('c');
            if (null != cluster)
                cluster = cluster.trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(cluster);
        }
        System.out.printf(result ? "success" : "false");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 16
Project: rmq4note   File: CleanExpiredCQSubCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        boolean result = false;
        defaultMQAdminExt.start();
        if (commandLine.hasOption('b')) {
            String addr = commandLine.getOptionValue('b').trim();
            result = defaultMQAdminExt.cleanExpiredConsumerQueueByAddr(addr);

        } else {
            String cluster = commandLine.getOptionValue('c');
            if (null != cluster)
                cluster = cluster.trim();
            result = defaultMQAdminExt.cleanExpiredConsumerQueue(cluster);
        }
        System.out.printf(result ? "success" : "false");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 17
Project: devops-cm-client   File: UploadFileToTransport.java   Source Code and License 6 votes vote down vote up
public final static void main(String[] args) throws Exception {
    logger.debug(format("%s called with arguments: '%s'.", UploadFileToTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
    Options options = new Options();
    Commands.Helpers.addStandardParameters(options);

    if(helpRequested(args)) {
        handleHelpOption(format("%s <changeId> <transportId> <applicationId> <filePath>", getCommandName(UploadFileToTransport.class)),
                "Uploads the file specified by <filePath> to transport <transportId> for change <changeId>. "
                + "<applicationId> specifies how the file needs to be handled on server side.", new Options()); return;
    }

    CommandLine commandLine = new DefaultParser().parse(options, args);

    new UploadFileToTransport(
            getHost(commandLine),
            getUser(commandLine),
            getPassword(commandLine),
            getChangeId(commandLine),
            getArg(commandLine, 2, "transportId"),
            getArg(commandLine, 3, "applicationId"),
            getArg(commandLine, 4, "filePath")).execute();
}
 
Example 18
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: CleanUnusedTopicCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        boolean result = false;
        defaultMQAdminExt.start();
        if (commandLine.hasOption('b')) {
            String addr = commandLine.getOptionValue('b').trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(addr);

        } else {
            String cluster = commandLine.getOptionValue('c');
            if (null != cluster)
                cluster = cluster.trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(cluster);
        }
        System.out.printf(result ? "success" : "false");
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 19
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: SendMsgStatusCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook);
    producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis());

    try {
        producer.start();
        String brokerName = commandLine.getOptionValue('b').trim();
        int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128;
        int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('c')) : 50;

        producer.send(buildMessage(brokerName, 16));

        for (int i = 0; i < count; i++) {
            long begin = System.currentTimeMillis();
            SendResult result = producer.send(buildMessage(brokerName, messageSize));
            System.out.printf("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=" + result);
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        producer.shutdown();
    }
}
 
Example 20
Project: ditb   File: ThriftServer.java   Source Code and License 6 votes vote down vote up
private static Options getOptions() {
  Options options = new Options();
  options.addOption("b", "bind", true,
      "Address to bind the Thrift server to. [default: 0.0.0.0]");
  options.addOption("p", "port", true, "Port to bind to [default: " + DEFAULT_LISTEN_PORT + "]");
  options.addOption("f", "framed", false, "Use framed transport");
  options.addOption("c", "compact", false, "Use the compact protocol");
  options.addOption("w", "workers", true, "How many worker threads to use.");
  options.addOption("h", "help", false, "Print help information");
  options.addOption(null, "infoport", true, "Port for web UI");
  options.addOption("t", READ_TIMEOUT_OPTION, true,
    "Amount of time in milliseconds before a server thread will timeout " +
    "waiting for client to send data on a connected socket. Currently, " +
    "only applies to TBoundedThreadPoolServer");
  OptionGroup servers = new OptionGroup();
  servers.addOption(
      new Option("nonblocking", false, "Use the TNonblockingServer. This implies the framed transport."));
  servers.addOption(new Option("hsha", false, "Use the THsHaServer. This implies the framed transport."));
  servers.addOption(new Option("threadpool", false, "Use the TThreadPoolServer. This is the default."));
  options.addOptionGroup(servers);
  return options;
}
 
Example 21
Project: ParquetUtils   File: ParquetStats.java   Source Code and License 5 votes vote down vote up
private static Options configureCommandLineOptions() {
	Options result = new Options();
	result.addOption("i", "input", true, "specify the directory containing Parquet data files");
	result.addOption("c", "config", true, "specify the xml file path containing namenode address and port");

	return result;
}
 
Example 22
Project: ParquetUtils   File: CLUtils.java   Source Code and License 5 votes vote down vote up
public static CommandLine parseCommandLine(String nameApp, String descriptionApp, String[] args, Options options) {
	CommandLineParser parser = new BasicParser();
	CommandLine cmd = null;
	try {
		cmd = parser.parse(options, args);
	} catch (ParseException e) {
		usage(nameApp, descriptionApp, options);
	}
	return cmd;
}
 
Example 23
Project: ParquetUtils   File: ParquetGenerator.java   Source Code and License 5 votes vote down vote up
private static Options configureCommandLineOptions() {
	Options result = new Options();
	result.addOption("s", "structPath", true,
			"specify the input file path containing the structure of dataset in the form of key=value pairs");
	result.addOption("f", "structPath", true, "specify the path of a file .txt containing a set of values");
	result.addOption("p", "partitions", true, "number of output Parquet data files");
	result.addOption("r", "rows", true, "number of rows of each Parquet data file");
	result.addOption("o", "output", true, "specify the output directory in which to store Parquet data files");
	return result;
}
 
Example 24
Project: Open-DM   File: ManagedCLIJob.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings({ "static-access", "AccessStaticViaInstance" })
protected void getSharedOptions(Options options) {
    options.addOption(OptionBuilder.withArgName("results_path").hasArg()
            .withDescription("Directory in which to store the exported results lists.  If omitted, defaults to the current directory.")
            .withLongOpt(EXPORT_RESULTS_PATH).create());
    options.addOption(OptionBuilder.withArgName("string").hasArg()
            .withDescription("Prefix for the results lists file names.  If omitted, results lists file names have no prefix.")
            .withLongOpt(EXPORT_RESULTS_PREFIX).create());

    options.addOption(OptionBuilder.withArgName("integer").hasArg()
            .withDescription("Maximum number of connections per HCP system node.  Valid range is from 1 to 100.  If omitted, defaults to 25.")
            .withLongOpt(MAX_NODE_CONNECTIONS).create());
    options.addOption(OptionBuilder.withArgName("integer").hasArg()
            .withDescription("Maximum number of connections to the HCP system.  Valid range is from 2 to 1000.  If omitted, defaults to 200")
            .withLongOpt(MAX_CONNECTIONS).create());
    options.addOption(OptionBuilder.withArgName("integer").hasArg()
            .withDescription("Maximum number of connections per HCP system node during reduced load.  Valid range is from 1 to 100.  If omitted, defaults to 4.")
            .withLongOpt(REDUCED_MAX_NODE_CONNECTIONS).create());
    options.addOption(OptionBuilder.withArgName("integer").hasArg()
            .withDescription("Maximum number of connections to the HCP system during reduced load.  Valid range is from 2 to 1000.  If omitted, defaults to 50.")
            .withLongOpt(REDUCED_MAX_CONNECTIONS).create());
    options.addOption(OptionBuilder.withArgName("hh:mm").hasArg()
            .withDescription("Start time for the reduced load.  If omitted, defaults to 08:00.  If "
                    + REDUCED_END + " is also omitted, reduced load is off.")
            .withLongOpt(REDUCED_START).create());
    options.addOption(OptionBuilder.withArgName("hh:mm").hasArg()
            .withDescription("End time for the reduced load.  If omitted, defaults to 20:00.  If "
                    + REDUCED_START + " is also omitted, reduced load is off.")
            .withLongOpt(REDUCED_END).create());

    options.addOption(OptionBuilder.withArgName("job_name").hasArg()
            .withDescription("The name of the job.")
            .withLongOpt(JOB_NAME).create());

    options.addOption(getInsecureSSLOption());

}
 
Example 25
Project: rmq4note   File: GetNamesrvConfigCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(final CommandLine commandLine, final Options options, final RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        // servers
        String servers = commandLine.getOptionValue('n');
        List<String> serverList = null;
        if (servers != null && servers.length() > 0) {
            String[] serverArray = servers.trim().split(";");

            if (serverArray.length > 0) {
                serverList = Arrays.asList(serverArray);
            }
        }

        defaultMQAdminExt.start();

        Map<String, Properties> nameServerConfigs = defaultMQAdminExt.getNameServerConfig(serverList);

        for (String server : nameServerConfigs.keySet()) {
            System.out.printf("============%s============\n",
                server);
            for (Object key : nameServerConfigs.get(server).keySet()) {
                System.out.printf("%-50s=  %s\n", key, nameServerConfigs.get(server).get(key));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 26
Project: runtime-builder-java   File: RootModuleTest.java   Source Code and License 5 votes vote down vote up
/**
 * A check that the default settings are not outdated compared to what is in java.yaml.
 */
@Test
public void testDefaultSettingsMatchJavaYaml()
    throws URISyntaxException, IOException, ParseException {
  Path path = Paths.get("../java.yaml");

  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

  JavaYaml javaYaml = mapper.readValue(path.toFile(), JavaYaml.class);

  String[] args = ((ArrayList<String>) javaYaml.getSteps()[0].get("args")).toArray(new String[0]);

  Options options = new Options();

  Application.addCliOptions(options);

  CommandLine cmd = new DefaultParser().parse(options, args);

  String[] jdkMappings = cmd.getOptionValues("j");
  String[] serverMappings = cmd.getOptionValues("s");

  assertTrue(Arrays.equals(jdkMappings, Application.DEFAULT_JDK_MAPPINGS));
  assertTrue(Arrays.equals(serverMappings, Application.DEFAULT_SERVER_MAPPINGS));

  String compatImage = cmd.getOptionValue("c");
  String mavenImage = cmd.getOptionValue("m");
  String gradleImage = cmd.getOptionValue("g");

  assertEquals(compatImage, Application.DEFAULT_COMPAT_RUNTIME_IMAGE);
  assertEquals(mavenImage, Application.DEFAULT_MAVEN_DOCKER_IMAGE);
  assertEquals(gradleImage, Application.DEFAULT_GRADLE_DOCKER_IMAGE);
}
 
Example 27
Project: powsybl-core   File: RunScriptTool.java   Source Code and License 5 votes vote down vote up
@Override
public Options getOptions() {
    Options options = new Options();
    options.addOption(Option.builder()
            .longOpt(FILE)
            .desc("the script file")
            .hasArg()
            .required()
            .argName("FILE")
            .build());
    return options;
}
 
Example 28
Project: rmq4note   File: ClusterListSubCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    long printInterval = 1;
    boolean enableInterval = commandLine.hasOption('i');

    if (enableInterval) {
        printInterval = Long.parseLong(commandLine.getOptionValue('i')) * 1000;
    }

    try {
        defaultMQAdminExt.start();
        long i = 0;

        do {
            if (i++ > 0) {
                Thread.sleep(printInterval);
            }
            if (commandLine.hasOption('m')) {
                this.printClusterMoreStats(defaultMQAdminExt);
            } else {
                this.printClusterBaseInfo(defaultMQAdminExt);
            }
        }
        while (enableInterval);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 29
Project: powsybl-core   File: CommandLineToolsTest.java   Source Code and License 5 votes vote down vote up
@Override
public Command getCommand() {
    return new Command() {
        @Override
        public String getName() {
            return "tool1";
        }

        @Override
        public String getTheme() {
            return "theme1";
        }

        @Override
        public String getDescription() {
            return "test tool1";
        }

        @Override
        public Options getOptions() {
            Options options = new Options();
            options.addOption(Option.builder()
                    .longOpt("option1")
                    .desc("this is option 1")
                    .hasArg()
                    .argName("FILE")
                    .required()
                    .build());
            return options;
        }

        @Override
        public String getUsageFooter() {
            return "footer1";
        }
    };
}
 
Example 30
Project: reading-and-annotate-rocketmq-3.4.6   File: CleanUnusedTopicCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        boolean result = false;
        defaultMQAdminExt.start();
        if (commandLine.hasOption('b')) {
            String addr = commandLine.getOptionValue('b').trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(addr);

        }
        else {
            String cluster = commandLine.getOptionValue('c');
            if (null != cluster)
                cluster = cluster.trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(cluster);
        }
        System.out.println(result ? "success" : "false");
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 31
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 32
Project: rmq4note   File: AllocateMQSubCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        adminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        String ips = commandLine.getOptionValue('i').trim();
        final String[] split = ips.split(",");
        final List<String> ipList = new LinkedList<String>();
        for (String ip : split) {
            ipList.add(ip);
        }

        final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic);
        final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData);

        final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely();

        RebalanceResult rr = new RebalanceResult();

        for (String i : ipList) {
            final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList);
            rr.getResult().put(i, mqResult);
        }

        final String json = RemotingSerializable.toJson(rr, false);
        System.out.printf("%s%n", json);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        adminExt.shutdown();
    }
}
 
Example 33
Project: hadoop   File: LogsCLI.java   Source Code and License 5 votes vote down vote up
private void printHelpMessage(Options options) {
  System.out.println("Retrieve logs for completed YARN applications.");
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("yarn logs -applicationId <application ID> [OPTIONS]", new Options());
  formatter.setSyntaxPrefix("");
  formatter.printHelp("general options are:", options);
}
 
Example 34
Project: powsybl-core   File: MpiToolUtil.java   Source Code and License 5 votes vote down vote up
public static Options createMpiOptions() {
    Options options = new Options();
    options.addOption(Option.builder()
            .longOpt(TMP_DIR)
            .desc("local temporary directory")
            .hasArg()
            .argName("dir")
            .build());
    options.addOption(Option.builder()
            .longOpt(STATISTICS_DB_DIR)
            .desc("statistics db directory")
            .hasArg()
            .argName("dir")
            .build());
    options.addOption(Option.builder()
            .longOpt(STATISTICS_DB_NAME)
            .desc("statistics db name")
            .hasArg()
            .argName("name")
            .build());
    options.addOption(Option.builder()
            .longOpt(CORES)
            .desc("number of cores per rank")
            .hasArg()
            .required()
            .argName("n")
            .build());
    options.addOption(Option.builder()
            .longOpt(VERBOSE)
            .desc("verbose mode")
            .build());
    options.addOption(Option.builder()
            .longOpt(STDOUT_ARCHIVE)
            .desc("tasks standard output archive")
            .hasArg()
            .argName("file")
            .build());
    return options;
}
 
Example 35
Project: cyberduck   File: CommandLinePathParserTest.java   Source Code and License 5 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;
        }
    })
    ));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory)),
            new CommandLinePathParser(input, factory).parse("ftps://[email protected]/"));
    assertEquals(new Path("/d", EnumSet.of(Path.Type.directory)),
            new CommandLinePathParser(input, factory).parse("ftps://[email protected]/d/"));
    assertEquals(new Path("/d", EnumSet.of(Path.Type.file)),
            new CommandLinePathParser(input, factory).parse("ftps://[email protected]/d"));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory)),
            new CommandLinePathParser(input, factory).parse("ftps://[email protected]/"));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory)),
            new CommandLinePathParser(input, factory).parse("ftps://[email protected]"));

    assertEquals(new Path("/test.cyberduck.ch", EnumSet.of(Path.Type.directory)),
            new CommandLinePathParser(input, factory).parse("s3://[email protected]/"));
    assertEquals(new Path("/test.cyberduck.ch/d", EnumSet.of(Path.Type.directory)),
            new CommandLinePathParser(input, factory).parse("s3://[email protected]/d/"));
    assertEquals(new Path("/test.cyberduck.ch/d", EnumSet.of(Path.Type.file)),
            new CommandLinePathParser(input, factory).parse("s3://[email protected]/d"));
}
 
Example 36
Project: reading-and-annotate-rocketmq-3.4.6   File: ConsumerProgressSubCommand.java   Source Code and License 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "groupName", true, "consumer group name");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}
 
Example 37
Project: appdomain   File: MainApp.java   Source Code and License 5 votes vote down vote up
/**
 * 
 * @param options
 * @param message
 */
protected static void printHelp(Options options,String message) {
	if (message!=null) System.out.println(message);
	System.out.println(title);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp( MainApp.class.getName(), options );
    System.out.println("Examples:");
    System.out.println(example_demo_fp());
    System.out.println(example_demo_density());
    System.out.println(example_density());
    
    
    Runtime.getRuntime().runFinalization();						 
	Runtime.getRuntime().exit(0);	
}
 
Example 38
Project: ditb   File: RESTServer.java   Source Code and License 5 votes vote down vote up
private static void printUsageAndExit(Options options, int exitCode) {
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("bin/hbase rest start", "", options,
    "\nTo run the REST server as a daemon, execute " +
    "bin/hbase-daemon.sh start|stop rest [--infoport <port>] [-p <port>] [-ro]\n", true);
  System.exit(exitCode);
}
 
Example 39
Project: rmq4note   File: DeleteTopicSubCommandTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testExecute() {
    DeleteTopicSubCommand cmd = new DeleteTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue("c").trim()).isEqualTo("default-cluster");
}
 
Example 40
Project: solr-upgrade-tool   File: ConfigUpgradeTool.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private static void printHelp(Options options) {
  StringBuilder helpFooter = new StringBuilder();
  helpFooter.append("Examples: \n");
  helpFooter.append("config_upgrade.sh -c schema.xml -t schema -u solr_4_to_5_processors.xml -d /tmp/result-dir \n");
  helpFooter.append("config_upgrade.sh --dry-run -c schema.xml -t schema -u solr_4_to_5_processors.xml -d /tmp/result-dir \n");

  HelpFormatter formatter = new HelpFormatter();
  formatter.setOptionComparator(new OptionComarator());
  formatter.printHelp("ConfigUpgradeTool", null, options, helpFooter.toString(), false);
}