List of usage examples for org.apache.commons.cli OptionBuilder hasArg
public static OptionBuilder hasArg()
From source file:edu.harvard.med.iccbl.screensaver.io.screens.ScreenPrivacyExpirationUpdater.java
@SuppressWarnings("static-access") public static void main(String[] args) { final ScreenPrivacyExpirationUpdater app = new ScreenPrivacyExpirationUpdater(args); // TODO: allow this to be optional and glean the eCommons ID from the // environment - sde4 app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(SCREEN_TYPE_OPTION[ARG_INDEX]) .withDescription(SCREEN_TYPE_OPTION[DESCRIPTION_INDEX]) .withLongOpt(SCREEN_TYPE_OPTION[LONG_OPTION_INDEX]).create(SCREEN_TYPE_OPTION[SHORT_OPTION_INDEX])); app.addCommandLineOption(// w w w . ja v a2 s. co m OptionBuilder.hasArg().withArgName(ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[ARG_INDEX]) .withDescription(ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[DESCRIPTION_INDEX]) .withLongOpt(ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[LONG_OPTION_INDEX]) .create(ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[SHORT_OPTION_INDEX])); app.addCommandLineOption(OptionBuilder.withDescription(NOTIFY_OF_OVERRIDES[DESCRIPTION_INDEX]) .withLongOpt(NOTIFY_OF_OVERRIDES[LONG_OPTION_INDEX]) .create(NOTIFY_OF_OVERRIDES[SHORT_OPTION_INDEX])); app.addCommandLineOption(OptionBuilder.withDescription(EXPIRE_PRIVACY[DESCRIPTION_INDEX]) .withLongOpt(EXPIRE_PRIVACY[LONG_OPTION_INDEX]).create(EXPIRE_PRIVACY[SHORT_OPTION_INDEX])); app.addCommandLineOption(OptionBuilder.hasArg().withArgName(NOTIFY_PRIVACY_EXPIRATION[ARG_INDEX]) .withDescription(NOTIFY_PRIVACY_EXPIRATION[DESCRIPTION_INDEX]) .withLongOpt(NOTIFY_PRIVACY_EXPIRATION[LONG_OPTION_INDEX]) .create(NOTIFY_PRIVACY_EXPIRATION[SHORT_OPTION_INDEX])); app.addCommandLineOption(OptionBuilder.hasArg().withArgName(EXPIRATION_EMAIL_MESSAGE_LOCATION[ARG_INDEX]) .withDescription(EXPIRATION_EMAIL_MESSAGE_LOCATION[DESCRIPTION_INDEX]) .withLongOpt(EXPIRATION_EMAIL_MESSAGE_LOCATION[LONG_OPTION_INDEX]) .create(EXPIRATION_EMAIL_MESSAGE_LOCATION[SHORT_OPTION_INDEX])); app.addCommandLineOption(OptionBuilder.withDescription(NOTIFY_OF_PUBLICATIONS[DESCRIPTION_INDEX]) .withLongOpt(NOTIFY_OF_PUBLICATIONS[LONG_OPTION_INDEX]) .create(NOTIFY_OF_PUBLICATIONS[SHORT_OPTION_INDEX])); app.addCommandLineOption(OptionBuilder.withDescription(TEST_ONLY[DESCRIPTION_INDEX]) .withLongOpt(TEST_ONLY[LONG_OPTION_INDEX]).create(TEST_ONLY[SHORT_OPTION_INDEX])); app.processOptions(/* acceptDatabaseOptions= */true, /* acceptAdminUserOptions= */true); log.info("==== Running ScreenPrivacyExpirationUpdater: " + app.toString() + "======"); final GenericEntityDAO dao = (GenericEntityDAO) app.getSpringBean("genericEntityDao"); app.init(); dao.doInTransaction(new DAOTransaction() { public void runTransaction() { try { // check that not too many options are specified int numberOfActions = 0; if (app.isCommandLineFlagSet(NOTIFY_PRIVACY_EXPIRATION[SHORT_OPTION_INDEX])) numberOfActions++; if (app.isCommandLineFlagSet(NOTIFY_OF_PUBLICATIONS[SHORT_OPTION_INDEX])) numberOfActions++; if (app.isCommandLineFlagSet(EXPIRE_PRIVACY[SHORT_OPTION_INDEX])) numberOfActions++; if (app.isCommandLineFlagSet( ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[SHORT_OPTION_INDEX])) numberOfActions++; if (numberOfActions > 1) { log.error("May only specify one of: " + NOTIFY_PRIVACY_EXPIRATION[SHORT_OPTION_INDEX] + ", " + NOTIFY_OF_PUBLICATIONS[SHORT_OPTION_INDEX] + ", " + EXPIRE_PRIVACY[SHORT_OPTION_INDEX] + ", " + ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[SHORT_OPTION_INDEX]); System.exit(1); } app.setScreenType(app.getCommandLineOptionEnumValue(SCREEN_TYPE_OPTION[SHORT_OPTION_INDEX], ScreenType.class)); try { if (app.isCommandLineFlagSet(NOTIFY_PRIVACY_EXPIRATION[SHORT_OPTION_INDEX])) { Integer daysAheadToNotify = app.getCommandLineOptionValue( NOTIFY_PRIVACY_EXPIRATION[SHORT_OPTION_INDEX], Integer.class); app.findNewExpiredAndNotifyAhead(daysAheadToNotify); } else if (app.isCommandLineFlagSet(NOTIFY_OF_PUBLICATIONS[SHORT_OPTION_INDEX])) { app.notifyOfPublications(); } else if (app.isCommandLineFlagSet(EXPIRE_PRIVACY[SHORT_OPTION_INDEX])) { app.expireScreenDataSharingLevels(); } else if (app.isCommandLineFlagSet( ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[SHORT_OPTION_INDEX])) { Integer ageToExpireFromActivityDateInDays = app.getCommandLineOptionValue( ADJUST_DATA_PRIVACY_EXPIRATION_DATE_BASED_ON_ACTIVITY[SHORT_OPTION_INDEX], Integer.class); app.adjustDataPrivacyExpirationByActivities(ageToExpireFromActivityDateInDays); } else { app.showHelpAndExit( "No action specified (expire, notify of privacy expirations, notify of publications, or adjust)?"); } } catch (OperationRestrictedException e) { app.sendErrorMail("Warn: Could not complete expiration service operation", "Warn: Could not complete expiration service operation", e); throw new DAOTransactionRollbackException(e); } } catch (MessagingException e) { String msg = "Admin email operation not completed due to MessagingException"; log.error(msg + ":\nApp: " + app.toString(), e); throw new DAOTransactionRollbackException(e); } if (app.isCommandLineFlagSet(TEST_ONLY[SHORT_OPTION_INDEX])) { throw new DAOTransactionRollbackException("Rollback, testing only"); } } }); log.info("==== finished ScreenPrivacyExpirationUpdater ======"); }
From source file:com.maxl.java.aips2sqlite.Aips2Sqlite.java
/** * Adds an option into the command line parser * /*ww w . j a va 2 s .co m*/ * @param optionName - the option name * @param description - option descriptiuon * @param hasValue - if set to true, --option=value, otherwise, --option is a boolean * @param isMandatory - if set to true, the option must be provided. */ @SuppressWarnings("static-access") static void addOption(Options opts, String optionName, String description, boolean hasValue, boolean isMandatory) { OptionBuilder opt = OptionBuilder.withLongOpt(optionName); opt = opt.withDescription(description); if (hasValue) opt = opt.hasArg(); if (isMandatory) opt = opt.isRequired(); opts.addOption(opt.create()); }
From source file:jetbrains.exodus.console.Console.java
private static CommandLine getCommandLine(String[] args) throws ParseException { Options options = new Options(); options.addOption(OptionBuilder.hasArg().withType(Number.class).withDescription("sshd port").create('l')); options.addOption(OptionBuilder.hasArg().withDescription("password to login").create('p')); options.addOption(OptionBuilder.hasArg().withDescription("xodus database path").create('x')); if (args.length <= 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Console.class.getCanonicalName(), options); }//from www .jav a2s .c o m // create the parser CommandLineParser parser = new BasicParser(); return parser.parse(options, args); }
From source file:carmen.utils.CommandLineUtilities.java
/** * This uses the apache Jakarta CLI to parse the command line. * A single static instance of this class exists for global access by all parts * of the program./*from www . j a va 2 s. co m*/ * To use this class, a list of options must be specified and passed to this method. * Manditory arguments should be encoded as strings. * @param args The command line received by main * @param manditory_args A list of strings that contain the names of manditory arguments. * @param specified_options A list of options to use for this program. */ public static void initCommandLineParameters(String[] args, List<Option> specified_options, String[] manditory_args) { Options options = new Options(); if (specified_options != null) for (Option option : specified_options) options.addOption(option); Option option = null; OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("A file containing command line parameters as a Java properties file."); option = OptionBuilder.create("parameter_file"); options.addOption(option); CommandLineParser command_line_parser = new GnuParser(); CommandLineUtilities._properties = new Properties(); try { CommandLineUtilities._command_line = command_line_parser.parse(options, args); } catch (ParseException e) { System.out.println("***ERROR: " + e.getClass() + ": " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("parameters:", options); System.exit(0); } if (CommandLineUtilities.hasArg("parameter_file")) { String parameter_file = CommandLineUtilities.getOptionValue("parameter_file"); // Read the property file. try { _properties.load(new FileInputStream(parameter_file)); } catch (IOException e) { System.err.println("Problem reading parameter file: " + parameter_file); } } boolean failed = false; if (manditory_args != null) { for (String arg : manditory_args) { if (!CommandLineUtilities.hasArg(arg)) { failed = true; System.out.println("Missing argument: " + arg); } } if (failed) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("parameters:", options); System.exit(0); } } }
From source file:edu.kit.dama.transfer.client.impl.BaseUserClient.java
/** * Adds a new option to the default command line options. * * @param pOptionName The option and the short option character. * @param pDescription The plain text description of the option. * @param pArgCount The argument count./*from ww w .j ava 2 s . co m*/ * @param pLongOption The long option string. * @param pMandatory TRUE = This option MUST be provided. */ public final void addOption(String pOptionName, String pDescription, int pArgCount, String pLongOption, boolean pMandatory) { if (pOptionName == null || pDescription == null) { throw new IllegalArgumentException("Neither pOptionName nor pDescription must be 'null'"); } OptionBuilder b = OptionBuilder.withLongOpt(pLongOption).withDescription(pDescription) .isRequired(pMandatory); if (pArgCount != 0) { if (pArgCount == 1) { b = b.hasArg(); } else { b = b.hasArgs(pArgCount); } } OPTIONS.addOption(b.create(pOptionName)); }
From source file:fr.smartcontext.yatte.context.cli.DefaultOptionsProvider.java
/** * {@inheritDoc}/*w w w . j ava 2s .com*/ * @see fr.smartcontext.yatte.context.cli.CLIOptionsProvider#getOptions() */ @Override public Options getOptions() { Options options = new Options(); OptionBuilder.withLongOpt(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_LONG_NAME); OptionBuilder.withDescription(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_DESCRIPTION); OptionBuilder.hasArg(); OptionBuilder.withArgName(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_ARGUMENT_NAME); options.addOption(OptionBuilder.create(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_NAME)); OptionBuilder.withLongOpt(ApplicationParametersConstants.OUTPUT_OPTION_LONG_NAME); OptionBuilder.withDescription(ApplicationParametersConstants.OUTPUT_OPTION_DESCRIPTION); OptionBuilder.hasArg(); OptionBuilder.withArgName(ApplicationParametersConstants.OUTPUT_OPTION_ARGUMENT_NAME); OptionBuilder.isRequired(); options.addOption(OptionBuilder.create(ApplicationParametersConstants.OUTPUT_OPTION_NAME)); OptionBuilder.withLongOpt(ApplicationParametersConstants.TEMPLATE_OPTION_LONG_NAME); OptionBuilder.withDescription(ApplicationParametersConstants.TEMPLATE_OPTION_DESCRIPTION); OptionBuilder.hasArg(); OptionBuilder.withArgName(ApplicationParametersConstants.TEMPLATE_OPTION_ARGUMENT_NAME); OptionBuilder.isRequired(); options.addOption(OptionBuilder.create(ApplicationParametersConstants.TEMPLATE_OPTION_NAME)); return options; }
From source file:com.example.geomesa.lambda.LambdaQuickStart.java
@SuppressWarnings("AccessStaticViaInstance") public static Map<String, String> parseOptions(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.hasArg().withArgName("brokers") .withDescription("The comma-separated list of Kafka brokers, e.g. localhost:9092").isRequired() .withLongOpt("brokers").create("b")); options.addOption(OptionBuilder.hasArg().withArgName("zookeepers").withDescription( "The comma-separated list of Zookeeper nodes that support your Kafka and Accumulo instances, e.g.: zoo1:2181,zoo2:2181,zoo3:2181") .isRequired().withLongOpt("zookeepers").create("z")); options.addOption(//w w w . j av a 2 s .co m OptionBuilder.hasArg().withArgName("instance").withDescription("The name of your Accumulo instance") .isRequired().withLongOpt("instance").create("i")); options.addOption(OptionBuilder.hasArg().withArgName("user") .withDescription("The user used to connect to your Accumulo instance").isRequired() .withLongOpt("user").create("u")); options.addOption(OptionBuilder.hasArg().withArgName("password") .withDescription("The password for your Accumulo instance").isRequired().withLongOpt("password") .create("p")); options.addOption(OptionBuilder.hasArg().withArgName("catalog") .withDescription("The catalog table to store Accumulo data, e.g. geomesa.my_catalog").isRequired() .withLongOpt("catalog").create("c")); Map<String, String> map = new HashMap<>(); CommandLine cmd = null; try { cmd = new BasicParser().parse(options, args); } catch (MissingOptionException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LambdaQuickStart", options); return null; } catch (ParseException e) { throw new RuntimeException(e); } String zookeepers = cmd.getOptionValue("z"); map.put(LambdaDataStoreFactory$Params$Accumulo$.MODULE$.ZookeepersParam().getName(), zookeepers); map.put(LambdaDataStoreFactory$Params$Accumulo$.MODULE$.InstanceParam().getName(), cmd.getOptionValue("i")); map.put(LambdaDataStoreFactory$Params$Accumulo$.MODULE$.UserParam().getName(), cmd.getOptionValue("u")); map.put(LambdaDataStoreFactory$Params$Accumulo$.MODULE$.PasswordParam().getName(), cmd.getOptionValue("p")); map.put(LambdaDataStoreFactory$Params$Accumulo$.MODULE$.CatalogParam().getName(), cmd.getOptionValue("c")); map.put(LambdaDataStoreFactory$Params$Kafka$.MODULE$.BrokersParam().getName(), cmd.getOptionValue("b")); map.put(LambdaDataStoreFactory$Params$Kafka$.MODULE$.ZookeepersParam().getName(), zookeepers); map.put(LambdaDataStoreFactory.Params$.MODULE$.ExpiryParam().getName(), "1s"); return map; }
From source file:de.weltraumschaf.groundzero.opt.commons.OptionsConfiguration.java
/** * Initializes {@link #options} with all information the options parser needs. *///from w w w . jav a 2 s. co m public OptionsConfiguration() { super(); // w/ argument OptionBuilder.withDescription(OptionDescriptor.PATH_PREFIX.getDescription()); OptionBuilder.withArgName("PATH"); OptionBuilder.hasArg(); OptionBuilder.withLongOpt(OptionDescriptor.PATH_PREFIX.getLongOption()); options.addOption(OptionBuilder.create(OptionDescriptor.PATH_PREFIX.getShortOption())); OptionBuilder.withDescription(OptionDescriptor.INPUT_ENCODING.getDescription()); OptionBuilder.withArgName("ENCODING"); OptionBuilder.hasArg(); OptionBuilder.withLongOpt(OptionDescriptor.INPUT_ENCODING.getLongOption()); options.addOption(OptionBuilder.create(OptionDescriptor.INPUT_ENCODING.getShortOption())); OptionBuilder.withDescription(OptionDescriptor.OUTPUT_ENCODING.getDescription()); OptionBuilder.withArgName("ENCODING"); OptionBuilder.hasArg(); OptionBuilder.withLongOpt(OptionDescriptor.OUTPUT_ENCODING.getLongOption()); options.addOption(OptionBuilder.create(OptionDescriptor.OUTPUT_ENCODING.getShortOption())); // w/o argument options.addOption(OptionDescriptor.DEBUG.getShortOption(), OptionDescriptor.DEBUG.getLongOption(), false, OptionDescriptor.DEBUG.getDescription()); options.addOption(OptionDescriptor.HELP.getShortOption(), OptionDescriptor.HELP.getLongOption(), false, OptionDescriptor.HELP.getDescription()); options.addOption(OptionDescriptor.VERSION.getShortOption(), OptionDescriptor.VERSION.getLongOption(), false, OptionDescriptor.VERSION.getDescription()); }
From source file:edu.odu.cs.cs350.yellow1.ui.cli.ClI.java
@SuppressWarnings("static-access") private static Options getOptions() { Options opts = new Options(); opts.addOption("help", false, "Display help information"); Option src = OptionBuilder.withArgName("src folder").hasArg() .withDescription("The parent folder for the coding project").create("src"); Option zipd = OptionBuilder.hasArg().withArgName("zipped src folder").hasArg() .withDescription("the src folder is zipped y:n").create('z'); Option mutFile = OptionBuilder.hasArg().withArgName("file to be mutated").hasArg() .withDescription("The file name to be mutated. Requires full path").create("mutF"); Option testSuitePath = OptionBuilder.hasArg().withArgName("project test suite").hasArg() .withDescription("The test suite for the project. Requires full path").create("testSte"); Option goldOutput = OptionBuilder.hasArg().withArgName("gold version output").hasArg() .withDescription("The output for the gold program. Requires full path").create("goldOut"); opts.addOption(src);/*w w w . j av a 2 s . c om*/ opts.addOption(zipd); opts.addOption(mutFile); opts.addOption(testSuitePath); opts.addOption(goldOutput); return opts; }
From source file:net.alegen.datpass.cli.input.PasswordCommand.java
protected PasswordCommand() { this.options = new Options(); Option length = OptionBuilder.hasArg().withArgName("length").withDescription("length of the password") .withLongOpt(OPTION_LENGTH_LONG).create(OPTION_LENGTH); Option input = OptionBuilder.hasArg().withArgName("input") .withDescription("input for the key generation function").withLongOpt(OPTION_INPUT_LONG) .create(OPTION_INPUT);/*from w w w . j a va 2 s .c om*/ this.options.addOption(length); this.options.addOption(input); }