List of usage examples for org.apache.commons.cli BasicParser BasicParser
BasicParser
From source file:org.apache.isis.core.runtime.runner.IsisRunner.java
private boolean parseOptions(final Options options, final BootPrinter printer) { final CommandLineParser parser = new BasicParser(); try {/*from w w w . j a v a2 s. c o m*/ final CommandLine commandLine = parser.parse(options, args); for (final OptionHandler optionHandler : optionHandlers) { if (!optionHandler.handle(commandLine, printer, options)) { return false; } } } catch (final ParseException e) { printer.printErrorMessage(e.getMessage()); printer.printHelp(options); return false; } return true; }
From source file:org.apache.isis.objectstore.nosql.db.file.server.FileServer.java
public static void main(final String[] args) throws IOException, ParseException { final Options options = new Options(); options.addOption("h", "help", false, "Show this help"); options.addOption("m", "mode", true, "mode: normal | secondary | recovery | archive"); final CommandLineParser parser = new BasicParser(); final CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { printHelp(options);/* ww w. j av a 2 s .co m*/ return; } final String mode = cmd.getOptionValue("m"); final List<String> argList = ObjectExtensions.asT(cmd.getArgList()); if ("recovery".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startRecovery(argList); } else if ("archive".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startArchive(argList); } else if ("secondary".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startSecondary(); } else if (mode == null || "normal".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startNormal(); } else { printHelp(options); } }
From source file:org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileServer.java
public static void main(final String[] args) throws IOException, ParseException { final Options options = new Options(); options.addOption("h", "help", false, "Show this help"); options.addOption("m", "mode", true, "mode: normal | secondary | recovery | archive"); final CommandLineParser parser = new BasicParser(); final CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { printHelp(options);/*from ww w . j a va2 s . c o m*/ return; } final String mode = cmd.getOptionValue("m"); final List<String> argList = CastUtils.cast(cmd.getArgList()); if ("recovery".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startRecovery(argList); } else if ("archive".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startArchive(argList); } else if ("secondary".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startSecondary(); } else if (mode == null || "normal".equals(mode)) { final FileServer fileServer = new FileServer(); fileServer.startNormal(); } else { printHelp(options); } }
From source file:org.apache.jackrabbit.standalone.cli.JcrClient.java
/** * Run client/*w ww . j a va2 s.c o m*/ * @param args * the arguments */ private void run(String[] args) { try { // parse arguments Parser parser = new BasicParser(); org.apache.commons.cli.CommandLine cl = parser.parse(options, args); // Set locale this.setLocale(cl); // Welcome message System.out.println(bundle.getString("word.welcome")); // check interactive mode if (cl.hasOption("source")) { this.runNonInteractive(cl); } else { this.runInteractive(); } } catch (Exception e) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("jcrclient", options); e.printStackTrace(); return; } }
From source file:org.apache.juddi.v3.migration.tool.App.java
public static void main(String[] args) throws ParseException, Exception { System.out.println("This tool is used to export and import UDDI data from a UDDI v3 registry"); System.out.println("Random TIP: " + RandomTip()); System.out.println();/*from w w w. j a v a 2s . c om*/ Options options = new Options(); options.addOption("import", false, "Imports data into a UDDIv3 registry"); options.addOption("export", false, "Exports data into a UDDIv3 registry"); options.addOption("user", true, "Username, if not defined, those is uddi.xml will be used"); options.addOption("pass", true, "Password, if not defined, those is uddi.xml will be used"); //options.addOption("safeMode", false, "Prevents overriding existing entities, saves items one at a time"); options.addOption("config", true, "Use an alternate config file default is 'uddi.xml'"); options.addOption("node", true, "The node 'name' in the config, default is 'default'"); options.addOption("isJuddi", false, "Is this a jUDDI registry? If so we can in/export more stuff"); options.addOption("tmodel", true, "Im/Export for tmodels, file to store tmodel data, default is 'tmodel-export.xml'"); options.addOption("business", true, "Im/Export option, file to store the business data, default is 'business-export.xml'"); options.addOption("mappings", true, "Im/Export option, file that maps keys to owners, default is 'entityusermappings.properties'"); options.addOption("publishers", true, "jUDDI only - In/Export option, file to store publishers, default is 'publishers-export.xml'"); options.addOption("myItemsOnly", false, "Export option, Only export items owned by yourself"); options.addOption("preserveOwnership", false, "Im/Export option, saves owership data to the 'mappings' file"); options.addOption("credFile", true, "Import option with -preserveOwnership, this is a properties file mapping with user=pass"); options.addOption("stripSignatures", false, "Im/Export option, removes digital signatures from all signed items, default is false"); // create the parser CommandLineParser parser = new BasicParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); if (line.hasOption("import") && line.hasOption("export")) { ShowHelp(options); return; } if (!line.hasOption("import") && !line.hasOption("export")) { ShowHelp(options); return; } String config = line.getOptionValue("config", "uddi.xml"); boolean stripSig = line.hasOption("stripSignatures"); String node = line.getOptionValue("node", "default"); String pass = line.getOptionValue("pass", null); String user = line.getOptionValue("user", null); String tmodel = line.getOptionValue("tmodel", "tmodel-export.xml"); String business = line.getOptionValue("business", "business-export.xml"); String publishers = line.getOptionValue("publishers", "publishers-export.xml"); //username to password String credFile = line.getOptionValue("credFile", "credentials.properties"); //key to username String mappings = line.getOptionValue("mappings", "entityusermappings.properties"); boolean preserveOwnership = line.hasOption("preserveOwnership"); boolean juddi = line.hasOption("isJuddi"); boolean myItemsOnly = line.hasOption("myItemsOnly"); boolean safe = true;//line.hasOption("safeMode"); if (line.hasOption("export")) //CommandLine cmd = parser.parse(options, args); { System.out.println("Exporting..."); new Export().Execute(config, node, user, pass, tmodel, business, juddi, safe, publishers, myItemsOnly, mappings, preserveOwnership, credFile, stripSig); System.out.println(); if (preserveOwnership) { System.out.println( "Next step(s), Edit the " + credFile + " and make any adjustments that are necessary."); System.out.println( "TIP: if you're using juddi, you can temporarily switch to the 'JuddiAuthenticator' which doesn't validate passwords."); } System.out.println("Next step(s), Edit " + config + " to point to the next registry. Then try -import. You can also specify a different node."); } if (line.hasOption("import")) //CommandLine cmd = parser.parse(options, args); { System.out.println("Importing..."); new Import().Execute(config, node, user, pass, tmodel, business, juddi, safe, publishers, preserveOwnership, mappings, credFile, stripSig); } } catch (Exception exp) { // oops, something went wrong ShowHelp(options); System.err.println("Failed!"); exp.printStackTrace(); } }
From source file:org.apache.metron.api.helper.service.PcapServiceCli.java
public void parse() { CommandLineParser parser = new BasicParser(); CommandLine cmd = null;// www . j a va 2s .com try { cmd = parser.parse(options, args); } catch (ParseException e1) { e1.printStackTrace(); } if (cmd.hasOption("h")) { help(); } if (cmd.hasOption("log4j")) { PropertyConfigurator.configure(cmd.getOptionValue("log4j")); } if (cmd.hasOption("port")) { try { port = Integer.parseInt(cmd.getOptionValue("port").trim()); } catch (Exception e) { System.out.println("[Metron] Invalid value for port entered"); help(); } } if (cmd.hasOption("pcap_hdfs_path")) { pcapHdfsPath = cmd.getOptionValue("pcap_hdfs_path"); } else { throw new IllegalStateException("You must specify the pcap hdfs path"); } if (cmd.hasOption("query_hdfs_path")) { queryHdfsPath = cmd.getOptionValue("query_hdfs_path"); } else { throw new IllegalStateException("You must specify the query temp hdfs path"); } if (cmd.hasOption("endpoint_uri")) { try { if (uri == null || uri.equals("")) throw new Exception("invalid uri"); uri = cmd.getOptionValue("uri").trim(); if (uri.charAt(0) != '/') uri = "/" + uri; if (uri.charAt(uri.length()) == '/') uri = uri.substring(0, uri.length() - 1); } catch (Exception e) { System.out.println("[Metron] Invalid URI entered"); help(); } } }
From source file:org.apache.metron.dataloads.cif.HBaseTableLoad.java
private void parse(String[] args) { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("d", true, "description"); options.addOption("t", true, "description"); options.addOption("f", false, "description"); CommandLine cmd = null;//from w ww .j a v a 2 s . co m try { cmd = parser.parse(options, args); if (cmd.hasOption("d")) { this.dirName = cmd.getOptionValue("d"); LOG.info("Directory Name:" + cmd.getOptionValue("d")); } else { LOG.info("Missing Directory Name"); printUsage(); System.exit(-1); } if (cmd.hasOption("t")) { this.hbaseTable = cmd.getOptionValue("t"); LOG.info("HBase Table Name:" + cmd.getOptionValue("t")); } else { LOG.info("Missing Table Name"); printUsage(); System.exit(-1); } if (cmd.hasOption("f")) { this.usefileList = true; files = LoadFileList(cmd.getOptionValue("f")); LOG.info("FileList:" + cmd.getOptionValue("f")); } } catch (org.apache.commons.cli.ParseException e) { LOG.error("Failed to parse comand line properties", e); e.printStackTrace(); System.exit(-1); } }
From source file:org.apache.metron.dataloads.ThreatIntelLoader.java
private static CommandLine parseCommandLine(String[] args) { CommandLineParser parser = new BasicParser(); CommandLine cli = null;/*from w ww. ja v a2s .c o m*/ Options options = new Options(); options.addOption(OptionBuilder.withArgName("s").withLongOpt("source").isRequired(true).hasArg(true) .withDescription("Source class to use").create()); options.addOption(OptionBuilder.withArgName("t").withLongOpt("table").isRequired(true).hasArg(true) .withDescription("HBase table to load into").create()); options.addOption(OptionBuilder.withArgName("c").withLongOpt("configFile").hasArg(true) .withDescription("Configuration file for source class").create()); try { cli = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ThreatIntelLoader", options, true); System.exit(-1); } return cli; }
From source file:org.apache.metron.helpers.services.PcapServiceCli.java
public void parse() { CommandLineParser parser = new BasicParser(); CommandLine cmd = null;/*from w w w . j ava 2s . c o m*/ try { cmd = parser.parse(options, args); } catch (ParseException e1) { e1.printStackTrace(); } if (cmd.hasOption("h")) help(); if (cmd.hasOption("port")) { try { port = Integer.parseInt(cmd.getOptionValue("port").trim()); } catch (Exception e) { System.out.println("[Metron] Invalid value for port entered"); help(); } } if (cmd.hasOption("endpoint_uri")) { try { if (uri == null || uri.equals("")) throw new Exception("invalid uri"); uri = cmd.getOptionValue("uri").trim(); if (uri.charAt(0) != '/') uri = "/" + uri; if (uri.charAt(uri.length()) == '/') uri = uri.substring(0, uri.length() - 1); } catch (Exception e) { System.out.println("[Metron] Invalid URI entered"); help(); } } }