use of org.apache.commons.cli.ParseException in project java-jotasync by trixon.
the class Main method main.
/**
* @param args the command line arguments
* @throws java.rmi.RemoteException
*/
public static void main(String[] args) throws RemoteException, IOException {
SystemHelper.enableRmiServer();
Options options = initOptions();
CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("help")) {
displayHelp(options);
} else if (cmd.hasOption("version")) {
displayVersion();
} else {
Server server = new Server(cmd);
}
} catch (ParseException ex) {
Xlog.timedErr(ex.getMessage());
System.out.println(sBundle.getString("parse_help_server"));
}
}
use of org.apache.commons.cli.ParseException in project rocketmq by apache.
the class ServerUtil method parseCmdLine.
public static CommandLine parseCmdLine(final String appName, String[] args, Options options, CommandLineParser parser) {
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp(appName, options, true);
return null;
}
} catch (ParseException e) {
hf.printHelp(appName, options, true);
}
return commandLine;
}
use of org.apache.commons.cli.ParseException in project rocketmq by apache.
the class Consumer method buildCommandline.
public static CommandLine buildCommandline(String[] args) {
final Options options = new Options();
Option opt = new Option("h", "help", false, "Print help");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("g", "consumerGroup", true, "Consumer Group Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("t", "topic", true, "Topic Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("s", "subscription", true, "subscription");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message");
opt.setRequired(true);
options.addOption(opt);
PosixParser parser = new PosixParser();
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp("producer", options, true);
return null;
}
} catch (ParseException e) {
hf.printHelp("producer", options, true);
return null;
}
return commandLine;
}
use of org.apache.commons.cli.ParseException in project rocketmq by apache.
the class Producer method buildCommandline.
public static CommandLine buildCommandline(String[] args) {
final Options options = new Options();
Option opt = new Option("h", "help", false, "Print help");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("g", "producerGroup", true, "Producer Group Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("t", "topic", true, "Topic Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("a", "tags", true, "Tags Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("k", "keys", true, "Keys Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("c", "msgCount", true, "Message Count");
opt.setRequired(true);
options.addOption(opt);
PosixParser parser = new PosixParser();
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp("producer", options, true);
return null;
}
} catch (ParseException e) {
hf.printHelp("producer", options, true);
return null;
}
return commandLine;
}
use of org.apache.commons.cli.ParseException 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;
}
Aggregations