public static void main(final String[] args) throws Exception { final OptionParser parser = new OptionParser(); final OptionSpec<String> scriptDirectory = parser .acceptsAll(Arrays.asList("s", "script"), "Directory of update scripts.").withRequiredArg() .describedAs("script").ofType(String.class); final OptionSpec<Void> updateOption = parser.acceptsAll(Arrays.asList("u", "update"), "Will update if necessary"); final Props props = AzkabanServer.loadProps(args, parser); if (props == null) { logger.error("Properties not found. Need it to connect to the db."); logger.error("Exiting..."); return; } final OptionSet options = parser.parse(args); boolean updateDB = false; if (options.has(updateOption)) { updateDB = true; } else { logger.info("Running DatabaseUpdater in test mode"); } String scriptDir = "sql"; if (options.has(scriptDirectory)) { scriptDir = options.valueOf(scriptDirectory); } runDatabaseUpdater(props, scriptDir, updateDB); }
List<String> args) throws Exception { OptionParser p = new OptionParser(); OptionSpec<String> keyOption = p.accepts("key", "Metadata key") .withOptionalArg() .ofType(String.class); OptionSet opts = p.parse(args.toArray(new String[0])); String keyName = keyOption.value(opts); List<String> nargs = (List<String>)opts.nonOptionArguments(); if (nargs.size() != 1) { err.println("Expected 1 arg: input_file");
final OptionParser parser = new OptionParser(); parser.accepts("developer-mode", "Enable developer tools"); parser.accepts("debug", "Show extra debugging output"); .accepts("rs", "Select client type") .withRequiredArg() .ofType(ClientUpdateCheckMode.class) .defaultsTo(ClientUpdateCheckMode.AUTO) .withValuesConvertedBy(new EnumConverter<ClientUpdateCheckMode>(ClientUpdateCheckMode.class) parser.accepts("help", "Show this text").forHelp(); OptionSet options = parser.parse(args); if (options.has("help")) parser.printHelpOn(System.out); final boolean developerMode = options.has("developer-mode"); if (options.has("debug"))
private static OptionParser setupParser() { OptionParser parser = new OptionParser(); parser.accepts("help", "Print usage information").withOptionalArg(); parser.acceptsAll(Arrays.asList("id", "nodeId"), "expected node Id") .withRequiredArg() .describedAs("expected node Id") .ofType(String.class); parser.acceptsAll(Arrays.asList("path", "clusterPath"), "clusterPath") .withRequiredArg() .describedAs("clusterPath") .ofType(String.class); return parser; }
parser.acceptsAll(Arrays.asList("help", "?", "h"), "shows this help").forHelp(); parser.acceptsAll(Arrays.asList("n", "iteration"), "vjtop will exit after n output iterations (defaults to unlimit)").withRequiredArg() .ofType(Integer.class); parser.acceptsAll(Arrays.asList("i", "interval", "d"), "interval between each output iteration (defaults to 10s)").withRequiredArg().ofType(Integer.class); parser.acceptsAll(Arrays.asList("w", "width"), "Number of columns for the console display (defaults to 100)") .withRequiredArg().ofType(Integer.class); parser.acceptsAll(Arrays.asList("l", "limit"), "Number of threads to display ( default to 10 threads)") .withRequiredArg().ofType(Integer.class); parser.acceptsAll(Arrays.asList("f", "filter"), "Thread name filter ( no default)").withRequiredArg() .ofType(String.class); parser.acceptsAll(Arrays.asList("j", "jmxurl"), "give JMX url like 127.0.0.1:7001 when VM attach doesn't work") .withRequiredArg().ofType(String.class); + " memory: display thread memory allocated and sort by delta\n" + " totalmemory: display thread memory allocated and sort by total") .withRequiredArg().ofType(String.class); + " clean: console without warning and flush ansi code\n" + " text: plain text like /proc/status for 3rd tools\n") .withRequiredArg().ofType(String.class); parser.acceptsAll(Arrays.asList("c", "content"), "output content: \n" + " all(default): jvm info and theads info\n jvm: only jvm info\n thread: only thread info\n") .withRequiredArg().ofType(String.class);
protected OptionParser buildOptionParser() { OptionParser parser = new OptionParser(); parser.accepts( "config", "location of config file" ).withRequiredArg(); parser.accepts( "__separator_1", "" ); parser.accepts( "database", "database that contains the table to bootstrap").withRequiredArg(); parser.accepts( "table", "table to bootstrap").withRequiredArg(); parser.accepts( "where", "where clause to restrict the rows bootstrapped from the specified table. e.g. my_date >= '2017-01-01 11:07:13'").withOptionalArg(); parser.accepts( "__separator_2", "" ); parser.accepts( "abort", "bootstrap_id to abort" ).withRequiredArg(); parser.accepts( "monitor", "bootstrap_id to monitor" ).withRequiredArg(); parser.accepts( "__separator_3", "" ); parser.accepts( "client_id", "maxwell client to perform the bootstrap" ).withRequiredArg(); parser.accepts( "log_level", "log level, one of DEBUG|INFO|WARN|ERROR. default: WARN" ).withRequiredArg(); parser.accepts( "host", "mysql host. default: localhost").withRequiredArg(); parser.accepts( "user", "mysql username. default: maxwell" ).withRequiredArg(); parser.accepts( "password", "mysql password" ).withRequiredArg(); parser.accepts( "port", "mysql port. default: 3306" ).withRequiredArg(); parser.accepts( "schema_database", "database that contains maxwell schema and state").withRequiredArg(); parser.accepts( "help", "display help").forHelp(); BuiltinHelpFormatter helpFormatter = new BuiltinHelpFormatter(200, 4) { @Override public String format(Map<String, ? extends OptionDescriptor> options) { this.addRows(options.values()); String output = this.formattedHelpOutput(); return output.replaceAll("--__separator_.*", ""); } }; parser.formatHelpWith(helpFormatter); return parser; }
@Test public void withMissingOption() { OptionParser parser = new OptionParser(); parser.accepts("foo").withRequiredArg().withValuesSeparatedBy(','); OptionSet options = parser.parse(); // <-- no options whatsoever PropertySource<?> ps = new JOptCommandLinePropertySource(options); assertThat(ps.getProperty("foo"), nullValue()); }
public static void main(String[] args) throws Exception { OptionParser parser = new OptionParser(); parser.accepts("help", "print usage information"); parser.accepts("cluster", "[REQUIRED] the voldemort cluster.xml file ") .withRequiredArg() .describedAs("cluster.xml"); parser.accepts("name", "[REQUIRED] the name of the store to swap") .withRequiredArg() .describedAs("store-name"); parser.accepts("file", "[REQUIRED] uri of a directory containing the new store files") .withRequiredArg() .describedAs("uri"); parser.accepts("timeout", "http timeout for the fetch in ms") .withRequiredArg() .describedAs("timeout ms") .ofType(Integer.class); parser.accepts("rollback", "Rollback store to older version"); parser.accepts("push-version", "[REQUIRED] Version of push to fetch / rollback-to") .withRequiredArg() .ofType(Long.class); if(!(missing.equals(ImmutableSet.of("file")) && (options.has("rollback")))) { System.err.println("Missing required arguments: " + Joiner.on(", ").join(missing)); parser.printHelpOn(System.err); String clusterXml = (String) options.valueOf("cluster"); String storeName = (String) options.valueOf("name"); String filePath = (String) options.valueOf("file");
/** * Adds OPT_S | OPT_STORE option to OptionParser, with one argument. * * @param parser OptionParser to be modified * @param required Tells if this option is required or optional */ public static void acceptsStoreSingle(OptionParser parser) { parser.acceptsAll(Arrays.asList(OPT_S, OPT_STORE), "store name") .withRequiredArg() .describedAs("store-name") .ofType(String.class); }
public static void main(String... args) throws Exception { final OptionParser parser = new OptionParser(); final OptionSpec<Void> help = parser.accepts("help").forHelp(); final OptionSpec<Double> wgsLongitudeOpt = parser.acceptsAll(Arrays.asList("longitude")) .withRequiredArg().ofType(Double.class).required().describedAs("The WGS Longitude"); final OptionSpec<Double> wgsLatitudeOpt = parser.acceptsAll(Arrays.asList("latitude")) .withRequiredArg().ofType(Double.class).required().describedAs("The WGS Latitude"); OptionSet options = null; try { options = parser.parse(args); } catch (final OptionException e) { System.out.println(e.getMessage()); parser.printHelpOn(System.out); throw e; } if (options.has(help)) { parser.printHelpOn(System.out); return; } UTM fromWGS = UTM.fromWGS84(wgsLatitudeOpt.value(options), wgsLongitudeOpt.value(options)); System.out.println(fromWGS.toString()); } }
private static OptionParser getOptionParser(Class<?> clazz) { final OptionParser parser = new OptionParser(); for (Field field : clazz.getDeclaredFields()) { if (field.isAnnotationPresent(NamedArg.class)) { final NamedArg arg = field.getAnnotation(NamedArg.class); final OptionSpecBuilder osb = parser.accepts(arg.name(), arg.summary()); if (arg.hasValue()) { final boolean isCollection = field.getType().isAssignableFrom(Collection.class); if (isCollection) { osb.withOptionalArg(); } else { osb.withOptionalArg().ofType(field.getType()); } } } } return parser; }
"apollo cli args"); final OptionParser parser = new OptionParser(); if (cliHelp) { helpOption = parser.acceptsAll(ImmutableList.of("help", "h"), "Shows this help.").forHelp(); } else { helpOption = null; "Set configuration key with '-Dkey=value'. Supports Typesafe Config syntax, i.e. " + "'-Dhosts+=foo.${domain}'.") .withRequiredArg(); final OptionSpec<Boolean> syslogOption = parser.accepts( "Log to syslog (Alias for '-D%s=<value>').", CommonConfigKeys.LOGGING_SYSLOG.getKey())) .withOptionalArg().ofType(Boolean.class); final OptionSpec<Void> verboseOption = parser.acceptsAll( "Load configuration from the specified file. The values from the file will be " + "overlayed on top of any already loaded configuration.") .withRequiredArg(); if (helpOption != null && parsed.has(helpOption)) {
@SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { OptionParser parser = new OptionParser(); parser.accepts("k", "key size").withRequiredArg().ofType(Integer.class); parser.accepts("v", "value size").withRequiredArg().ofType(Integer.class); parser.accepts("p", "prefix").withRequiredArg(); OptionSet options = parser.parse(args); List<String> nonOptions = (List<String>) options.nonOptionArguments(); if(nonOptions.size() != 3) { printUsage(System.err, parser); } String url = nonOptions.get(0); String storeName = nonOptions.get(1); int requests = Integer.parseInt(nonOptions.get(2)); int keySize = CmdUtils.valueOf(options, "k", 128); int valueSize = CmdUtils.valueOf(options, "v", 256); int workers = CmdUtils.valueOf(options, "threads", MAX_WORKERS); String postfix = (String) (options.has("p") ? options.valueOf("p") : null); RemoteDataGenerator rdg = new RemoteDataGenerator(url, storeName, workers); rdg.generateData(requests, keySize, valueSize, postfix); } }
private Configure analyzeConfigure(String[] args) { final OptionParser parser = new OptionParser(); parser.accepts("pid").withRequiredArg().ofType(int.class).required(); parser.accepts("target").withOptionalArg().ofType(String.class); parser.accepts("multi").withOptionalArg().ofType(int.class); parser.accepts("core").withOptionalArg().ofType(String.class); parser.accepts("agent").withOptionalArg().ofType(String.class); final OptionSet os = parser.parse(args); final Configure configure = new Configure(); if (os.has("target")) { final String[] strSplit = ((String) os.valueOf("target")).split(":"); configure.setTargetIp(strSplit[0]); configure.setTargetPort(Integer.valueOf(strSplit[1])); } configure.setJavaPid((Integer) os.valueOf("pid")); configure.setGreysAgent((String) os.valueOf("agent")); configure.setGreysCore((String) os.valueOf("core")); return configure; }
public static void main(final String... args) throws IOException, ProcessingException final OptionParser parser = new OptionParser(); parser.accepts("help", "show this help").forHelp(); parser.acceptsAll(Arrays.asList("s", "brief"), "only show validation status (OK/NOT OK)"); parser.acceptsAll(Arrays.asList("q", "quiet"), parser.accepts("fakeroot", "pretend that the current directory is absolute URI \"uri\"") .withRequiredArg(); parser.formatHelpWith(HELP); if (optionSet.has("help")) { parser.printHelpOn(System.out); System.exit(ALL_OK.get()); if (optionSet.has("s") && optionSet.has("q")) { System.err.println("cannot specify both \"--brief\" and " + "\"--quiet\"");
@Override public UpdateOperationOptions parseOptions(String[] operationArgs) throws Exception { UpdateOperationOptions operationOptions = new UpdateOperationOptions(); OptionParser parser = new OptionParser(); OptionSpec<Void> optionSnapshots = parser.acceptsAll(asList("s", "snapshot", "snapshots")); OptionSpec<String> optionApiEndpoint = parser.acceptsAll(asList("a", "api-endpoint")).withRequiredArg(); OptionSet options = parser.parse(operationArgs); // Action List<?> nonOptionArgs = options.nonOptionArguments(); if (nonOptionArgs.size() == 0) { throw new Exception("Invalid syntax, please specify an action (check)."); } // <action> String actionStr = nonOptionArgs.get(0).toString(); UpdateOperationAction action = parseAction(actionStr); operationOptions.setAction(action); // --snapshots operationOptions.setSnapshots(options.has(optionSnapshots)); // --api-endpoint if (options.has(optionApiEndpoint)) { operationOptions.setApiEndpoint(options.valueOf(optionApiEndpoint)); } return operationOptions; }
public void run(String[] args) throws Exception { OptionParser parser = new OptionParser(); parser.formatHelpWith(new OptionFormatter(label())); OptionSpec<String> optClassPath = parser.accepts("cp", "Additional classpath entries, where to look for the referenced classes.") .withRequiredArg().ofType(String.class).describedAs("classpath").withValuesSeparatedBy(getProperty("path.separator")); OptionSpec<String> optClasses = parser.nonOptions("Class names to work on."); try { OptionSet set = parser.parse(args); classes = set.valuesOf(optClasses); if (classes.isEmpty()) { System.err.println("Need class name(s) as the arguments."); if (set.has(optClassPath)) { ClassUtils.addClasspathEntries(optClassPath.values(set));
private static OptionSet parseArguments(final String[] args) throws IOException { final OptionParser optionParser = new OptionParser(); optionParser.accepts(PEER_NAME_PARAMETER).withRequiredArg().ofType(String.class).describedAs("peer name"); optionParser.accepts(BIND_PORT_PARAMETER).withRequiredArg().ofType(Integer.class).describedAs("port to bind"); optionParser.accepts(CONFIG_FILE_PARAMETER).withOptionalArg().ofType(File.class).describedAs("config properties file"); optionParser.accepts(HELP_PARAMETER).forHelp(); final OptionSet options = optionParser.parse(args); if (options.has(HELP_PARAMETER)) { optionParser.printHelpOn(System.out); } if (!options.has(PEER_NAME_PARAMETER) || !options.has(BIND_PORT_PARAMETER)) { if (!options.has(HELP_PARAMETER)) { optionParser.printHelpOn(System.out); } LOGGER.error("Missing arguments!!"); System.exit(-1); } return options; }
public static void main(String[] args) throws IOException, SentenceAnnotatorLoadException, TalismaneException, ReflectiveOperationException { OptionParser parser = new OptionParser(); parser.accepts("serializeLexicon", "serialize lexicon"); parser.acceptsAll(Arrays.asList("?", "help"), "show help").availableUnless("serializeLexicon").forHelp(); OptionSpec<String> sessionIdOption = parser.accepts("sessionId", "the current session id - configuration read as talismane.core.[sessionId]") .requiredUnless("?", "help").withRequiredArg().ofType(String.class); OptionSpec<File> lexiconPropsFileOption = parser.accepts("lexiconProps", "the lexicon properties file").withRequiredArg().required().ofType(File.class); OptionSpec<File> outFileOption = parser.accepts("outFile", "where to write the lexicon").withRequiredArg().required().ofType(File.class); if (args.length <= 1) { parser.printHelpOn(System.out); return; } OptionSet options = parser.parse(args); File lexiconPropsFile = options.valueOf(lexiconPropsFileOption); File outFile = options.valueOf(outFileOption); Config config = ConfigFactory.load(); String sessionId = options.valueOf(sessionIdOption); TalismaneSession session = new TalismaneSession(config, sessionId); LexiconReader lexiconSerializer = new LexiconReader(session); List<PosTaggerLexicon> lexicons = lexiconSerializer.readLexicons(lexiconPropsFile); lexiconSerializer.serializeLexicons(lexicons, outFile); }
ProxyOptions(final String[] args) { final OptionParser parser = new OptionParser(); final OptionSpec<Void> help = parser.acceptsAll(Arrays.asList("h", "help"), "Print help") .forHelp(); final OptionSpec<Integer> port = parser.acceptsAll(Arrays.asList("p", "port"), "Specify the bind port to be used. The configuration bind port will be ignored.") .withRequiredArg().ofType(Integer.class); final OptionSet set = parser.parse(args); this.help = set.has(help); this.port = port.value(set); if (this.help) { try { parser.printHelpOn(System.out); } catch (final IOException e) { logger.error("Could not print help", e); } } }