List of usage examples for org.apache.commons.cli Options addOption
public Options addOption(String opt, boolean hasArg, String description)
From source file:com.chriscx.similarity.SimilarityApp.java
public static void main(String[] args) throws ParseException { Options options = new Options(); options.addOption("i", true, "input folder"); options.addOption("o", true, "output folder"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (args.length > 1) { }// w w w . j a v a2 s . c o m }
From source file:com.adobe.aem.demomachine.Base64Encoder.java
public static void main(String[] args) throws IOException { String value = null;/*from w ww. jav a 2 s. c o m*/ // Command line options for this tool Options options = new Options(); options.addOption("v", true, "Value"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("v")) { value = cmd.getOptionValue("v"); } if (value == null) { System.out.println("Command line parameters: -v value"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } byte[] encodedBytes = Base64.encodeBase64(value.getBytes()); System.out.println(new String(encodedBytes)); }
From source file:com.floreantpos.main.Main.java
/** * @param args/*from w ww .j a v a2 s.c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(DEVELOPMENT_MODE, true, "State if this is developmentMode"); //$NON-NLS-1$ CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); String optionValue = commandLine.getOptionValue(DEVELOPMENT_MODE); Locale defaultLocale = TerminalConfig.getDefaultLocale(); if (defaultLocale != null) { Locale.setDefault(defaultLocale); } Application application = Application.getInstance(); if (optionValue != null) { application.setDevelopmentMode(Boolean.valueOf(optionValue)); } application.start(); }
From source file:com.tomdoel.mpg2dcm.Mpg2Dcm.java
public static void main(String[] args) { try {/*from w ww. ja v a2 s . co m*/ final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an mpeg2 video file to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Mpg2Dcm mpegfile dicomfile", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String mpegFileName = remainingArgs.get(0); final String dicomFileName = remainingArgs.get(1); final File mpegFile = new File(mpegFileName); final File dicomOutputFile = new File(dicomFileName); MpegFileConverter.convert(mpegFile, dicomOutputFile); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:craterdog.security.DigitalNotaryMain.java
public static void main(String[] args) throws ParseException, IOException { HelpFormatter help = new HelpFormatter(); Options options = new Options(); options.addOption("help", false, "print this message"); options.addOption("pubfile", true, "public key input file"); options.addOption("prvfile", true, "private key input file"); try {// w ww .java 2s . co m CommandLine cli = new BasicParser().parse(options, args); String pubfile = cli.getOptionValue("pubfile"); String prvfile = cli.getOptionValue("prvfile"); NotaryKey notaryKey = notarization.generateNotaryKey(); if (pubfile != null || prvfile != null) { if (pubfile == null) throw new MissingArgumentException("Missing option: pubfile"); if (prvfile == null) throw new MissingArgumentException("Missing option: prvfile"); CertificateManager manager = new RsaCertificateManager(); PublicKey publicKey = manager.decodePublicKey(FileUtils.readFileToString(new File(pubfile))); char[] password = System.console().readPassword("input private key password: "); PrivateKey privateKey = manager.decodePrivateKey(FileUtils.readFileToString(new File(prvfile)), password); notaryKey.signingKey = privateKey; notaryKey.verificationKey = publicKey; // make sure it works DigitalSeal seal = notarization.notarizeDocument("test document", "test document", notaryKey); notarization.documentIsValid("test document", seal, publicKey); } char[] password = System.console().readPassword("verficationKey password: "); System.out.println(notarization.serializeNotaryKey(notaryKey, password)); } catch (MissingArgumentException | FileNotFoundException ex) { System.out.println(ex.getMessage()); help.printHelp(CMD_LINE_SYNTAX, options); System.exit(1); } }
From source file:com.redhat.poc.jdg.bankofchina.util.GenerateUserIdCsv.java
public static void main(String[] args) throws Exception { CommandLine commandLine;/*from w w w . ja va 2 s. com*/ Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args); commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } for (int i = csvFileStart; i <= csvFileEnd; i++) { ReadCsvFile(i); } System.out.println(); System.out.println("%%%%%%%%% " + csvFileStart + "-" + csvFileEnd + " ? userid.csv ,? %%%%%%%%%"); System.out.println("%%%%%%%%% userid.csv " + userIdList.size() + " ? %%%%%%%%%"); CSVWriter writer = new CSVWriter(new FileWriter(CSV_FILE_PATH + "userid.csv")); writer.writeAll(userIdList); writer.flush(); writer.close(); }
From source file:com.tomdoel.mpg2dcm.Xml2Dicom.java
public static void main(String[] args) { try {//from ww w. ja v a2s. c om final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an endoscopic xml and video files to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Xml2Dcm xml-file dicom-output-path", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String xmlInputFileName = remainingArgs.get(0); final String dicomOutputPath = remainingArgs.get(1); EndoscopicXmlToDicomConverter.convert(new File(xmlInputFileName), dicomOutputPath); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } }
From source file:com.trovit.hdfstree.HdfsTree.java
public static void main(String... args) { Options options = new Options(); options.addOption("l", false, "Use local filesystem."); options.addOption("p", true, "Path used as root for the tree."); options.addOption("s", false, "Display the size of the directory"); options.addOption("d", true, "Maximum depth of the tree (when displaying)"); CommandLineParser parser = new PosixParser(); TreeBuilder treeBuilder;//from ww w.j a va2s. com FSInspector fsInspector = null; String rootPath = null; Displayer displayer = new ConsoleDisplayer(); try { CommandLine cmd = parser.parse(options, args); // local or hdfs. if (cmd.hasOption("l")) { fsInspector = new LocalFSInspector(); } else { fsInspector = new HDFSInspector(); } // check that it has the root path. if (cmd.hasOption("p")) { rootPath = cmd.getOptionValue("p"); } else { throw new ParseException("Mandatory option (-p) is not specified."); } if (cmd.hasOption("d")) { displayer.setMaxDepth(Integer.parseInt(cmd.getOptionValue("d"))); } if (cmd.hasOption("s")) { displayer.setDisplaySize(); } } catch (ParseException e) { System.out.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("hdfstree", options); System.exit(1); } treeBuilder = new TreeBuilder(rootPath, fsInspector); TreeNode tree = treeBuilder.buildTree(); displayer.display(tree); }
From source file:StompMessageConsumer.java
public static void main(String[] args) throws ParseException { Options options = new Options(); options.addOption("h", true, "Host to connect to"); options.addOption("p", true, "Port to connect to"); options.addOption("u", true, "User name"); options.addOption("P", true, "Password"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String host = "192.168.1.7"; String port = "61613"; String user = "guest"; String pass = "P@ssword1"; if (cmd.hasOption("h")) { host = cmd.getOptionValue("h"); }// w w w. j a va2 s . c o m if (cmd.hasOption("p")) { port = cmd.getOptionValue("p"); } if (cmd.hasOption("u")) { user = cmd.getOptionValue("u"); } if (cmd.hasOption("P")) { pass = cmd.getOptionValue("P"); } try { StompConnection connection = new StompConnection(); connection.open(host, Integer.parseInt(port)); connection.connect(user, pass); // connection.open("orange.cloudtroopers.ro", 61613); // connection.connect("system", "manager"); connection.subscribe("jms.queue.memberRegistration", Subscribe.AckModeValues.CLIENT); connection.subscribe(StompMessagePublisher.MEMBER_REGISTRATION_JMS_DESTINATION, Subscribe.AckModeValues.CLIENT); connection.begin("tx2"); StompFrame message = connection.receive(); System.out.println(message.getBody()); connection.ack(message, "tx2"); connection.commit("tx2"); connection.disconnect(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.librec.tool.driver.DataDriver.java
public static void main(String[] args) throws Exception { LibrecTool tool = new DataDriver(); Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("build")) { tool.run(args);/*www . ja v a2 s. co m*/ } else if (cmd.hasOption("load")) { ; } else if (cmd.hasOption("save")) { ; } }