use of org.apache.commons.cli.MissingArgumentException in project hadoop by apache.
the class NodeInfo method main.
@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {
GenericOptionsParser genericParser = new GenericOptionsParser(args);
String[] remainingArgs = genericParser.getRemainingArgs();
Option conf = OptionBuilder.hasArg().create("conffile");
Option help = OptionBuilder.withLongOpt("help").create('h');
Options opts = new Options().addOption(conf).addOption(help);
CommandLineParser specificParser = new GnuParser();
CommandLine cmd = null;
try {
cmd = specificParser.parse(opts, remainingArgs);
} catch (MissingArgumentException e) {
terminate(1, "No argument specified for -conffile option");
} catch (ParseException e) {
terminate(1, USAGE);
}
if (cmd == null) {
terminate(1, "Failed to parse options");
}
if (cmd.hasOption('h')) {
terminate(0, USAGE);
}
List<File> files = new ArrayList<File>();
if (cmd.hasOption("conffile")) {
String[] values = cmd.getOptionValues("conffile");
for (String value : values) {
File confFile = new File(value);
if (confFile.isFile()) {
files.add(confFile);
} else if (confFile.isDirectory()) {
for (File file : listFiles(confFile)) {
files.add(file);
}
} else {
terminate(1, confFile.getAbsolutePath() + " is neither a file nor directory");
}
}
} else {
String confDirName = System.getenv(HADOOP_CONF_DIR);
if (confDirName == null) {
terminate(1, HADOOP_CONF_DIR + " is not defined");
}
File confDir = new File(confDirName);
if (!confDir.isDirectory()) {
terminate(1, HADOOP_CONF_DIR + " is not a directory");
}
files = Arrays.asList(listFiles(confDir));
}
if (files.isEmpty()) {
terminate(1, "No input file to validate");
}
boolean ok = true;
for (File file : files) {
String path = file.getAbsolutePath();
List<String> errors = checkConf(new FileInputStream(file));
if (errors.isEmpty()) {
System.out.println(path + ": valid");
} else {
ok = false;
System.err.println(path + ":");
for (String error : errors) {
System.err.println("\t" + error);
}
}
}
if (ok) {
System.out.println("OK");
} else {
terminate(1, "Invalid file exists");
}
}
use of org.apache.commons.cli.MissingArgumentException in project jPOS by jpos.
the class Q2 method parseCmdLine.
private void parseCmdLine(String[] args) {
CommandLineParser parser = new DefaultParser();
Options options = new Options();
options.addOption("v", "version", false, "Q2's version");
options.addOption("d", "deploydir", true, "Deployment directory");
options.addOption("r", "recursive", false, "Deploy subdirectories recursively");
options.addOption("h", "help", false, "Usage information");
options.addOption("C", "config", true, "Configuration bundle");
options.addOption("e", "encrypt", true, "Encrypt configuration bundle");
options.addOption("i", "cli", false, "Command Line Interface");
options.addOption("c", "command", true, "Command to execute");
options.addOption("O", "osgi", false, "Start experimental OSGi framework server");
options.addOption("p", "pid-file", true, "Store project's pid");
options.addOption("n", "name", true, "Optional name (defaults to 'Q2')");
options.addOption("s", "ssh", false, "Enable SSH server");
options.addOption("sp", "ssh-port", true, "ssh port (defaults to 2222)");
options.addOption("sa", "ssh-authorized-keys", true, "Path to authorized key file (defaults to 'cfg/authorized_keys')");
options.addOption("su", "ssh-user", true, "ssh user (defaults to 'admin')");
options.addOption("sh", "ssh-host-key-file", true, "ssh host key file, defaults to 'cfg/hostkeys.ser'");
try {
CommandLine line = parser.parse(options, args);
if (line.hasOption("v")) {
displayVersion();
System.exit(0);
}
if (line.hasOption("h")) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("Q2", options);
System.exit(0);
}
if (line.hasOption("c")) {
cli = new CLI(this, line.getOptionValue("c"), line.hasOption("i"));
} else if (line.hasOption("i"))
cli = new CLI(this, null, true);
String dir = DEFAULT_DEPLOY_DIR;
if (line.hasOption("d")) {
dir = line.getOptionValue("d");
} else if (cli != null)
dir = dir + "-" + "cli";
recursive = line.hasOption("r");
this.deployDir = new File(dir);
if (line.hasOption("C"))
deployBundle(new File(line.getOptionValue("C")), false);
if (line.hasOption("e"))
deployBundle(new File(line.getOptionValue("e")), true);
if (line.hasOption("O"))
startOSGI = true;
if (line.hasOption("p"))
pidFile = line.getOptionValue("p");
if (line.hasOption("n"))
name = line.getOptionValue("n");
enableSsh = line.hasOption("s");
sshPort = Integer.parseInt(line.getOptionValue("sp", "2222"));
sshAuthorizedKeys = line.getOptionValue("sa", "cfg/authorized_keys");
sshUser = line.getOptionValue("su", "admin");
sshHostKeyFile = line.getOptionValue("sh", "cfg/hostkeys.ser");
} catch (MissingArgumentException e) {
System.out.println("ERROR: " + e.getMessage());
System.exit(1);
} catch (IllegalAccessError | UnrecognizedOptionException e) {
System.out.println(e.getMessage());
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
use of org.apache.commons.cli.MissingArgumentException in project Angelia-core by Maxopoly.
the class PluginManager method parseOptions.
private Map<String, List<String>> parseOptions(AngeliaPlugin plugin, String[] args) {
CommandLineParser parser = new DefaultParser();
Options options = new Options();
for (Option opt : plugin.getOptions()) {
options.addOption(opt);
}
CommandLine cmd;
try {
cmd = parser.parse(options, args, true);
} catch (MissingArgumentException e) {
Option opt = e.getOption();
connection.getLogger().warn("An incorrect amount of argument(s) was supplied for the option " + opt.getArgName() + ". Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
return null;
} catch (MissingOptionException e) {
List<String> missingOptions = e.getMissingOptions();
StringBuilder sb = new StringBuilder();
for (String opt : missingOptions) {
sb.append(opt + " ");
}
connection.getLogger().warn("The required argument(s) " + sb.toString() + "were not supplied. Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
return null;
} catch (UnrecognizedOptionException e) {
connection.getLogger().warn("The supplied option " + e.getOption() + " could not be recognized. Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
return null;
} catch (ParseException e) {
connection.getLogger().error("An unknown exception occured while trying to parse arguments", e);
return null;
}
Map<String, List<String>> parsedValues = new HashMap<String, List<String>>();
for (Option option : cmd.getOptions()) {
if (option.hasArg()) {
parsedValues.put(option.getOpt(), Arrays.asList(cmd.getOptionValues(option.getOpt())));
} else {
parsedValues.put(option.getOpt(), new LinkedList<String>());
}
}
return parsedValues;
}
use of org.apache.commons.cli.MissingArgumentException in project accumulo by apache.
the class AddSplitsCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
final String tableName = OptUtil.getTableOpt(cl, shellState);
final boolean decode = cl.hasOption(base64Opt.getOpt());
final TreeSet<Text> splits = new TreeSet<>();
if (cl.hasOption(optSplitsFile.getOpt())) {
splits.addAll(ShellUtil.scanFile(cl.getOptionValue(optSplitsFile.getOpt()), decode));
} else {
if (cl.getArgList().isEmpty()) {
throw new MissingArgumentException("No split points specified");
}
for (String s : cl.getArgs()) {
splits.add(new Text(s.getBytes(Shell.CHARSET)));
}
}
if (!shellState.getConnector().tableOperations().exists(tableName)) {
throw new TableNotFoundException(null, tableName, null);
}
shellState.getConnector().tableOperations().addSplits(tableName, splits);
return 0;
}
use of org.apache.commons.cli.MissingArgumentException in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsTransformerMain method run.
/**
***************************************************************************
* {@link Runnable} Interface
***************************************************************************
*/
public void run(String[] args) throws IOException {
if (needsHelp(args)) {
printHelp();
System.exit(0);
}
try {
CommandLine cli = _parser.parse(_options, args, true);
runApplication(cli, args);
} catch (MissingOptionException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (MissingArgumentException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (UnrecognizedOptionException ex) {
System.err.println("Unknown argument: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (AlreadySelectedException ex) {
System.err.println("Argument already selected: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (ParseException ex) {
System.err.println(ex.getMessage());
printHelp();
System.exit(-2);
} catch (TransformSpecificationException ex) {
System.err.println("error with transform line: " + ex.getLine());
System.err.println(ex.getMessage());
System.exit(-1);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(-1);
}
}
Aggregations