use of org.apache.commons.cli.DefaultParser in project flink by apache.
the class CliFrontendParser method parseCancelCommand.
public static CancelOptions parseCancelCommand(String[] args) throws CliArgsException {
try {
DefaultParser parser = new DefaultParser();
CommandLine line = parser.parse(CANCEL_OPTIONS, args, false);
return new CancelOptions(line);
} catch (ParseException e) {
throw new CliArgsException(e.getMessage());
}
}
use of org.apache.commons.cli.DefaultParser in project flink by apache.
the class CliFrontendParser method parseInfoCommand.
public static InfoOptions parseInfoCommand(String[] args) throws CliArgsException {
try {
DefaultParser parser = new DefaultParser();
CommandLine line = parser.parse(INFO_OPTIONS, args, true);
return new InfoOptions(line);
} catch (ParseException e) {
throw new CliArgsException(e.getMessage());
}
}
use of org.apache.commons.cli.DefaultParser in project hbase by apache.
the class AbstractHBaseTool method run.
@Override
public int run(String[] args) throws IOException {
cmdLineArgs = args;
if (conf == null) {
LOG.error("Tool configuration is not initialized");
throw new NullPointerException("conf");
}
CommandLine cmd;
List<String> argsList = new ArrayList<>(args.length);
for (String arg : args) {
argsList.add(arg);
}
// For backward compatibility of args which can't be parsed as Option. See javadoc for
// processOldArgs(..)
processOldArgs(argsList);
try {
addOptions();
if (isHelpCommand(args)) {
printUsage();
return EXIT_SUCCESS;
}
String[] remainingArgs = new String[argsList.size()];
argsList.toArray(remainingArgs);
cmd = new DefaultParser().parse(options, remainingArgs);
} catch (MissingOptionException e) {
LOG.error(e.getMessage());
LOG.error("Use -h or --help for usage instructions.");
return EXIT_FAILURE;
} catch (ParseException e) {
LOG.error("Error when parsing command-line arguments", e);
LOG.error("Use -h or --help for usage instructions.");
return EXIT_FAILURE;
}
processOptions(cmd);
int ret;
try {
ret = doWork();
} catch (Exception e) {
LOG.error("Error running command-line tool", e);
return EXIT_FAILURE;
}
return ret;
}
use of org.apache.commons.cli.DefaultParser in project hbase by apache.
the class AbstractHBaseTool method isHelpCommand.
private boolean isHelpCommand(String[] args) throws ParseException {
Options helpOption = new Options().addOption(HELP_OPTION);
// this parses the command line but doesn't throw an exception on unknown options
CommandLine cl = new DefaultParser().parse(helpOption, args, true);
return cl.getOptions().length != 0;
}
use of org.apache.commons.cli.DefaultParser in project heron by twitter.
the class JavaCheckstyle method main.
public static void main(String[] args) throws IOException {
CommandLineParser parser = new DefaultParser();
// create the Options
Options options = new Options();
options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file").desc("bazel extra action protobuf file").build());
options.addOption(Option.builder("hc").required(true).hasArg().longOpt("heron_checkstyle_config_file").desc("checkstyle config file").build());
options.addOption(Option.builder("ac").required(true).hasArg().longOpt("apache_checkstyle_config_file").desc("checkstyle config file for imported source files").build());
try {
// parse the command line arguments
CommandLine line = parser.parse(options, args);
String extraActionFile = line.getOptionValue("f");
String configFile = line.getOptionValue("hc");
String apacheConfigFile = line.getOptionValue("ac");
// check heron source file style
String[] heronSourceFiles = getHeronSourceFiles(extraActionFile);
checkStyle(heronSourceFiles, configFile);
// check other apache source file style
String[] apacheSourceFiles = getApacheSourceFiles(extraActionFile);
checkStyle(apacheSourceFiles, apacheConfigFile);
} catch (ParseException exp) {
LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java " + CLASSNAME, options);
}
}
Aggregations