List of usage examples for org.apache.commons.cli UnrecognizedOptionException getMessage
public String getMessage()
From source file:de.akadvh.view.Main.java
/** * @param args/*from w ww . ja v a 2 s . com*/ */ public static void main(String[] args) { Options options = new Options(); options.addOption("u", "user", true, "Benutzername"); options.addOption("p", "pass", true, "Passwort"); options.addOption("c", "console", false, "Consolenmodus"); options.addOption("v", "verbose", false, "Mehr Ausgabe"); options.addOption("m", "modul", true, "Modul"); options.addOption("n", "noten", false, "Notenuebersicht erstellen"); options.addOption("t", "termin", false, "Terminuebersicht (angemeldete Module) downloaden"); options.addOption("version", false, "Version"); options.addOption("h", "help", false, "Hilfe"); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar akadvh.jar", options); System.exit(0); } if (cmd.hasOption("version")) { System.out.println("Akadvh Version: " + Akadvh.getVersion()); System.exit(0); } if (cmd.hasOption("console")) { ConsoleView cv = new ConsoleView(cmd.getOptionValue("user"), cmd.getOptionValue("pass"), cmd.getOptionValue("modul"), cmd.hasOption("noten"), cmd.hasOption("termin"), cmd.hasOption("verbose")); } else { SwingView sv = new SwingView(cmd.getOptionValue("user"), cmd.getOptionValue("pass")); } } catch (UnrecognizedOptionException e1) { System.out.println(e1.getMessage()); System.out.println("--help fuer Hilfe"); } catch (ParseException e) { e.printStackTrace(); } }
From source file:edu.msu.cme.rdp.unifrac.Unifrac.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); CommandLine line = null;// w ww .j av a 2 s . c o m try { line = parser.parse(options, args); } catch (UnrecognizedOptionException e) { System.err.println(e.getMessage()); printUsage(); return; } UnifracTree unifracTree = null; PrintStream out = System.out; if (line.hasOption("tree") && line.hasOption("sequence-files")) { printUsage(); } else if (!(line.hasOption("weighted") || line.hasOption("unweighted") || line.hasOption("significance"))) { System.err.println("Must specify at least one calculation option"); printUsage(); } else if (line.hasOption("sample-mapping")) { Map<String, UnifracSample> sampleMap = readSampleMap(line.getOptionValue("sample-mapping")); if (line.hasOption("tree")) { unifracTree = parseNewickTree(line.getOptionValue("tree"), sampleMap); } } else { if (!line.hasOption("sample-mapping")) { System.err.println("A sample mapping file must be provided"); } printUsage(); } if (line.hasOption("outfile")) { out = new PrintStream(line.getOptionValue("outfile")); } if (unifracTree != null) { if (line.hasOption("unweighted")) { printResults(out, unifracTree.computeUnifrac(), "Unweighted Unifrac"); if (line.hasOption("significance")) { printResults(out, unifracTree.computeUnifracSig(1000, false), "Unweighted Unifrac Significance"); } } if (line.hasOption("weighted")) { printResults(out, unifracTree.computeWeightedUnifrac(), "Weighted Unifrac"); if (line.hasOption("significance")) { printResults(out, unifracTree.computeUnifracSig(1000, true), "Weighted Unifrac Significance"); } } } }
From source file:fdtutilscli.Main.java
/** * //from ww w . jav a 2 s .c o m * @param args the command line arguments */ public static void main(String[] args) { CommandLineParser parser = new PosixParser(); CommandLine line = null; Options options = new Options(); OptionGroup optCommand = new OptionGroup(); OptionGroup optOutput = new OptionGroup(); HelpFormatter formatter = new HelpFormatter(); TRACE trace = TRACE.DEFAULT; optCommand.addOption(OptionBuilder.withArgName("ndf odf nif key seperator").hasArgs(5) .withValueSeparator(' ').withDescription("Description").create("delta")); optCommand.addOption(OptionBuilder.withArgName("dupsfile key seperator").hasArgs(3) .withDescription("Description").create("duplicates")); optCommand.addOption(OptionBuilder.withLongOpt("help").withDescription("print this message.").create("h")); optCommand.addOption( OptionBuilder.withLongOpt("version").withDescription("print version information.").create("V")); optOutput.addOption(new Option("verbose", "be extra verbose")); optOutput.addOption(new Option("quiet", "be extra quiet")); optOutput.addOption(new Option("silent", "same as --quiet")); options.addOptionGroup(optCommand); options.addOptionGroup(optOutput); try { line = parser.parse(options, args); if (line.hasOption("verbose")) { trace = TRACE.VERBOSE; } else if (line.hasOption("quiet") || line.hasOption("silent")) { trace = TRACE.QUIET; } if (line.hasOption("h")) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, null, true); return; } else if (line.hasOption("V")) { System.out.println(APP_NAME + " version " + VERSION); System.out.println("fDTDeltaBuilder version " + DTDeltaBuilder.version()); System.out.println("DTDuplicateKeyFinder version " + DTDuplicateKeyFinder.version()); return; } else if (line.hasOption("delta")) { String ndf = line.getOptionValues("delta")[0]; String odf = line.getOptionValues("delta")[1]; String nif = line.getOptionValues("delta")[2]; Integer key = (line.getOptionValues("delta").length <= 3) ? DEFAULT_KEY : new Integer(line.getOptionValues("delta")[3]); String seperator = (line.getOptionValues("delta").length <= 4) ? DEFAULT_SEPERATOR : line.getOptionValues("delta")[4]; doDelta(ndf, odf, nif, key.intValue(), seperator, trace); return; } else if (line.hasOption("duplicates")) { String dupsFile = line.getOptionValues("duplicates")[0]; Integer key = (line.getOptionValues("duplicates").length <= 1) ? DEFAULT_KEY : new Integer(line.getOptionValues("duplicates")[1]); String seperator = (line.getOptionValues("duplicates").length <= 2) ? DEFAULT_SEPERATOR : line.getOptionValues("duplicates")[2]; doDuplicates(dupsFile, key.intValue(), seperator, trace); return; } else if (args.length == 0) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, null, true); } else { throw new UnrecognizedOptionException(E_MSG_UNREC_OPT); } } catch (UnrecognizedOptionException e) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, HELP_FOOTER + e.getMessage(), true); } catch (ParseException e) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, HELP_FOOTER + e.getMessage(), true); } }
From source file:com.simple.sftpfetch.App.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); Options options = getOptions();//from www . java 2s . c o m List<String> requiredProperties = asList("c"); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("h")) { printUsage(options); System.exit(0); } for (String opt : requiredProperties) { if (!commandLine.hasOption(opt)) { System.err.println("The option: " + opt + " is required."); printUsage(options); System.exit(1); } } Pattern pattern; if (commandLine.hasOption("p")) { pattern = Pattern.compile(commandLine.getOptionValue("p")); } else { pattern = MATCH_EVERYTHING; } String filename = commandLine.getOptionValue("c"); Properties properties = new Properties(); try { InputStream stream = new FileInputStream(new File(filename)); properties.load(stream); } catch (IOException ioe) { System.err.println("Unable to read properties from: " + filename); System.exit(2); } String routingKey = ""; if (commandLine.hasOption("r")) { routingKey = commandLine.getOptionValue("r"); } else if (properties.containsKey("rabbit.routingkey")) { routingKey = properties.getProperty("rabbit.routingkey"); } int daysToFetch; if (commandLine.hasOption("d")) { daysToFetch = Integer.valueOf(commandLine.getOptionValue("d")); } else { daysToFetch = Integer.valueOf(properties.getProperty(FETCH_DAYS)); } FileDecrypter decrypter = null; if (properties.containsKey("decryption.key.path")) { decrypter = new PGPFileDecrypter(new File(properties.getProperty("decryption.key.path"))); } else { decrypter = new NoopDecrypter(); } SftpClient sftpClient = new SftpClient(new JSch(), new SftpConnectionInfo(properties)); try { App app = new App(sftpClient, s3FromProperties(properties), new RabbitClient(new ConnectionFactory(), new RabbitConnectionInfo(properties)), decrypter, System.out); app.run(routingKey, daysToFetch, pattern, commandLine.hasOption("n"), commandLine.hasOption("o")); } finally { sftpClient.close(); } System.exit(0); } catch (UnrecognizedOptionException uoe) { System.err.println(uoe.getMessage()); printUsage(options); System.exit(10); } }
From source file:imageviewer.util.PasswordGenerator.java
public static void main(String[] args) { Option help = new Option("help", "Print this message"); Option file = OptionBuilder.withArgName("file").hasArg().withDescription("Password filename") .create("file"); Option addUser = OptionBuilder.withArgName("add").hasArg().withDescription("Add user profile") .create("add"); Option removeUser = OptionBuilder.withArgName("remove").hasArg().withDescription("Remove user profile") .create("remove"); Option updateUser = OptionBuilder.withArgName("update").hasArg().withValueSeparator() .withDescription("Update user profile").create("update"); file.setRequired(true);/*from w w w . jav a2 s. com*/ OptionGroup og = new OptionGroup(); og.addOption(addUser); og.addOption(removeUser); og.addOption(updateUser); og.setRequired(true); Options o = new Options(); o.addOption(help); o.addOption(file); o.addOptionGroup(og); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(o, args); PasswordGenerator pg = new PasswordGenerator(line); pg.execute(); } catch (UnrecognizedOptionException uoe) { System.err.println("Unknown argument: " + uoe.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("PasswordGenerator", o); System.exit(1); } catch (MissingOptionException moe) { System.err.println("Missing argument: " + moe.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("PasswordGenerator", o); System.exit(1); } catch (Exception exc) { exc.printStackTrace(); } }
From source file:com.chigix.autosftp.Application.java
public static void main(String[] args) { Options options = new Options(); options.addOption(Option.builder("P").longOpt("port").hasArg().build()) .addOption(Option.builder("h").longOpt("help").desc("Print this message").build()) .addOption(Option.builder("i").argName("identity_file").hasArg().build()); int port = 22; CommandLine line;/*from www.j av a 2 s . c o m*/ try { line = new DefaultParser().parse(options, args); } catch (UnrecognizedOptionException ex) { System.err.println(ex.getMessage()); return; } catch (ParseException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("autosftp /path/to/watch [user@]host2:[file2]", options, true); return; } String givenPort; if (line.hasOption("port") && StringUtils.isNumeric(givenPort = line.getOptionValue("port"))) { port = Integer.valueOf(givenPort); } if (line.getArgs().length < 0) { System.err.println("Please provide a path to watch."); return; } localPath = Paths.get(line.getArgs()[0]); if (line.getArgs().length < 1) { System.err.println("Please provide remote ssh information."); return; } SshAddressParser addressParse; try { addressParse = new SshAddressParser().parse(line.getArgs()[1]); } catch (SshAddressParser.InvalidAddressException ex) { System.err.println(ex.getMessage()); return; } if (addressParse.getDefaultDirectory() != null) { remotePath = Paths.get(addressParse.getDefaultDirectory()); } try { sshSession = new JSch().getSession(addressParse.getUsername(), addressParse.getHost(), port); } catch (JSchException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } try { sshOpen(); } catch (JSchException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); sshClose(); } System.out.println("Remote Default Path: " + remotePath); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { sshClose(); System.out.println("Bye~~~"); } }); try { watchDir(Paths.get(line.getArgs()[0])); } catch (Exception ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:imageviewer.system.ImageViewerClient.java
public static void main(String[] args) { // Use Apache command-line interface (CLI) to set up the argument // handling, etc. Option help = new Option("help", "Print this message"); Option fullScreen = new Option("fullscreen", "Run imageViewer in full screen mode"); Option noNetwork = new Option("nonet", "No network connectivity"); Option client = OptionBuilder.withArgName("prefix").hasArg() .withDescription("Specify client node (prefix) for imageServer").create("client"); Option imageType = OptionBuilder.withArgName("image type").hasArg().withDescription("Open as image type") .create("type"); Option imageDir = OptionBuilder.withArgName("image directory").hasArg() .withDescription("Open images in directory").create("dir"); Option property = OptionBuilder.withArgName("property=value").hasArg().withValueSeparator() .withDescription("use value for given property").create("D"); Options o = new Options(); o.addOption(help);//from w ww . ja v a 2s. c om o.addOption(client); o.addOption(imageDir); o.addOption(fullScreen); o.addOption(noNetwork); o.addOption(property); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(o, args); String jaasConfig = System.getProperty("java.security.auth.login.config"); if (jaasConfig == null) System.setProperty("java.security.auth.login.config", "config/jaas.config"); String antialising = new String("swing.aatext"); if (System.getProperty(antialising) == null) System.setProperty(antialising, "true"); @SuppressWarnings("unused") ImageViewerClient ivc = new ImageViewerClient(line); } catch (UnrecognizedOptionException uoe) { System.err.println("Unknown argument: " + uoe.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("ImageViewerClient", o); System.exit(1); } catch (Exception exc) { exc.printStackTrace(); } }
From source file:Executable.LinkImputeR.java
/** * Main function/* ww w . jav a 2 s . co m*/ * @param args Command line arguments * @throws Exception If an uncaught error occurs */ public static void main(String[] args) throws Exception { try { Options options = new Options(); OptionGroup all = new OptionGroup(); all.addOption(Option.builder("c").build()); all.addOption(Option.builder("s").build()); all.addOption(Option.builder("v").build()); all.addOption(Option.builder("h").build()); options.addOptionGroup(all); CommandLineParser parser = new DefaultParser(); CommandLine commands = parser.parse(options, args); String[] fileNames = commands.getArgs(); XMLConfiguration c; boolean done = false; if (commands.hasOption("c")) { if (fileNames.length == 2) { c = convert(new File(fileNames[0])); writeXML(c, new File(fileNames[1])); } else { System.out.println("An input and output file must be provided"); System.out.println(); help(); } done = true; } if (commands.hasOption("s")) { if (fileNames.length == 1) { c = convert(new File(fileNames[0])); accuracy(c); } else { System.out.println("An input file must be provided"); System.out.println(); help(); } done = true; } if (commands.hasOption("v")) { System.out.println("LinkImputeR version 1.1.3"); done = true; } if (commands.hasOption("h")) { help(); done = true; } if (!done) { if (fileNames.length == 3) { File xml = new File(fileNames[0]); FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>( XMLConfiguration.class).configure(new Parameters().xml().setFile(xml)); XMLConfiguration config = builder.getConfiguration(); switch (config.getString("mode")) { case "accuracy": accuracy(config); break; case "impute": if (args.length == 3) { impute(config, args[1], new File(args[2])); } else { impute(config, null, null); } break; } } else { System.out.println("An input file, case name and output file must be provided (in that order)"); System.out.println(); help(); } } } catch (UnrecognizedOptionException ex) { System.err.println("Unrecognised command line option (" + ex.getOption() + ")"); System.err.println(); help(); } catch (AlreadySelectedException ex) { System.err.println("Only one option can be selected at a time"); System.err.println(); help(); } catch (VCFException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem with the VCF file"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (INIException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem with the ini file"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (OutputException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem writing an output file"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (AlgorithmException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem with the algorithms"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (ProgrammerException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("Well this is embarrassing. This shouldn't have happened. " + "Please contact the maintainer if you can not solve the error" + "from the technical details."); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (Exception ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("Well this is embarrassing. This was not expected to have happened. " + "Please contact the maintainer if you can not solve the error" + "from the technical details."); System.err.println(); System.err.println("Note: The maintainer would be interested in knowing " + "about any XML related messages so he can write nicer error " + "messages for these problems."); System.err.println(); System.err.println("Technical details follow:"); throw ex; } }
From source file:com.modeln.build.common.tool.CMnCmdLineTool.java
/** * Parse the command line arguments./*from w w w . j a v a 2 s. c o m*/ */ protected static CommandLine parseArgs(String[] args) { CommandLine cl = null; try { cl = argParser.parse(cmdOptions, args); } catch (AlreadySelectedException dupex) { displayHelp(); display("\nDuplicate option: " + dupex.getMessage()); } catch (MissingOptionException opex) { displayHelp(); display("\nMissing command line option: " + opex.getMessage()); } catch (UnrecognizedOptionException uex) { displayHelp(); display(uex.getMessage()); } catch (ParseException pe) { display("Unable to parse the command line arguments: " + pe); } catch (Exception ex) { ex.printStackTrace(); } return cl; }
From source file:fr.ens.transcriptome.corsen.Corsen.java
private static void parseCommandLine(final String[] args) { Options options = makeOptions();/*w w w . j a v a2 s .c o m*/ Settings s = new Settings(); try { CommandLineParser parser = new GnuParser(); int argsOptions = 0; // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) help(options); if (line.hasOption("about")) about(); if (line.hasOption("licence")) licence(); if (line.hasOption("conf")) { loadSettings(line.getOptionValue("file")); s = settings; argsOptions++; } if (line.hasOption("typea")) { s.setParticlesAType(ParticleType.getParticleType(line.getOptionValue("type"))); argsOptions++; } if (line.hasOption("typeb")) { s.setParticlesBType(ParticleType.getParticleType(line.getOptionValue("type"))); argsOptions++; } if (line.hasOption("factor")) { s.setFactor(line.getOptionValue("factor")); argsOptions++; } if (line.hasOption("zfactor")) { s.setZFactor(line.getOptionValue("zfactor")); argsOptions++; } if (line.hasOption("od")) s.setSaveDataFile(true); if (line.hasOption("oiv")) s.setSaveIVFile(true); if (line.hasOption("or")) s.setSaveResultFile(true); if (line.hasOption("ova")) { s.setSaveVisualizationFiles(true); s.setSaveParticlesA3dFile(true); } if (line.hasOption("ovac")) { s.setSaveVisualizationFiles(true); s.setSaveParticlesACuboids3dFile(true); } if (line.hasOption("ovb")) { s.setSaveVisualizationFiles(true); s.setSaveParticlesB3dFile(true); } if (line.hasOption("ovbc")) { s.setSaveVisualizationFiles(true); s.setSaveParticlesBCuboids3dFile(true); } if (line.hasOption("ovd")) { s.setSaveVisualizationFiles(true); s.setSaveDistances3dFile(true); } if (line.hasOption("threads")) { String val = line.getOptionValue("threads"); if (val != null) { try { s.setThreadNumber(Integer.parseInt(val.trim())); } catch (NumberFormatException e) { } argsOptions++; } } if (line.hasOption("batch")) batchMode = true; if (line.hasOption("batchFile")) batchFile = line.getOptionValue("batchFile"); mainArgs = line.getArgs(); if (mainArgs.length > 0 && mainArgs.length != 3) help(options); } catch (UnrecognizedOptionException exp) { System.err.println(exp.getMessage()); System.exit(1); } catch (MissingArgumentException exp) { System.err.println(exp.getMessage()); System.exit(1); } catch (ParseException exp) { System.err.println("Error analysing command line. "); System.exit(1); } settings = s; }