List of usage examples for org.apache.commons.cli OptionBuilder withType
public static OptionBuilder withType(Object newType)
type
. From source file:edu.harvard.med.screensaver.io.Spammer.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { CommandLineApplication app = new CommandLineApplication(args); String[] option = MAIL_RECIPIENT_LIST_OPTION; app.addCommandLineOption(OptionBuilder.withType(Integer.class).hasArg().isRequired() .withArgName(option[SHORT_OPTION_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = MAIL_CC_LIST_OPTION;/*from ww w . ja v a 2 s . co m*/ app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_REPLYTO_LIST_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_MESSAGE_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_FILE_ATTACHMENT; app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_SUBJECT_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_SERVER_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_USERNAME_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_USER_PASSWORD_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_FROM_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_USE_SMTPS; app.addCommandLineOption( OptionBuilder.withArgName(option[SHORT_OPTION_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); app.processOptions(true, true); String message = app.getCommandLineOptionValue(MAIL_MESSAGE_OPTION[SHORT_OPTION_INDEX]); File attachedFile = null; if (app.isCommandLineFlagSet(MAIL_FILE_ATTACHMENT[SHORT_OPTION_INDEX])) { attachedFile = new File(app.getCommandLineOptionValue(MAIL_FILE_ATTACHMENT[SHORT_OPTION_INDEX])); if (!attachedFile.exists()) { log.error("Specified file does not exist: " + attachedFile.getCanonicalPath()); System.exit(1); } } String subject = app.getCommandLineOptionValue(MAIL_SUBJECT_OPTION[SHORT_OPTION_INDEX]); String recipientlist = app.getCommandLineOptionValue(MAIL_RECIPIENT_LIST_OPTION[SHORT_OPTION_INDEX]); String[] recipients = recipientlist.split(DELIMITER); String[] ccrecipients = null; if (app.isCommandLineFlagSet(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX])) { String cclist = app.getCommandLineOptionValue(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX]); ccrecipients = cclist.split(DELIMITER); } String replytos = null; if (app.isCommandLineFlagSet(MAIL_REPLYTO_LIST_OPTION[SHORT_OPTION_INDEX])) { replytos = app.getCommandLineOptionValue(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX]); } String mailHost = app.getCommandLineOptionValue(MAIL_SERVER_OPTION[SHORT_OPTION_INDEX]); String username = app.getCommandLineOptionValue(MAIL_USERNAME_OPTION[SHORT_OPTION_INDEX]); String password = app.getCommandLineOptionValue(MAIL_USER_PASSWORD_OPTION[SHORT_OPTION_INDEX]); boolean useSmtps = app.isCommandLineFlagSet(MAIL_USE_SMTPS[SHORT_OPTION_INDEX]); String mailFrom = username; if (app.isCommandLineFlagSet(MAIL_FROM_OPTION[SHORT_OPTION_INDEX])) { mailFrom = app.getCommandLineOptionValue(MAIL_FROM_OPTION[SHORT_OPTION_INDEX]); } SmtpEmailService service = new SmtpEmailService(mailHost, username, replytos, password, useSmtps); service.send(subject, message, mailFrom, recipients, ccrecipients, attachedFile); }
From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.spi.CliOptionsBuilder.java
public CliOptionsBuilder withType(Object newType) { OptionBuilder.withType(newType); return this; }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a lattice infile option to a given {@link Options} * object.// ww w .j a va 2 s.c o m * * @param options * The <code>Options</code> object to add to. */ private static void addLatticeInfileOption(final Options options) { OptionBuilder.isRequired(true); OptionBuilder.withLongOpt(LATTICE_INFILE_KEY_LONG); OptionBuilder.withDescription(LATTICE_INFILE_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(INFILE_ARG_NAME); OptionBuilder.withType(File.class); final Option latticeInfile = OptionBuilder.create(LATTICE_INFILE_KEY); options.addOption(latticeInfile); }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a minimum state size option to a given {@link Options} * object.//from ww w. j a va 2 s .c o m * * @param options * The <code>Options</code> object to add to. */ private static void addMinStateSizeOption(final Options options) { OptionBuilder.withLongOpt(MIN_STATE_SIZE_KEY_LONG); OptionBuilder.withDescription(MIN_STATE_SIZE_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(SIZE_ARG_NAME); OptionBuilder.withType(int.class); final Option minStateSize = OptionBuilder.create(MIN_STATE_SIZE_KEY); options.addOption(minStateSize); }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a non-word infile option to a given {@link Options} * object.//from w ww. j a v a 2 s . c o m * * @param options * The <code>Options</code> object to add to. */ private static void addNonwordInfileOption(final Options options) { OptionBuilder.withLongOpt(NONWORD_INFILE_KEY_LONG); OptionBuilder.withDescription(NONWORD_INFILE_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(INFILE_ARG_NAME); OptionBuilder.withType(File.class); final Option nonwordInfile = OptionBuilder.create(NONWORD_INFILE_KEY); options.addOption(nonwordInfile); }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a state size multiplier option to a given * {@link Options} object.//ww w . j a va 2 s .co m * * @param options * The <code>Options</code> object to add to. */ private static void addStateSizeMultiplierOption(final Options options) { OptionBuilder.withLongOpt(STATE_SIZE_MULTIPLIER_KEY_LONG); OptionBuilder.withDescription(STATE_SIZE_MULTIPLIER_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(SIZE_ARG_NAME); OptionBuilder.withType(double.class); final Option stateSizeMultiplier = OptionBuilder.create(STATE_SIZE_MULTIPLIER_KEY); options.addOption(stateSizeMultiplier); }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a horizontal size option to a given {@link Options} * object.//from ww w . j a v a2s . co m * * @param options * The <code>Options</code> object to add to. */ private static void addXSizeOption(final Options options) { OptionBuilder.withLongOpt(WIDTH_KEY_LONG); OptionBuilder.withDescription(WIDTH_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(SIZE_ARG_NAME); OptionBuilder.withType(Integer.class); final Option width = OptionBuilder.create(WIDTH_KEY); options.addOption(width); }
From source file:de.vandermeer.skb.commons.utils.CLIApache.java
@Override public Com_Coin declareOptions(PropertyTable prop) { String optShort;/* ww w . jav a2 s .c om*/ String optLong; CC_Warning ret = null; for (String current : prop.keys()) { if (prop.hasPropertyValue(current, EAttributeKeys.CLI_PARAMETER_TYPE)) { Object o = Skb_ObjectUtils.CONVERT(prop.get(current, EAttributeKeys.CLI_PARAMETER_LONG), Object.class, NONull.get, NONone.get); if (!(o instanceof Com_Coin)) { optLong = o.toString(); } else { optLong = null; } OptionBuilder.withLongOpt(optLong); o = Skb_ObjectUtils.CONVERT(prop.get(current, EAttributeKeys.CLI_PARAMETER_DESCRIPTION_SHORT), Object.class, NONull.get, NONone.get); OptionBuilder.withDescription(o.toString()); o = Skb_ObjectUtils.CONVERT(prop.get(current, EAttributeKeys.CLI_PARAMETER_DESCRIPTION_ARGUMENTS), Object.class, NONull.get, NONone.get); if (!(o instanceof Com_Coin) && o.toString().length() > 0) { OptionBuilder.hasArg(); OptionBuilder.withArgName(o.toString()); } else { OptionBuilder.hasArg(false); } switch (this.typeMap .getPair4Source(prop.get(current, EAttributeKeys.CLI_PARAMETER_TYPE).toString())) { case JAVA_BOOLEAN: OptionBuilder.withType(Boolean.class); break; case JAVA_DOUBLE: OptionBuilder.withType(Double.class); break; case JAVA_INTEGER: OptionBuilder.withType(Integer.class); break; case JAVA_LONG: OptionBuilder.withType(Long.class); break; case JAVA_STRING: default: OptionBuilder.withType(String.class); break; } o = prop.get(current, EAttributeKeys.CLI_PARAMETER_SHORT); if (o != null && !(o instanceof Com_Coin)) { optShort = o.toString(); } else { optShort = null; } if (optShort != null && optLong != null) { this.options.addOption(OptionBuilder.create(optShort.charAt(0))); this.optionList.put(current, optLong); } else if (optLong != null) { this.options.addOption(OptionBuilder.create()); this.optionList.put(current, optLong); } else { //dummy create, nothing to be done since no option set (short/long) OptionBuilder.withLongOpt("__dummyLongOpt__"); OptionBuilder.create(); if (ret == null) { ret = new CC_Warning(); } ret.add(new Message5WH_Builder().addWhat("no short and no long options for <").addWhat(current) .addWhat(">").build()); } } } if (ret == null) { return NOSuccess.get; } return ret; }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a vertical size option to a given {@link Options} * object.//from w ww .ja v a 2 s. c om * * @param options * The <code>Options</code> object to add to. */ private static void addYSizeOption(final Options options) { OptionBuilder.withLongOpt(HEIGHT_KEY_LONG); OptionBuilder.withDescription(HEIGHT_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(SIZE_ARG_NAME); OptionBuilder.withType(int.class); final Option height = OptionBuilder.create(HEIGHT_KEY); options.addOption(height); }
From source file:goal.tools.Run.java
/** * Creates the command line options.// w w w .ja v a2s.co m * * @return the command line options. */ private static Options createOptions() { Options options = new Options(); OptionBuilder.withDescription("Print all messages"); OptionBuilder.withLongOpt(OPTION_VERBOSE); options.addOption(OptionBuilder.create(OPTION_VERBOSE_SHORT)); OptionBuilder.withDescription("Print messages from parser"); options.addOption(OptionBuilder.create(OPTION_VERBOSE_PARSER)); OptionBuilder.withDescription("Print messages from info"); options.addOption(OptionBuilder.create(OPTION_VERBOSE_INFO)); OptionBuilder.withDescription("Print messages from error"); options.addOption(OptionBuilder.create(OPTION_VERBOSE_ERROR)); OptionBuilder.withDescription("Print messages from warning"); options.addOption(OptionBuilder.create(OPTION_VERBOSE_WARNING)); options.addOption(new Option(OPTION_HELP_SHORT, OPTION_HELP, false, "Displays this help")); OptionBuilder.withDescription("Shows the license"); OptionBuilder.withLongOpt(OPTION_LICENSE); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_VERSION); OptionBuilder.withDescription("Shows the current version"); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_REPEATS); OptionBuilder.withArgName("number"); OptionBuilder.withDescription("Number of times to repeat running all episodes"); OptionBuilder.hasArg(); OptionBuilder.withType(Number.class); options.addOption(OptionBuilder.create(OPTION_REPEATS_SHORT)); OptionBuilder.withLongOpt(OPTION_TIMEOUT); OptionBuilder.withArgName("number"); OptionBuilder.withDescription("Maximum time to run a system (in seconds)"); OptionBuilder.hasArg(); OptionBuilder.withType(Number.class); options.addOption(OptionBuilder.create(OPTION_TIMEOUT_SHORT)); OptionBuilder.withLongOpt(OPTION_RECURSIVE); OptionBuilder.withDescription("Recursively search for mas files"); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_DEBUG); OptionBuilder.withDescription("Display out put from debugger while running agent"); options.addOption(OptionBuilder.create(OPTION_DEBUG_SHORT)); OptionBuilder.withLongOpt(OPTION_RMI_MESSAGING); OptionBuilder.hasArg(); OptionBuilder.withArgName("host"); OptionBuilder.withDescription( "Use RMI messaging middleware. Host is the location of the RMI server. Using \"localhost\" will initialize a RMI server"); options.addOption(OptionBuilder.create()); return options; }