List of usage examples for org.apache.commons.cli ParseException printStackTrace
public void printStackTrace()
From source file:fr.ortolang.diffusion.client.cmd.ImportZipCommand.java
@Override public void execute(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd;//from ww w .j a va 2 s .c o m Map<String, String> params = new HashMap<>(); Map<String, File> files = new HashMap<>(); try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { help(); } String[] credentials = getCredentials(cmd); String username = credentials[0]; String password = credentials[1]; if (cmd.hasOption("f")) { if (cmd.hasOption("upload")) { files.put("zippath", new File(cmd.getOptionValue("f"))); } else { params.put("zippath", cmd.getOptionValue("f")); } } else { help(); } if (cmd.hasOption("k")) { params.put("wskey", cmd.getOptionValue("k")); } else { help(); } if (cmd.hasOption("p")) { params.put("ziproot", cmd.getOptionValue("p")); } else { help(); } if (cmd.hasOption("overwrite")) { params.put("zipoverwrites", "true"); } OrtolangClient client = OrtolangClient.getInstance(); if (username.length() > 0) { client.getAccountManager().setCredentials(username, password); client.login(username); } System.out.println("Connected as user: " + client.connectedProfile()); String pkey = client.createProcess("import-zip", "Import Zip", params, files); System.out.println("Import-Zip process created with key : " + pkey); client.logout(); client.close(); } catch (ParseException e) { System.out.println("Failed to parse command line properties " + e.getMessage()); help(); } catch (OrtolangClientException | OrtolangClientAccountException e) { System.out.println("Unexpected error !!"); e.printStackTrace(); } }
From source file:fr.ortolang.diffusion.client.cmd.ReindexAllRootCollectionCommand.java
@Override public void execute(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd;/* w w w.ja v a 2s . c o m*/ try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { help(); } String[] credentials = getCredentials(cmd); String username = credentials[0]; String password = credentials[1]; boolean fakeMode = cmd.hasOption("F"); OrtolangClient client = OrtolangClient.getInstance(); if (username.length() > 0) { client.getAccountManager().setCredentials(username, password); client.login(username); } System.out.println("Connected as user: " + client.connectedProfile()); System.out.println("Looking for root collection ..."); // Looking for root collection List<String> rootCollectionKeys = new ArrayList<>(); int offset = 0; int limit = 100; JsonObject listOfObjects = client.listObjects("core", "collection", "PUBLISHED", offset, limit); JsonArray keys = listOfObjects.getJsonArray("entries"); while (!keys.isEmpty()) { for (JsonString objectKey : keys.getValuesAs(JsonString.class)) { JsonObject objectRepresentation = client.getObject(objectKey.getString()); JsonObject objectProperty = objectRepresentation.getJsonObject("object"); boolean isRoot = objectProperty.getBoolean("root"); if (isRoot) { rootCollectionKeys.add(objectKey.getString()); } } offset += limit; listOfObjects = client.listObjects("core", "collection", "PUBLISHED", offset, limit); keys = listOfObjects.getJsonArray("entries"); } System.out.println("Reindex keys : " + rootCollectionKeys); if (!fakeMode) { for (String key : rootCollectionKeys) { client.reindex(key); } } client.logout(); client.close(); } catch (ParseException e) { System.out.println("Failed to parse command line properties " + e.getMessage()); help(); } catch (OrtolangClientException | OrtolangClientAccountException e) { System.out.println("Unexpected error !!"); e.printStackTrace(); } }
From source file:gr.evoltrio.conf.CliParametersParser.java
public CliParametersParser(String[] args) { this.args = args; parser = new GnuParser(); options = new Options(); // add options first addOptions();/*from w w w . j a v a 2 s . co m*/ // parse the command line arguments try { line = parser.parse(options, args); parseParameters(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fr.ortolang.diffusion.client.cmd.ReindexCommand.java
@Override public void execute(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd;/*w ww . ja v a 2 s . c o m*/ try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { help(); } String[] credentials = getCredentials(cmd); String username = credentials[0]; String password = credentials[1]; String type = cmd.getOptionValue("t"); String service = cmd.getOptionValue("s"); String status = cmd.getOptionValue("a", "PUBLISHED"); boolean fakeMode = cmd.hasOption("F"); if (service != null) { OrtolangClient client = OrtolangClient.getInstance(); if (username.length() > 0) { client.getAccountManager().setCredentials(username, password); client.login(username); } System.out.println("Connected as user: " + client.connectedProfile()); System.out.println("Retrieving for published objects from service " + service + ", with type " + type + " and with status " + status + " ..."); List<String> objectKeys = new ArrayList<>(); int offset = 0; int limit = 100; JsonObject listOfObjects = client.listObjects(service, type, status, offset, limit); JsonArray keys = listOfObjects.getJsonArray("entries"); while (!keys.isEmpty()) { objectKeys.addAll(keys.getValuesAs(JsonString.class).stream().map(JsonString::getString) .collect(Collectors.toList())); offset += limit; listOfObjects = client.listObjects(service, type, status, offset, limit); keys = listOfObjects.getJsonArray("entries"); } System.out.println("Reindex keys (" + objectKeys.size() + ") : " + objectKeys); if (!fakeMode) { for (String key : objectKeys) { client.reindex(key); } System.out.println("All keys reindexed."); } client.logout(); client.close(); } else { help(); } } catch (ParseException e) { System.out.println("Failed to parse command line properties " + e.getMessage()); help(); } catch (OrtolangClientException | OrtolangClientAccountException e) { System.out.println("Unexpected error !!"); e.printStackTrace(); } }
From source file:com.xtructure.xevolution.tool.impl.ReadPopulationsTool.java
@Override public void launch(String[] args) { try {//w w w . j av a 2s. com XOption.parseArgs(getOptions(), args); } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); new HelpFormatter().printHelp(getClass().getSimpleName(), getOptions(), true); return; } // process help option if ((Boolean) getOption(HELP).processValue()) { new HelpFormatter().printHelp(getClass().getSimpleName(), getOptions(), true); return; } // get options FileXOption popDirOption = getOption(POPULATION_DIRECTORY); FileXOption dataDirOption = getOption(DATA_DIRECTORY); BooleanXOption continueOption = getOption(CONTINUOUS_READ); BooleanXOption verboseOption = getOption(VERBOSE); // set options continuousRead = continueOption.processValue(); verbose = verboseOption.processValue(); if (popDirOption.hasValue()) { populationDir = popDirOption.processValue(); } else { populationDir = null; } if (dataDirOption.hasValue()) { dataDir = dataDirOption.processValue(); } else { dataDir = null; } // check for required args if (populationDir == null || dataDir == null) { System.out.printf("%s and %s are required\n", POPULATION_DIRECTORY, DATA_DIRECTORY); System.out.printf("%s : %s\n", POPULATION_DIRECTORY, populationDir); System.out.printf("%s : %s\n", DATA_DIRECTORY, dataDir); new HelpFormatter().printHelp(getClass().getSimpleName(), getOptions(), true); return; } dataDir.mkdirs(); // process rebuild option if (!(Boolean) getOption(RESUME).processValue()) { if (verbose) { System.out.println("Deleting old data... "); } if (LATEST.delete() && verbose) { System.out.printf("\t...%s deleted...\n", LATEST); } if (dataDir.exists()) { for (File file : dataDir.listFiles()) { if (file.delete() && verbose) { System.out.printf("\t...%s deleted...\n", file); } } } if (verbose) { System.out.println("\tdone."); } } // run tool if (verbose) { System.out.println("Start reading population files."); } try { // for console tool, using a thread is unnecessary, but may be // useful when integrating with gui tools worker.start(); worker.join(); } catch (InterruptedException e) { e.printStackTrace(); } if (verbose) { System.out.println("Finished reading population files."); } }
From source file:com.linkedin.harisekhon.CLI.java
private void parseArgs2(String[] args) { log.trace("parseArgs2()"); // 1.3+ API problem with Spark, go back to older API for commons-cli //CommandLineParser parser = new DefaultParser(); CommandLineParser parser = new GnuParser(); try {/*from w w w .j a v a 2 s.c om*/ cmd = parser.parse(options, args); // TODO: swtich to getOpt after Optional implemented if (cmd.hasOption("h")) { usage(); } if (cmd.hasOption("D")) { debug = true; } if (cmd.hasOption("v")) { verbose += 1; } // TODO: get version and top level class name // if(cmd.hasOption("%s version %s".format())){ // println(version_string); // System.exit(exit_codes.get("UNKNOWN")); // } timeout = timeout_default; if (cmd.hasOption("t")) { timeout = Integer.valueOf(cmd.getOptionValue("t", String.valueOf(timeout))); } } catch (ParseException e) { if (debug) { e.printStackTrace(); } log.error(e + "\n"); usage(); } String env_verbose = System.getenv("VERBOSE"); if (env_verbose != null && !env_verbose.trim().isEmpty()) { try { int v = Integer.valueOf(env_verbose.trim()); if (v > verbose) { log.trace( String.format("environment variable $VERBOSE = %d, increasing verbosity to %d", v, v)); verbose = v; } } catch (NumberFormatException e) { log.warn(String.format("$VERBOSE environment variable is not an integer ('%s')", env_verbose)); } } parseArgs(); }
From source file:ch.cern.db.flume.sink.kite.util.InferSchemaFromTable.java
public void configure(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;// w w w . j a v a2 s . c o m try { cmd = parser.parse(options, args); showHelp = cmd.hasOption("help"); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); printHelp(); System.exit(1); } String driverClass = cmd.getOptionValue("dc", DRIVER_CLASS_DEFAULT); try { Class.forName(driverClass); } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(2); } connection_url = cmd.getOptionValue("c"); connection_user = cmd.getOptionValue("u"); connection_password = cmd.getOptionValue("p"); tableName = cmd.getOptionValue("t"); }
From source file:com.symbian.driver.core.controller.tasks.BuildTask.java
private int getSBSVersion() { try {//from w w w. jav a 2 s .c o m String sbsVersionStr = this.iConfig.getPreference("sbs").toLowerCase(); String version = sbsVersionStr.substring(1); int sbsVersion = Integer.parseInt(version); return sbsVersion; } catch (ParseException e) { e.printStackTrace(); return -1; } }
From source file:fr.ortolang.diffusion.client.cmd.CopyCommand.java
@Override public void execute(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd;/* ww w . j a va 2 s .co m*/ String localPath = null; String workspace = null; String remotePath = null; try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { help(); } String[] credentials = getCredentials(cmd); String username = credentials[0]; String password = credentials[1]; if (cmd.hasOption("w")) { workspace = cmd.getOptionValue("w"); } else { System.out.println("Workspace key is needed (-w)"); help(); } if (cmd.hasOption("m")) { //TODO validate (with an enum ?) mode = cmd.getOptionValue("m"); } List<String> argList = cmd.getArgList(); if (argList.size() < 2) { System.out.println("Two arguments is needed (localpath and remotepath)"); help(); } else { localPath = argList.get(0); remotePath = argList.get(1); } client = OrtolangClient.getInstance(); if (username.length() > 0) { client.getAccountManager().setCredentials(username, password); client.login(username); } System.out.println("Connected as user: " + client.connectedProfile()); if (!Files.exists(Paths.get(localPath))) { errors.append("-> Le chemin local (").append(localPath).append(") n'existe pas\r\n"); } else { //TODO Checks if remote Path exist if (Files.exists(Paths.get(localPath))) { copy(Paths.get(localPath), workspace, remotePath); } } if (errors.length() > 0) { System.out.println("## Some errors has been found : "); System.out.print(errors.toString()); } client.logout(); client.close(); } catch (ParseException e) { System.out.println("Failed to parse command line properties " + e.getMessage()); help(); } catch (OrtolangClientException | OrtolangClientAccountException e) { System.out.println("Unexpected error !!"); e.printStackTrace(); } }
From source file:OneParameterization.java
@Override public void start(String[] args) { // trim last argument because of an error with Windows newline // characters if (args.length > 0) { args[args.length - 1] = args[args.length - 1].trim(); }/*from w w w . j a v a2 s .com*/ Options options = getOptions(); CommandLineParser commandLineParser = new GnuParser(); CommandLine commandLine = null; try { commandLine = commandLineParser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); } if ((commandLine == null) || commandLine.hasOption("help")) { // there's no helping you! System.exit(-1); } try { run(commandLine); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }