use of com.beust.jcommander.JCommander in project GeoGig by boundlessgeo.
the class SLCommandProxy method getCommandParser.
/**
* @return the JCommander parser for this extension
* @see JCommander
*/
@Override
public JCommander getCommandParser() {
JCommander commander = new JCommander();
commander.setProgramName("geogig sl");
commander.addCommand("import", new SLImport());
commander.addCommand("list", new SLList());
commander.addCommand("describe", new SLDescribe());
commander.addCommand("export", new SLExport());
return commander;
}
use of com.beust.jcommander.JCommander in project jvm-tools by aragozin.
the class CommandLauncher method start.
public boolean start(String[] args) {
JCommander parser = null;
try {
parser = new JCommander(this);
addCommands(parser);
try {
parser.parse(args);
} catch (Exception e) {
failAndPrintUsage(e.toString());
}
if (help) {
String cmd = parser.getParsedCommand();
if (cmd == null) {
parser.usage();
} else {
parser.usage(cmd);
}
} else if (listCommands) {
for (String cmd : commands.keySet()) {
System.out.println(String.format("%8s - %s", cmd, parser.getCommandDescription(cmd)));
}
} else {
Runnable cmd = commands.get(parser.getParsedCommand());
if (cmd == null) {
failAndPrintUsage();
} else {
cmd.run();
}
}
if (suppressSystemExit) {
return true;
} else {
System.exit(0);
}
} catch (CommandAbortedError error) {
for (String m : error.messages) {
logError(m);
}
if (verbose && error.getCause() != null) {
logTrace(error.getCause());
}
if (error.printUsage && parser != null) {
if (parser.getParsedCommand() != null) {
parser.usage(parser.getParsedCommand());
} else {
parser.usage();
}
}
} catch (Throwable e) {
e.printStackTrace();
}
// abnormal termination
if (suppressSystemExit) {
return false;
} else {
System.exit(1);
return false;
}
}
use of com.beust.jcommander.JCommander in project jvm-tools by aragozin.
the class YoungGCStarter method main.
public static void main(String[] args) throws IOException {
JCommander jcmd = new JCommander();
YoungGCPauseBenchmark bench = new YoungGCPauseBenchmark();
jcmd.addCommand("ygc", bench);
jcmd.parse(args);
String cmd = jcmd.getParsedCommand();
if (cmd != null) {
bench.benchmark();
} else {
jcmd.usage();
}
}
use of com.beust.jcommander.JCommander in project disunity by ata4.
the class Command method addSubCommand.
protected JCommander addSubCommand(String commandName, Command commandObj) {
commander.addCommand(commandName, commandObj);
JCommander subCommander = commander.getCommands().get(commandName);
commandObj.init(subCommander, out);
return subCommander;
}
use of com.beust.jcommander.JCommander in project disunity by ata4.
the class Command method run.
@Override
public void run() {
String commandName = commander.getParsedCommand();
if (!commander.getCommands().isEmpty()) {
JCommander command = commander.getCommands().get(commandName);
if (command != null && !command.getObjects().isEmpty()) {
Command commandObj = (Command) command.getObjects().get(0);
commandObj.run();
} else {
// no command selected, show usage
usage();
}
}
}
Aggregations