List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:com.flaptor.indextank.storage.LogWriterServer.java
@SuppressWarnings("static-access") private static Options getOptions() { Option port = OptionBuilder.withArgName("port").hasArg().withDescription("Server Port").withLongOpt("port") .create("p"); Option path = OptionBuilder.withArgName("path").hasArg().withDescription("Logs Path").withLongOpt("path") .isRequired(false).create("f"); Option help = OptionBuilder.withDescription("Displays this help").withLongOpt("help").create("h"); Options options = new Options(); options.addOption(port);//from w w w . j a va2s . co m options.addOption(path); options.addOption(help); return options; }
From source file:amie.keys.CSAKey.java
/** * Parses the command line arguments and the returns an object that maps each argument * to its value.//from w w w . ja v a2s.co m * @param args * @return * @throws IOException */ public static Triple<MiningAssistant, Float, String> parseArguments(String[] args) throws IOException { HelpFormatter formatter = new HelpFormatter(); float inputSupport = defaultMinSupport; // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); CommandLine cli = null; Option supportOpt = OptionBuilder.withArgName("min-support").hasArg() .withDescription( "Minimum support. Default: 5 positive examples. If the option percentage is enabled, " + "the value is considered as the percentage of entities covered " + "by the a conditional key.") .create("mins"); Option ratioOpt = OptionBuilder.withArgName("percentage") .withDescription("Interpret the support as a percentage " + "Default: false").create("p"); Option nonKeysOpt = OptionBuilder.withArgName("non-keys").withDescription("Path the to the non-keys file.") .hasArg().isRequired().create("nk"); Option minLoadOpt = OptionBuilder.withArgName("").withDescription("Mininum load").hasArg().create("minl"); Option maxLoadOpt = OptionBuilder.withArgName("").withDescription("Maximum load").hasArg().create("maxl"); options.addOption(supportOpt); options.addOption(ratioOpt); options.addOption(nonKeysOpt); options.addOption(minLoadOpt); options.addOption(maxLoadOpt); try { cli = parser.parse(options, args); } catch (ParseException e) { System.out.println("Unexpected exception: " + e.getMessage()); formatter.printHelp("CombinationsExploration [OPTIONS] <TSV FILES>", options); System.exit(1); } String[] fileNameArgs = cli.getArgs(); // Use kb = amie.data.U.loadFiles(args, 1) to ignore the first // argument. This first argument could be the list of non-keys //kb = amie.data.U.loadFiles(fileNameArgs); KB kb = AlignKBs.loadFiles(fileNameArgs, 0); MiningAssistant miningHelper = new DefaultMiningAssistant(kb); if (cli.hasOption("mins")) { try { inputSupport = Float.parseFloat(cli.getOptionValue("mins")); } catch (NumberFormatException e) { System.out.println("Unexpected exception: " + e.getMessage()); formatter.printHelp("CombinationsExploration [OPTIONS] <TSV FILES>", options); System.exit(1); } } if (cli.hasOption("p")) { System.out.println("Support interpreted as a " + inputSupport + "% of the number of entities."); long numberOfInstances = kb.size(Column.Subject); System.out.println(numberOfInstances + " instances found as subjects in the KB."); inputSupport = (int) Math.ceil(numberOfInstances * inputSupport / 100.0); } if (cli.hasOption("minl")) { minLoad = Integer.parseInt(cli.getOptionValue("minl")); System.out.println("minLoad=" + minLoad); } if (cli.hasOption("maxl")) { maxLoad = Integer.parseInt(cli.getOptionValue("maxl")); System.out.println("maxLoad=" + maxLoad); } System.out.println("Using minimum support " + inputSupport); return new Triple<>(miningHelper, inputSupport, cli.getOptionValue("nk")); }
From source file:edu.umass.cs.gnsclient.client.testing.CreateGuidTest.java
private static CommandLine initializeOptions(String[] args) throws ParseException { Option help = new Option("help", "Prints Usage"); Option alias = OptionBuilder.withArgName("alias").hasArg() .withDescription("the alias (HRN) to use for the account").create("alias"); commandLineOptions = new Options(); commandLineOptions.addOption(alias); commandLineOptions.addOption(help);/*w ww.java 2s. com*/ CommandLineParser parser = new GnuParser(); return parser.parse(commandLineOptions, args); }
From source file:com.google.code.linkedinapi.client.examples.PostCommentExample.java
/** * Build command line options object./* w ww . j a v a 2 s . c o m*/ */ private static Options buildOptions() { Options opts = new Options(); String helpMsg = "Print this message."; Option help = new Option(HELP_OPTION, helpMsg); opts.addOption(help); String consumerKeyMsg = "You API Consumer Key."; OptionBuilder.withArgName("consumerKey"); OptionBuilder.hasArg(); OptionBuilder.withDescription(consumerKeyMsg); Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION); opts.addOption(consumerKey); String consumerSecretMsg = "You API Consumer Secret."; OptionBuilder.withArgName("consumerSecret"); OptionBuilder.hasArg(); OptionBuilder.withDescription(consumerSecretMsg); Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION); opts.addOption(consumerSecret); String accessTokenMsg = "You OAuth Access Token."; OptionBuilder.withArgName("accessToken"); OptionBuilder.hasArg(); OptionBuilder.withDescription(accessTokenMsg); Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION); opts.addOption(accessToken); String tokenSecretMsg = "You OAuth Access Token Secret."; OptionBuilder.withArgName("accessTokenSecret"); OptionBuilder.hasArg(); OptionBuilder.withDescription(tokenSecretMsg); Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION); opts.addOption(accessTokenSecret); String idMsg = "ID of the post on which to comment."; OptionBuilder.withArgName("postId"); OptionBuilder.hasArg(); OptionBuilder.withDescription(idMsg); Option id = OptionBuilder.create(POST_ID_OPTION); opts.addOption(id); String commentMsg = "Text of the comment."; OptionBuilder.withArgName("comment"); OptionBuilder.hasArg(); OptionBuilder.withDescription(commentMsg); Option comment = OptionBuilder.create(COMMENT_TEXT_OPTION); opts.addOption(comment); return opts; }
From source file:com.ilopez.jasperemail.JasperEmail.java
public static void main(String[] args) throws Exception { JasperEmail runJasperReports = new JasperEmail(); // Set up command line parser Options options = new Options(); Option reports = OptionBuilder.withArgName("reportlist").hasArg() .withDescription("Comma separated list of JasperReport XML input files").create("reports"); options.addOption(reports);/* w w w .ja va2s . com*/ Option emailTo = OptionBuilder.withArgName("emailaddress").hasArg() .withDescription("Email address to send generated reports to").create("emailto"); options.addOption(emailTo); Option emailFrom = OptionBuilder.withArgName("emailaddress").hasArg() .withDescription("Sender email address").create("emailfrom"); options.addOption(emailFrom); Option emailSubjectLine = OptionBuilder.withArgName("emailsubject").hasArg() .withDescription("Subject line of email").create("emailsubject"); options.addOption(emailSubjectLine); Option smtpHostOption = OptionBuilder.withArgName("smtphost").hasArg() .withDescription("Address of email server").create("smtphost"); options.addOption(smtpHostOption); Option smtpUserOption = OptionBuilder.withArgName("smtpuser").hasArg() .withDescription("Username if email server requires authentication").create("smtpuser"); options.addOption(smtpUserOption); Option smtpPassOption = OptionBuilder.withArgName("smtppass").hasArg() .withDescription("Password if email server requires authentication").create("smtppass"); options.addOption(smtpPassOption); Option smtpAuthOption = OptionBuilder.withArgName("smtpauth").hasArg() .withDescription("Set SMTP Authentication").create("smtpauth"); options.addOption(smtpAuthOption); Option smtpPortOption = OptionBuilder.withArgName("smtpport").hasArg() .withDescription("Port for the SMTP server 25/468/587/2525/2526").create("smtpport"); options.addOption(smtpPortOption); Option smtpTypeOption = OptionBuilder.withArgName("smtptype").hasArg() .withDescription("Define SMTP Type, one of: " + Arrays.asList(OptionValues.SMTPType.values())) .create("smtptype"); options.addOption(smtpTypeOption); Option outputFolder = OptionBuilder.withArgName("foldername").hasArg() .withDescription( "Folder to write generated reports to, with trailing separator (slash or backslash)") .create("folder"); options.addOption(outputFolder); Option dbJDBCClass = OptionBuilder.withArgName("jdbcclass").hasArg() .withDescription("Provide the JDBC Database Class ").create("jdbcclass"); options.addOption(dbJDBCClass); Option dbJDBCURL = OptionBuilder.withArgName("jdbcurl").hasArg() .withDescription("Provide the JDBC Database URL").create("jdbcurl"); options.addOption(dbJDBCURL); Option dbUserOption = OptionBuilder.withArgName("username").hasArg() .withDescription("Username to connect to databasewith").create("dbuser"); options.addOption(dbUserOption); Option dbPassOption = OptionBuilder.withArgName("password").hasArg().withDescription("Database password") .create("dbpass"); options.addOption(dbPassOption); Option outputTypeOption = OptionBuilder.withArgName("outputtype").hasArg() .withDescription("Output type, one of: " + Arrays.asList(OutputType.values())).create("output"); options.addOption(outputTypeOption); Option outputFilenameOption = OptionBuilder.withArgName("outputfilename").hasArg() .withDescription("Output filename (excluding filetype suffix)").create("filename"); options.addOption(outputFilenameOption); Option paramsOption = OptionBuilder.withArgName("parameters").hasArg().withDescription( "Parameters, e.g. param1=boolean:true,param2=string:ABC,param3=double:134.2,param4=integer:85") .create("params"); options.addOption(paramsOption); // Parse command line CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); String reportsDefinitionFileNamesCvs = commandLine.getOptionValue("reports"); if (reportsDefinitionFileNamesCvs == null) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar JasperEmail.jar", options); System.out.println(); System.out.println("See http://github.com/ilopez/JasperEmail for further documentation"); System.out.println(); throw new IllegalArgumentException("No reports specified"); } String outputPath = commandLine.getOptionValue("folder"); List<String> reportDefinitionFileNames = Arrays.asList(reportsDefinitionFileNamesCvs.split(",")); List<String> outputFileNames = new ArrayList<String>(); String jdbcClass = commandLine.getOptionValue("jdbcclass"); String jdbcURL = commandLine.getOptionValue("jdbcurl"); String databaseUsername = commandLine.getOptionValue("dbuser"); String databasePassword = commandLine.getOptionValue("dbpass"); OutputType outputType = OutputType.PDF; String outputTypeString = commandLine.getOptionValue("output"); if (outputTypeString != null) { outputType = OutputType.valueOf(outputTypeString.toUpperCase()); } String parametersString = commandLine.getOptionValue("params"); Map parameters = runJasperReports.prepareParameters(parametersString); String outputFilenameSpecified = commandLine.getOptionValue("filename"); if (outputFilenameSpecified == null) { outputFilenameSpecified = ""; } // SMTP PORT Integer smtpport = Integer.parseInt(commandLine.getOptionValue("smtpport")); Boolean smtpauth = Boolean.parseBoolean(commandLine.getOptionValue("smtpauth")); OptionValues.SMTPType smtptype; String smtptypestring = commandLine.getOptionValue("smtpenc"); if (smtptypestring != null) { smtptype = OptionValues.SMTPType.valueOf(smtptypestring.toUpperCase()); } else { smtptype = OptionValues.SMTPType.PLAIN; } // SMTP TLS // SMTP // Iterate over reports, generating output for each for (String reportsDefinitionFileName : reportDefinitionFileNames) { String outputFilename = null; if ((reportDefinitionFileNames.size() == 1) && (!outputFilenameSpecified.equals(""))) { outputFilename = outputFilenameSpecified; } else { outputFilename = outputFilenameSpecified + reportsDefinitionFileName.replaceAll("\\..*$", ""); outputFilename = outputFilename.replaceAll("^.*\\/", ""); outputFilename = outputFilename.replaceAll("^.*\\\\", ""); } outputFilename = outputFilename.replaceAll("\\W", "").toLowerCase() + "." + outputType.toString().toLowerCase(); if (outputPath != null) { if (!outputPath.endsWith("\\") && !outputPath.endsWith("/")) { outputPath += java.io.File.separator; } outputFilename = outputPath + outputFilename; } System.out.println("Going to generate report " + outputFilename); runJasperReports.generateReport(reportsDefinitionFileName, jdbcClass, jdbcURL, databaseUsername, databasePassword, jdbcURL, parameters); outputFileNames.add(outputFilename); } String emailRecipientList = commandLine.getOptionValue("emailto"); if (emailRecipientList != null) { Set<String> emailRecipients = new HashSet<String>(Arrays.asList(emailRecipientList.split(","))); String emailSender = commandLine.getOptionValue("emailfrom"); String emailSubject = commandLine.getOptionValue("emailsubject"); if (emailSubject == null) { emailSubject = "Report attached"; } String emailHost = commandLine.getOptionValue("smtphost"); if (emailHost == null) { emailHost = "localhost"; } String emailUser = commandLine.getOptionValue("smtpuser"); String emailPass = commandLine.getOptionValue("smtppass"); System.out.println("Emailing reports to " + emailRecipients); runJasperReports.emailReport(emailHost, emailUser, emailPass, emailRecipients, emailSender, emailSubject, outputFileNames, smtpauth, smtptype, smtpport); } else { System.out.println("Email not generated (no recipients specified)"); } }
From source file:com.boundary.sdk.event.snmp.MIBCompiler.java
/** * Handles all the options passed to the command line. * /*from w ww . j a va 2 s .co m*/ * @param args Command line arguments */ @SuppressWarnings("static-access") public void parseCommandLineOptions(String[] args) { for (String s : args) { LOG.debug(s); } helpOption = OptionBuilder.withDescription("Display help information").withLongOpt("help").create("h"); licenseOption = OptionBuilder.withArgName("license").hasArgs().withValueSeparator(' ').withDescription( "The license key string you received with the purchase a SNMP4J-SMI license or its evaluation." + "You may provide leave empty, but then you may not use any MIB modules of the \"enterprise\" OID subtree.") .withLongOpt("license").create("l"); mibDirOption = OptionBuilder.withArgName("mib_path").hasArg() .withDescription("Path to single MIB, ZIP file of MIB(s), or a directory of MIBs to compile.") .withLongOpt("mib-path").create("m"); silentOption = OptionBuilder.withDescription("Quiet mode, suppress normal output.").withLongOpt("quiet") .create("q"); repoDirOption = OptionBuilder.withArgName("repository_dir").hasArg() .withDescription("An empty directory where the " + commandName + "can read and store compiled MIB modules persistently. " + "Directory must not contain any plain text (i.e., uncompiled) MIB files.") .withLongOpt("repository-dir").create("r"); strictCompileOption = OptionBuilder.withArgName("lenient|standard").hasArg() .withDescription("Strictness defines the number of syntax checks done on the sources.") .withLongOpt("compiler-strict").create("s"); updateExisting = OptionBuilder.withDescription("Update existing MIBs in repository") .withLongOpt("update-existing").create("u"); options.addOption(repoDirOption); options.addOption(mibDirOption); options.addOption(licenseOption); options.addOption(helpOption); options.addOption(strictCompileOption); options.addOption(silentOption); try { CommandLineParser parser = new BasicParser(); cmd = parser.parse(options, args); if (cmd.hasOption("h") == true && cmd.hasOption("q") == false) { usage(); } } catch (Exception e) { usage(); } }
From source file:be.svlandeg.diffany.console.DiffanyOptions.java
/** * Define the options specifying necessary arguments for the Diffany algorithms *//*from w w w .j av a 2s. co m*/ private Set<Option> getAllParameters() { Set<Option> allParameters = new HashSet<Option>(); OptionBuilder.withArgName("dir"); OptionBuilder.withLongOpt("inputDir"); OptionBuilder.hasArgs(1); OptionBuilder.isRequired(); OptionBuilder .withDescription("the input directory containing the reference and condition-specific networks"); allParameters.add(OptionBuilder.create(inputShort)); OptionBuilder.withArgName("dir"); OptionBuilder.withLongOpt("outputDir"); OptionBuilder.hasArgs(1); OptionBuilder.isRequired(); OptionBuilder.withDescription( "the output directory which will contain the generated differential/consensus networks"); allParameters.add(OptionBuilder.create(outputShort)); String defaultRunDiffString = defaultRunDiff ? "yes" : "no"; OptionBuilder.withLongOpt("differential"); OptionBuilder.hasArgs(1); OptionBuilder.withDescription("whether or not to calculate differential networks: yes or no (default=" + defaultRunDiffString + ")"); allParameters.add(OptionBuilder.create(runDiff)); String defaultRunConsString = defaultRunCons ? "yes" : "no"; ; OptionBuilder.withLongOpt("consensus"); OptionBuilder.hasArgs(1); OptionBuilder.withDescription( "whether or not to calculate consensus networks: yes or no (default=" + defaultRunConsString + ")"); allParameters.add(OptionBuilder.create(runCons)); OptionBuilder.withLongOpt("outputID"); OptionBuilder.hasArgs(1); OptionBuilder.withDescription("the first ID that will be used for the generated networks"); allParameters.add(OptionBuilder.create(nextID)); OptionBuilder.withLongOpt("confidence"); OptionBuilder.hasArgs(1); OptionBuilder.withDescription( "the minimum confidence threshold for output edges, as an integer or double (default=0.0)"); allParameters.add(OptionBuilder.create(cutoffShort)); String defaultMinOperatorString = defaultMinOperator ? "min" : "max"; OptionBuilder.withLongOpt("operator"); OptionBuilder.hasArgs(1); OptionBuilder.withDescription("the operator used to create consensus edges: min or max (default=" + defaultMinOperatorString + ")"); allParameters.add(OptionBuilder.create(operatorShort)); String defaultModeString = defaultModePairwise ? "pairwise" : "all"; OptionBuilder.withLongOpt("mode"); OptionBuilder.hasArgs(1); OptionBuilder .withDescription("the mode of comparison: pairwise or all (default=" + defaultModeString + ")"); allParameters.add(OptionBuilder.create(modeShort)); String defaultHeaderString = defaultReadHeader ? "yes" : "no"; OptionBuilder.withLongOpt("skipHeader"); OptionBuilder.hasArgs(1); OptionBuilder.withDescription( "whether or not to skip the first line (header) in the network .txt files (default=" + defaultHeaderString + ")"); allParameters.add(OptionBuilder.create(headerShort)); return allParameters; }
From source file:com.google.code.linkedinapi.client.examples.PostShareExample.java
/** * Build command line options object.//from w ww.j a va 2 s.c o m */ private static Options buildOptions() { Options opts = new Options(); String helpMsg = "Print this message."; Option help = new Option(HELP_OPTION, helpMsg); opts.addOption(help); String consumerKeyMsg = "You API Consumer Key."; OptionBuilder.withArgName("consumerKey"); OptionBuilder.hasArg(); OptionBuilder.withDescription(consumerKeyMsg); Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION); opts.addOption(consumerKey); String consumerSecretMsg = "You API Consumer Secret."; OptionBuilder.withArgName("consumerSecret"); OptionBuilder.hasArg(); OptionBuilder.withDescription(consumerSecretMsg); Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION); opts.addOption(consumerSecret); String accessTokenMsg = "You OAuth Access Token."; OptionBuilder.withArgName("accessToken"); OptionBuilder.hasArg(); OptionBuilder.withDescription(accessTokenMsg); Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION); opts.addOption(accessToken); String tokenSecretMsg = "You OAuth Access Token Secret."; OptionBuilder.withArgName("accessTokenSecret"); OptionBuilder.hasArg(); OptionBuilder.withDescription(tokenSecretMsg); Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION); opts.addOption(accessTokenSecret); String statusMsg = "Text of the share."; OptionBuilder.withArgName("share"); OptionBuilder.hasArg(); OptionBuilder.withDescription(statusMsg); Option status = OptionBuilder.create(SHARE_TEXT_OPTION); opts.addOption(status); String urlMsg = "URL to be shared."; OptionBuilder.withArgName("url"); OptionBuilder.hasArg(); OptionBuilder.withDescription(urlMsg); Option url = OptionBuilder.create(URL_OPTION); opts.addOption(url); return opts; }
From source file:com.google.code.stackexchange.client.examples.AsyncApiExample.java
/** * Builds the options.//from www . j a v a 2 s . c o m * * @return the options */ private static Options buildOptions() { Options opts = new Options(); String helpMsg = "Print this message."; Option help = new Option(HELP_OPTION, helpMsg); opts.addOption(help); String consumerKeyMsg = "You API Key."; OptionBuilder.withArgName("key"); OptionBuilder.hasArg(); OptionBuilder.withDescription(consumerKeyMsg); Option consumerKey = OptionBuilder.create(APPLICATION_KEY_OPTION); opts.addOption(consumerKey); return opts; }
From source file:de.wpsverlinden.ufilan.Ufilan.java
private CommandLine initCli() throws ParseException { options = new Options(); options.addOption(OptionBuilder.isRequired().hasArg() .withDescription("action to perform (histogram_text, histogram_img, map, type, size, entropy)") .create("a")); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("path of the input file. If null, stdin is used").create("if")); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("path of the output file. If null, stdout is used").create("of")); options.addOption(OptionBuilder.withArgName("byte").hasArg() .withDescription("chunk size in bytes used for input parsing. Default value: 1 byte").create("c")); options.addOption(OptionBuilder.withArgName("byte").hasArg() .withDescription("skips the given number of bytes start parsing. Default value: 0 byte") .create("s")); CommandLineParser parser = new PosixParser(); return parser.parse(options, args); }