use of org.apache.commons.cli.Option in project moco by dreamhead.
the class StartArgsParser method envOption.
protected Option envOption() {
Option opt = new Option("e", true, "environment");
opt.setType(String.class);
opt.setRequired(false);
return opt;
}
use of org.apache.commons.cli.Option in project moco by dreamhead.
the class StartArgsParser method portOption.
protected Option portOption() {
Option opt = new Option("p", true, "port");
opt.setType(Number.class);
opt.setRequired(false);
return opt;
}
use of org.apache.commons.cli.Option in project jmxtrans by jmxtrans.
the class CommonsCliArgumentParser method parseOptions.
/** Parse the options given on the command line. */
@Nonnull
@Override
public JmxTransConfiguration parseOptions(@Nonnull String[] args) throws OptionsException, org.apache.commons.cli.ParseException {
CommandLineParser parser = new GnuParser();
CommandLine cl = parser.parse(getOptions(), args);
Option[] options = cl.getOptions();
JmxTransConfiguration configuration = new JmxTransConfiguration();
for (Option option : options) {
if (option.getOpt().equals("c")) {
configuration.setContinueOnJsonError(Boolean.parseBoolean(option.getValue()));
} else if (option.getOpt().equals("j")) {
File jsonDir = new File(option.getValue());
if (jsonDir.exists() && jsonDir.isDirectory()) {
configuration.setJsonDir(jsonDir);
} else {
throw new OptionsException("Path to json directory is invalid: " + jsonDir);
}
} else if (option.getOpt().equals("f")) {
File jsonFile = new File(option.getValue());
if (jsonFile.exists() && jsonFile.isFile()) {
configuration.setJsonFile(jsonFile);
} else {
throw new OptionsException("Path to json file is invalid: " + jsonFile);
}
} else if (option.getOpt().equals("e")) {
configuration.setRunEndlessly(true);
} else if (option.getOpt().equals("q")) {
File quartzConfigFile = new File(option.getValue());
if (quartzConfigFile.exists() && quartzConfigFile.isFile()) {
configuration.setQuartzPropertiesFile(quartzConfigFile);
} else {
throw new OptionsException("Could not find path to the quartz properties file: " + quartzConfigFile.getAbsolutePath());
}
} else if (option.getOpt().equals("s")) {
try {
configuration.setRunPeriod(Integer.parseInt(option.getValue()));
} catch (NumberFormatException nfe) {
throw new OptionsException("Seconds between server job runs must be an integer");
}
} else if (option.getOpt().equals("a")) {
configuration.setAdditionalJars(option.getValuesList());
} else if (option.getOpt().equals("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar jmxtrans-all.jar", getOptions());
configuration.setHelp(true);
}
}
if ((!configuration.isHelp()) && (configuration.getJsonDirOrFile() == null)) {
throw new OptionsException("Please specify either the -f or -j option.");
}
return configuration;
}
use of org.apache.commons.cli.Option in project languagetool by languagetool-org.
the class BuilderOptions method addOption.
public void addOption(String opt, boolean hasArg, String description, boolean isRequired) {
Option option = new Option(opt, hasArg, description);
option.setRequired(isRequired);
options.addOption(option);
}
use of org.apache.commons.cli.Option in project databus by linkedin.
the class BootstrapDropSource method parseArgs.
@SuppressWarnings("static-access")
public static int parseArgs(String[] args) throws IOException {
CommandLineParser cliParser = new GnuParser();
Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen").create(HELP_OPT_CHAR);
Option sourceIdOption = OptionBuilder.withLongOpt(SOURCE_ID_OPT_LONG_NAME).withDescription("Source ID for which tables need to be dropped").hasArg().withArgName("Source ID").create(SOURCE_ID_OPT_CHAR);
Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
Option cmdLinePropsOption = OptionBuilder.withLongOpt(CMD_LINE_PROPS_OPT_LONG_NAME).withDescription("Cmd line override of config properties. Semicolon separated.").hasArg().withArgName("Semicolon_separated_properties").create(CMD_LINE_PROPS_OPT_CHAR);
Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME).withDescription("Log4j properties to use").hasArg().withArgName("property_file").create(LOG4J_PROPS_OPT_CHAR);
Options options = new Options();
options.addOption(helpOption);
options.addOption(sourceIdOption);
options.addOption(dbOption);
options.addOption(cmdLinePropsOption);
options.addOption(log4jPropsOption);
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
LOG.error("Bootstrap Physical Config: failed to parse command-line options.", pe);
throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
}
if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
PropertyConfigurator.configure(log4jPropFile);
LOG.info("Using custom logging settings from file " + log4jPropFile);
} else {
PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(defaultAppender);
LOG.info("Using default logging settings");
}
if (cmd.hasOption(HELP_OPT_CHAR)) {
printCliHelp(options);
System.exit(0);
}
if (!cmd.hasOption(SOURCE_ID_OPT_CHAR))
throw new RuntimeException("Source ID is not provided");
if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
throw new RuntimeException("Bootstrap config is not provided");
String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile);
_sBootstrapConfigProps = new Properties();
FileInputStream f = new FileInputStream(propFile);
try {
_sBootstrapConfigProps.load(f);
} finally {
f.close();
}
if (cmd.hasOption(CMD_LINE_PROPS_OPT_CHAR)) {
String cmdLinePropString = cmd.getOptionValue(CMD_LINE_PROPS_OPT_CHAR);
updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
}
return Integer.parseInt(cmd.getOptionValue(SOURCE_ID_OPT_CHAR));
}
Aggregations