use of org.apache.commons.cli.DefaultParser in project java-docs-samples by GoogleCloudPlatform.
the class BookstoreClient method main.
public static void main(String[] args) throws Exception {
Options options = createOptions();
CommandLineParser parser = new DefaultParser();
CommandLine params;
try {
params = parser.parse(options, args);
} catch (ParseException e) {
System.err.println("Invalid command line: " + e.getMessage());
printUsage(options);
return;
}
String address = params.getOptionValue("bookstore", DEFAULT_ADDRESS);
String apiKey = params.getOptionValue("api_key");
String authToken = params.getOptionValue("auth_token");
String operation = params.getOptionValue("operation", "list");
// Create gRPC stub.
BookstoreGrpc.BookstoreBlockingStub bookstore = createBookstoreStub(address, apiKey, authToken);
if ("list".equals(operation)) {
listShelves(bookstore);
} else if ("create".equals(operation)) {
createShelf(bookstore);
} else if ("enumerate".equals(operation)) {
enumerate(bookstore);
}
}
use of org.apache.commons.cli.DefaultParser in project java-docs-samples by GoogleCloudPlatform.
the class BookstoreServer method main.
public static void main(String[] args) throws Exception {
Options options = createOptions();
CommandLineParser parser = new DefaultParser();
CommandLine line;
try {
line = parser.parse(options, args);
} catch (ParseException e) {
System.err.println("Invalid command line: " + e.getMessage());
printUsage(options);
return;
}
int port = DEFAULT_PORT;
if (line.hasOption("port")) {
String portOption = line.getOptionValue("port");
try {
port = Integer.parseInt(portOption);
} catch (java.lang.NumberFormatException e) {
System.err.println("Invalid port number: " + portOption);
printUsage(options);
return;
}
}
final BookstoreData data = initializeBookstoreData();
final BookstoreServer server = new BookstoreServer();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
System.out.println("Shutting down");
server.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
});
server.start(port, data);
System.out.format("Bookstore service listening on %d\n", port);
server.blockUntilShutdown();
}
use of org.apache.commons.cli.DefaultParser in project Krill by KorAP.
the class Indexer method main.
/**
* Main method.
*
* @param argv
* Argument list,
* expecting the properties file
* and a list of directories
* @throws IOException
*/
public static void main(String[] argv) throws IOException {
Options options = new Options();
options.addOption(Option.builder("c").longOpt("config").desc("configuration file (defaults to " + KrillProperties.defaultPropertiesLocation + ").").hasArg().argName("properties file").required().build());
options.addOption(Option.builder("i").longOpt("inputDir").desc("input directories separated by semicolons. The input files " + "have to be in <filename>.json.gz format. ").hasArgs().argName("input directories").required().valueSeparator(new Character(';')).build());
options.addOption(Option.builder("o").longOpt("outputDir").desc("index output directory (defaults to " + "krill.indexDir in the configuration.").hasArg().argName("output directory").build());
CommandLineParser parser = new DefaultParser();
String propFile = null;
String[] inputDirectories = null;
try {
CommandLine cmd = parser.parse(options, argv);
log.info("Configuration file: " + cmd.getOptionValue("c"));
propFile = cmd.getOptionValue("c");
log.info("Input directories: " + StringUtils.join(cmd.getOptionValues("i"), ";"));
inputDirectories = cmd.getOptionValues("i");
if (cmd.hasOption("o")) {
log.info("Output directory: " + cmd.getOptionValue("o"));
path = cmd.getOptionValue("o");
}
} catch (MissingOptionException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("Krill indexer\n java -jar -c <properties file> -i <input directories> " + "[-o <output directory>]", options);
return;
} catch (ParseException e) {
log.error("Unexpected error: " + e);
e.printStackTrace();
}
// Load properties
Properties prop = KrillProperties.loadProperties(propFile);
// Get indexer object
Indexer indexer = new Indexer(prop);
// Iterate over list of directories
for (String arg : inputDirectories) {
log.info("Indexing files in " + arg);
File f = new File(arg);
if (f.isDirectory())
indexer.parse(f);
}
indexer.closeIndex();
// Final commit
log.info("Finished indexing.");
// Finish indexing
String message = "Indexed " + indexer.count + " file";
if (indexer.count > 1) {
message += "s";
}
System.out.print(message + ".");
}
use of org.apache.commons.cli.DefaultParser in project openmeetings by apache.
the class Admin method process.
// package private wrapper for testing
void process(String... args) throws Exception {
CommandLineParser parser = new DefaultParser();
try {
cmdl = parser.parse(opts, args);
} catch (ParseException e) {
log(e.getMessage());
usage();
throw new ExitException();
}
verbose = cmdl.hasOption('v');
Command cmd = Command.usage;
if (cmdl.hasOption('i')) {
cmd = Command.install;
} else if (cmdl.hasOption('b')) {
cmd = Command.backup;
} else if (cmdl.hasOption('r')) {
cmd = Command.restore;
} else if (cmdl.hasOption('f')) {
cmd = Command.files;
} else if (cmdl.hasOption('l')) {
cmd = Command.ldap;
}
String file = cmdl.getOptionValue("file", "");
switch(cmd) {
case install:
step = "Install";
processInstall(file);
break;
case backup:
step = "Backup";
processBackup(file);
break;
case restore:
step = "Restore";
processRestore(checkRestoreFile(file));
break;
case files:
step = "Files";
processFiles();
break;
case ldap:
step = "LDAP import";
processLdap();
break;
case usage:
default:
usage();
break;
}
}
use of org.apache.commons.cli.DefaultParser 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 {
SystemHelper.enableRmiServer();
Options options = initOptions();
CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption(Main.OPT_HELP)) {
displayHelp(options);
} else if (cmd.hasOption(OPT_VERSION)) {
displayVersion();
} else {
Client client = new Client(cmd);
}
} catch (ParseException ex) {
Xlog.timedErr(ex.getMessage());
System.out.println(sBundle.getString("parse_help_client"));
}
}
Aggregations