org.apache.commons.cli.Options Java Examples
The following examples show how to use
org.apache.commons.cli.Options.
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
Source File: QueryMsgByKeySubCommand.java From rocketmq with Apache License 2.0 | 6 votes |
@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 #2
Source File: StorageCleanupJob.java From Kylin with Apache License 2.0 | 6 votes |
@Override public int run(String[] args) throws Exception { Options options = new Options(); log.info("----- jobs args: " + Arrays.toString(args)); try { options.addOption(OPTION_DELETE); parseOptions(options, args); log.info("options: '" + getOptionsAsString() + "'"); log.info("delete option value: '" + getOptionValue(OPTION_DELETE) + "'"); delete = Boolean.parseBoolean(getOptionValue(OPTION_DELETE)); Configuration conf = HBaseConfiguration.create(getConf()); cleanUnusedHdfsFiles(conf); cleanUnusedHBaseTables(conf); cleanUnusedIntermediateHiveTable(conf); return 0; } catch (Exception e) { e.printStackTrace(System.err); throw e; } }
Example #3
Source File: TopicClusterSubCommand.java From rocketmq-read with Apache License 2.0 | 6 votes |
@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())); 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) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example #4
Source File: ScheduleGenerator.java From core with GNU General Public License v3.0 | 6 votes |
/** * Displays the command line options on stdout * * @param options */ private static void displayCommandLineOptions(Options options) { // Display help final String commandLineSyntax = "java transitime.jar"; final PrintWriter writer = new PrintWriter(System.out); final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(writer, 80, // printedRowWidth commandLineSyntax, "args:", // header options, 2, // spacesBeforeOption 2, // spacesBeforeOptionDescription null, // footer true); // displayUsage writer.write("Also need to set VM parameters: \n" + " -Dtransitime.core.agencyId=<agencyId>\n"); writer.close(); }
Example #5
Source File: Main.java From james-project with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Options options = buildOptions(); try { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); runCommand(cmd); } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp("mpt", options); System.exit(-1); } }
Example #6
Source File: DeleteTopicSubCommand.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { 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) { e.printStackTrace(); } finally { adminExt.shutdown(); } }
Example #7
Source File: GenericOptionsParser.java From jstorm with Apache License 2.0 | 6 votes |
static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option libjars = OptionBuilder.withArgName("paths").hasArg().withDescription("comma separated jars to be used by the submitted topology").create("libjars"); r.addOption(libjars); optionProcessors.put("libjars", new LibjarsProcessor()); Option conf = OptionBuilder.withArgName("configuration file").hasArg().withDescription("an application configuration file").create("conf"); r.addOption(conf); optionProcessors.put("conf", new ConfFileProcessor()); // Must come after `conf': this option is of higher priority Option extraConfig = OptionBuilder.withArgName("D").hasArg().withDescription("extra configurations (preserving types)").create("D"); r.addOption(extraConfig); optionProcessors.put("D", new ExtraConfigProcessor()); return r; }
Example #8
Source File: ZooKeeperCli.java From waltz with Apache License 2.0 | 6 votes |
@Override protected void configureOptions(Options options) { Option nameOption = Option.builder("n") .longOpt("name") .desc("Specify the name of the Waltz cluster") .hasArg() .build(); Option forceOption = Option.builder("f") .longOpt("force") .desc("Delete cluster even if cluster names don't match") .hasArg(false) .build(); Option cliCfgOption = Option.builder("c") .longOpt("cli-config-path") .desc("Specify the cli config file path required for ZooKeeper connection string, ZooKeeper root path") .hasArg() .build(); cliCfgOption.setRequired(true); nameOption.setRequired(true); forceOption.setRequired(false); options.addOption(cliCfgOption); options.addOption(nameOption); options.addOption(forceOption); }
Example #9
Source File: UpdateGroups.java From ade with GNU General Public License v3.0 | 6 votes |
/** * Parses the arguments. The valid arguments are: * --help or -h : prints out help message for this main class. * --json or -j : the JSON file. * @param args the arguments passed in as options. */ @Override public void parseArgs(String [] args) throws AdeUsageException{ Options options = new Options(); buildOptions(options); CommandLineParser parser = new GnuParser(); CommandLine line = parseLine(parser,options,args); if (line.hasOption('h')) { new HelpFormatter().printHelp(this.getClass().getSimpleName(), options); System.exit(0); } if (line.hasOption('j')){ String jsonFile = line.getOptionValue("j"); inputJSONFile = new File(jsonFile); validateFile(inputJSONFile); } else{ new HelpFormatter().printHelp(this.getClass().getSimpleName(), options); throw new AdeUsageException("Must specify a JSON file path using the -j option."); } }
Example #10
Source File: DeleteTopicSubCommand.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
@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
Source File: QueryMsgByUniqueKeySubCommand.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { defaultMQAdminExt.start(); final String msgId = commandLine.getOptionValue('i').trim(); final String topic = commandLine.getOptionValue('t').trim(); if (commandLine.hasOption('g') && commandLine.hasOption('d')) { final String consumerGroup = commandLine.getOptionValue('g').trim(); final String clientId = commandLine.getOptionValue('d').trim(); ConsumeMessageDirectlyResult result = defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, topic, msgId); System.out.printf("%s", result); } else { queryById(defaultMQAdminExt, topic, msgId); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example #12
Source File: TopicRouteSubCommandTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testExecute() { TopicRouteSubCommand cmd = new TopicRouteSubCommand(); Options options = ServerUtil.buildCommandlineOptions(new Options()); String[] subargs = new String[] {"-t unit-test"}; final CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test"); }
Example #13
Source File: ResetOffsetByTimeCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { System.setProperty(MixAll.NAMESRV_ADDR_PROPERTY, "127.0.0.1:9876"); ResetOffsetByTimeCommand cmd = new ResetOffsetByTimeCommand(); Options options = ServerUtil.buildCommandlineOptions(new Options()); String[] subargs = new String[] { "-t qatest_TopicTest", "-g qatest_consumer", "-s 1389098416742", "-f true" }; final CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); cmd.execute(commandLine, options, null); }
Example #14
Source File: CleanExpiredCQSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
@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.println(result ? "success" : "false"); } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example #15
Source File: ConsumerProgressSubCommandTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
@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 #16
Source File: Main.java From swift-t with Apache License 2.0 | 5 votes |
private static void usage(Options opts) { HelpFormatter fmt = new HelpFormatter(); fmt.printHelp("stc", opts, true); System.out.println( "The first filename is the input; it is required.\n" + "The second filename is the output; it is optional.\n" + "Use stc -h for full help."); }
Example #17
Source File: GobblinTaskRunner.java From incubator-gobblin with Apache License 2.0 | 5 votes |
public static Options buildOptions() { Options options = new Options(); options.addOption("a", GobblinClusterConfigurationKeys.APPLICATION_NAME_OPTION_NAME, true, "Application name"); options.addOption("d", GobblinClusterConfigurationKeys.APPLICATION_ID_OPTION_NAME, true, "Application id"); options.addOption("i", GobblinClusterConfigurationKeys.HELIX_INSTANCE_NAME_OPTION_NAME, true, "Helix instance name"); options.addOption(Option.builder("t").longOpt(GobblinClusterConfigurationKeys.HELIX_INSTANCE_TAGS_OPTION_NAME) .hasArg(true).required(false).desc("Helix instance tags").build()); return options; }
Example #18
Source File: FileChannelIntegrityTool.java From mt-flume with Apache License 2.0 | 5 votes |
private boolean parseCommandLineOpts(String[] args) throws ParseException { Options options = new Options(); options .addOption("l", "dataDirs", true, "Comma-separated list of data " + "directories which the tool must verify. This option is mandatory") .addOption("h", "help", false, "Display help"); CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); if(commandLine.hasOption("help")) { new HelpFormatter().printHelp("java -jar fcintegritytool ", options, true); return false; } if(!commandLine.hasOption("dataDirs")) { new HelpFormatter().printHelp("java -jar fcintegritytool ", "", options, "dataDirs is required.", true); return false; } else { String dataDirStr[] = commandLine.getOptionValue("dataDirs").split(","); for(String dataDir : dataDirStr) { File f = new File(dataDir); if(!f.exists()) { throw new FlumeException("Data directory, " + dataDir + " does not " + "exist."); } dataDirs.add(f); } } return true; }
Example #19
Source File: TopicClusterSubCommand.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); opt.setRequired(true); options.addOption(opt); return options; }
Example #20
Source File: ArgParsingHelper.java From triplea with GNU General Public License v3.0 | 5 votes |
/** * Parses the set of input parameters for things that look like "-Pkey=value" and will return the * key/value pairs as a Properties object. */ public static Properties getTripleaProperties(final String... args) { final Options options = getOptions(); final CommandLineParser parser = new DefaultParser(); try { final CommandLine cli = parser.parse(options, args); return cli.getOptionProperties(TRIPLEA_PROPERTY_PREFIX); } catch (final ParseException e) { throw new IllegalArgumentException("Failed to parse args: " + Arrays.toString(args), e); } }
Example #21
Source File: SparkCubingByLayer.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public SparkCubingByLayer() { options = new Options(); options.addOption(OPTION_INPUT_TABLE); options.addOption(OPTION_INPUT_PATH); options.addOption(OPTION_CUBE_NAME); options.addOption(OPTION_SEGMENT_ID); options.addOption(OPTION_META_URL); options.addOption(OPTION_OUTPUT_PATH); }
Example #22
Source File: ConsumerConnectionSubCommandTest.java From DDMQ with Apache License 2.0 | 5 votes |
@Ignore @Test public void testExecute() throws SubCommandException { ConsumerConnectionSubCommand cmd = new ConsumerConnectionSubCommand(); Options options = ServerUtil.buildCommandlineOptions(new Options()); String[] subargs = new String[] {"-g default-consumer-group"}; final CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); cmd.execute(commandLine, options, null); }
Example #23
Source File: Main.java From cassandra-opstools with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, InterruptedException, ParseException { final Options options = new Options(); options.addOption("f", "force", false, "Force auto balance"); options.addOption("d", "dryrun", false, "Dry run"); options.addOption("r", "noresolve", false, "Don't resolve host names"); options.addOption("h", "host", true, "Host to connect to (default: localhost)"); options.addOption("p", "port", true, "Port to connect to (default: 7199)"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); new Main().run(cmd); }
Example #24
Source File: TopicClusterSubCommand.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); opt.setRequired(true); options.addOption(opt); return options; }
Example #25
Source File: ConsumerProgressSubCommandTest.java From DDMQ with Apache License 2.0 | 5 votes |
@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 #26
Source File: DecodeMessageIdCommond.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("i", "messageId", true, "unique message ID"); opt.setRequired(false); options.addOption(opt); return options; }
Example #27
Source File: HiveColumnCardinalityUpdateJob.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public int run(String[] args) throws Exception { Options options = new Options(); try { options.addOption(OPTION_PROJECT); options.addOption(OPTION_TABLE); options.addOption(OPTION_OUTPUT_PATH); parseOptions(options, args); String project = getOptionValue(OPTION_PROJECT); String table = getOptionValue(OPTION_TABLE).toUpperCase(Locale.ROOT); // start job String jobName = JOB_TITLE + getOptionsAsString(); logger.info("Starting: " + jobName); Configuration conf = getConf(); Path output = new Path(getOptionValue(OPTION_OUTPUT_PATH)); updateKylinTableExd(table.toUpperCase(Locale.ROOT), output.toString(), conf, project); return 0; } catch (Exception e) { printUsage(options); throw e; } }
Example #28
Source File: Main.java From parquet-tools with Apache License 2.0 | 5 votes |
public static void mergeOptionsInto(Options opt, Options opts) { if (opts == null) { return; } Collection<Option> all = opts.getOptions(); if (all != null && !all.isEmpty()) { for (Option o : all) { opt.addOption(o); } } }
Example #29
Source File: LoadAmberData.java From hmftools with GNU General Public License v3.0 | 5 votes |
@NotNull private static Options createBasicOptions() { Options options = new Options(); options.addOption(SAMPLE, true, "Tumor sample"); options.addOption(AMBER_DIR, true, "Path to the amber directory"); options.addOption(DB_USER, true, "Database user name"); options.addOption(DB_PASS, true, "Database password"); options.addOption(DB_URL, true, "Database url"); options.addOption(BED_FILE, true, "Location of bed file"); return options; }
Example #30
Source File: Commands.java From devops-cm-client with Apache License 2.0 | 5 votes |
static void handleHelpOption(String commandName, String header, String args, Options options) { String exitCodes = format( " %d The request completed successfully.\n" + " %d The request did not complete successfully and\n" + " no more specific return code as defined below applies.\n" + " %d Wrong credentials.\n" + " %d Intentionally used by --return-code option in order to\n" + " indicate 'false'. Only available for commands providing\n" + " the --return-code option.", ExitException.ExitCodes.OK, ExitException.ExitCodes.GENERIC_FAILURE, ExitException.ExitCodes.NOT_AUTHENTIFICATED, ExitException.ExitCodes.FALSE); String commonOpts; HelpFormatter formatter = new HelpFormatter(); try( StringWriter commonOptions = new StringWriter(); PrintWriter pw = new PrintWriter(commonOptions);) { formatter.printOptions(pw, formatter.getWidth(), Command.addOpts(new Options()), formatter.getLeftPadding(), formatter.getDescPadding()); commonOpts = commonOptions.toString(); } catch(IOException e) { throw new RuntimeException(e); } String footer = format("%nCOMMON OPTIONS:%n%s%nEXIT CODES%n%s", commonOpts, exitCodes); formatter.printHelp( format("<CMD> [COMMON_OPTIONS] %s [SUBCOMMAND_OPTIONS] %s%n%n", commandName, args != null ? args : ""), format("SUBCOMMAND OPTIONS:%n",header), options, footer); }