List of usage examples for org.apache.commons.cli Option setArgName
public void setArgName(String argName)
From source file:org.dspace.app.itemupdate.ItemUpdate.java
/** * // w ww . j av a2 s . c o m * @param argv */ public static void main(String[] argv) { // create an options object and populate it CommandLineParser parser = new PosixParser(); Options options = new Options(); //processing basis for determining items //item-specific changes with metadata in source directory with dublin_core.xml files options.addOption("s", "source", true, "root directory of source dspace archive "); //actions on items options.addOption("a", "addmetadata", true, "add metadata specified for each item; multiples separated by semicolon ';'"); options.addOption("d", "deletemetadata", true, "delete metadata specified for each item"); options.addOption("A", "addbitstreams", false, "add bitstreams as specified for each item"); // extra work to get optional argument Option delBitstreamOption = new Option("D", "deletebitstreams", true, "delete bitstreams as specified for each item"); delBitstreamOption.setOptionalArg(true); delBitstreamOption.setArgName("BitstreamFilter"); options.addOption(delBitstreamOption); //other params options.addOption("e", "eperson", true, "email of eperson doing the update"); options.addOption("i", "itemfield", true, "optional metadata field that containing item identifier; default is dc.identifier.uri"); options.addOption("F", "filter-properties", true, "filter class name; only for deleting bitstream"); options.addOption("v", "verbose", false, "verbose logging"); //special run states options.addOption("t", "test", false, "test run - do not actually import items"); options.addOption("P", "provenance", false, "suppress altering provenance field for bitstream changes"); options.addOption("h", "help", false, "help"); int status = 0; boolean isTest = false; boolean alterProvenance = true; String itemField = null; String metadataIndexName = null; Context context = null; ItemUpdate iu = new ItemUpdate(); try { CommandLine line = parser.parse(options, argv); if (line.hasOption('h')) { HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("ItemUpdate", options); pr(""); pr("Examples:"); pr(" adding metadata: ItemUpdate -e jsmith@mit.edu -s sourcedir -a dc.contributor -a dc.subject "); pr(" deleting metadata: ItemUpdate -e jsmith@mit.edu -s sourcedir -d dc.description.other"); pr(" adding bitstreams: ItemUpdate -e jsmith@mit.edu -s sourcedir -A -i dc.identifier"); pr(" deleting bitstreams: ItemUpdate -e jsmith@mit.edu -s sourcedir -D ORIGINAL "); pr(""); System.exit(0); } if (line.hasOption('v')) { verbose = true; } if (line.hasOption('P')) { alterProvenance = false; pr("Suppressing changes to Provenance field option"); } iu.eperson = line.getOptionValue('e'); // db ID or email if (!line.hasOption('s')) // item specific changes from archive dir { pr("Missing source archive option"); System.exit(1); } String sourcedir = line.getOptionValue('s'); if (line.hasOption('t')) //test { isTest = true; pr("**Test Run** - not actually updating items."); } if (line.hasOption('i')) { itemField = line.getOptionValue('i'); } if (line.hasOption('d')) { String[] targetFields = line.getOptionValues('d'); DeleteMetadataAction delMetadataAction = (DeleteMetadataAction) iu.actionMgr .getUpdateAction(DeleteMetadataAction.class); delMetadataAction.addTargetFields(targetFields); //undo is an add for (String field : targetFields) { iu.undoActionList.add(" -a " + field + " "); } pr("Delete metadata for fields: "); for (String s : targetFields) { pr(" " + s); } } if (line.hasOption('a')) { String[] targetFields = line.getOptionValues('a'); AddMetadataAction addMetadataAction = (AddMetadataAction) iu.actionMgr .getUpdateAction(AddMetadataAction.class); addMetadataAction.addTargetFields(targetFields); //undo is a delete followed by an add of a replace record for target fields for (String field : targetFields) { iu.undoActionList.add(" -d " + field + " "); } for (String field : targetFields) { iu.undoActionList.add(" -a " + field + " "); } pr("Add metadata for fields: "); for (String s : targetFields) { pr(" " + s); } } if (line.hasOption('D')) // undo not supported { pr("Delete bitstreams "); String[] filterNames = line.getOptionValues('D'); if ((filterNames != null) && (filterNames.length > 1)) { pr("Error: Only one filter can be a used at a time."); System.exit(1); } String filterName = line.getOptionValue('D'); pr("Filter argument: " + filterName); if (filterName == null) // indicates using delete_contents files { DeleteBitstreamsAction delAction = (DeleteBitstreamsAction) iu.actionMgr .getUpdateAction(DeleteBitstreamsAction.class); delAction.setAlterProvenance(alterProvenance); } else { // check if param is on ALIAS list String filterClassname = filterAliases.get(filterName); if (filterClassname == null) { filterClassname = filterName; } BitstreamFilter filter = null; try { Class<?> cfilter = Class.forName(filterClassname); pr("BitstreamFilter class to instantiate: " + cfilter.toString()); filter = (BitstreamFilter) cfilter.newInstance(); //unfortunate cast, an erasure consequence } catch (Exception e) { pr("Error: Failure instantiating bitstream filter class: " + filterClassname); System.exit(1); } String filterPropertiesName = line.getOptionValue('F'); if (filterPropertiesName != null) //not always required { try { // TODO try multiple relative locations, e.g. source dir if (!filterPropertiesName.startsWith("/")) { filterPropertiesName = sourcedir + File.separator + filterPropertiesName; } filter.initProperties(filterPropertiesName); } catch (Exception e) { pr("Error: Failure finding properties file for bitstream filter class: " + filterPropertiesName); System.exit(1); } } DeleteBitstreamsByFilterAction delAction = (DeleteBitstreamsByFilterAction) iu.actionMgr .getUpdateAction(DeleteBitstreamsByFilterAction.class); delAction.setAlterProvenance(alterProvenance); delAction.setBitstreamFilter(filter); //undo not supported } } if (line.hasOption('A')) { pr("Add bitstreams "); AddBitstreamsAction addAction = (AddBitstreamsAction) iu.actionMgr .getUpdateAction(AddBitstreamsAction.class); addAction.setAlterProvenance(alterProvenance); iu.undoActionList.add(" -D "); // delete_contents file will be written, no arg required } if (!iu.actionMgr.hasActions()) { pr("Error - an action must be specified"); System.exit(1); } else { pr("Actions to be performed: "); for (UpdateAction ua : iu.actionMgr) { pr(" " + ua.getClass().getName()); } } pr("ItemUpdate - initializing run on " + (new Date()).toString()); context = new Context(); iu.setEPerson(context, iu.eperson); context.setIgnoreAuthorization(true); HANDLE_PREFIX = ConfigurationManager.getProperty("handle.canonical.prefix"); if (HANDLE_PREFIX == null || HANDLE_PREFIX.length() == 0) { HANDLE_PREFIX = "http://hdl.handle.net/"; } iu.processArchive(context, sourcedir, itemField, metadataIndexName, alterProvenance, isTest); context.complete(); // complete all transactions context.setIgnoreAuthorization(false); } catch (Exception e) { if (context != null && context.isValid()) { context.abort(); context.setIgnoreAuthorization(false); } e.printStackTrace(); pr(e.toString()); status = 1; } if (isTest) { pr("***End of Test Run***"); } else { pr("End."); } System.exit(status); }
From source file:org.duracloud.chunk.FileChunkerDriver.java
private static Options getOptions() { Option username = new Option("u", "username", true, "username of duracloud instance"); username.setArgs(1);/*from w w w . j a v a 2 s. c o m*/ username.setArgName("username"); Option password = new Option("p", "password", true, "password of duracloud instance"); password.setArgs(1); password.setArgName("password"); Option create = new Option("g", "generate", true, "generate test data to <outFile> of " + "<size> bytes"); create.setArgs(2); create.setArgName("outFile numBytes"); create.setValueSeparator(' '); Option add = new Option("a", "add", true, "add content from dir:<f> to space:<t> of max" + " chunk size:<s> in units of K,M,G"); add.setArgs(3); add.setArgName("f t s{K|M|G}"); add.setValueSeparator(' '); Option fileFiltered = new Option("f", "file-filter", true, "limit processed files to those " + "listed in file-list:<l>"); fileFiltered.setArgs(1); fileFiltered.setArgName("l"); Option dirFiltered = new Option("d", "dir-filter", true, "limit processed directories to " + "those listed in file-list:<l>"); dirFiltered.setArgs(1); dirFiltered.setArgName("l"); Option cloud = new Option("c", "cloud-store", true, "use cloud store found at <host>:<port> " + "as content dest"); cloud.setArgs(2); cloud.setArgName("host:port"); cloud.setValueSeparator(':'); Option excludeChunkMD5s = new Option("x", "exclude-chunk-md5s", false, "if this option is set, chunk " + "MD5s will NOT be preserved " + "in the manifest"); Option ignoreLargeFiles = new Option("i", "ignore-large-files", false, "if this option is set, files " + "over the chunk size " + "specified in the 'add' " + "option will be ignored."); Options options = new Options(); options.addOption(username); options.addOption(password); options.addOption(create); options.addOption(add); options.addOption(fileFiltered); options.addOption(dirFiltered); options.addOption(cloud); options.addOption(excludeChunkMD5s); options.addOption(ignoreLargeFiles); return options; }
From source file:org.duracloud.mill.ltp.bit.LoopingBitIntegrityTaskProducerCommandLineOptions.java
/** * //from w w w . j a v a2 s . c o m */ public LoopingBitIntegrityTaskProducerCommandLineOptions() { super(); Option exlucsionsList = new Option(EXCLUSION_LIST_OPTION, "exclusion-list", true, "A file containing exclusions as regular expressions, one expression per line." + "Expressions will be matched against the following path: /{account}/{storeId}/{spaceId}"); exlucsionsList.setArgs(1); exlucsionsList.setArgName("file"); addOption(exlucsionsList); Option inclusionList = new Option(INCLUSION_LIST_OPTION, "inclusion-list", true, "A file containing inclusions as regular expressions, one expression per line." + "Expressions will be matched against the following path: /{account}/{storeId}/{spaceId}"); inclusionList.setArgs(1); inclusionList.setArgName("file"); addOption(inclusionList); }
From source file:org.duracloud.mill.ltp.dup.DuplicationOptions.java
public DuplicationOptions() { super();/*w w w. j a v a2 s .c o m*/ Option localDuplicationDir = new Option(LOCAL_DUPLICATION_DIR_OPTION, "local-duplication-dir", true, "Indicates that a local duplication policy " + "directory should be used."); localDuplicationDir.setArgs(1); localDuplicationDir.setArgName("file"); addOption(localDuplicationDir); Option policyBucketSuffix = new Option(POLICY_BUCKET_SUFFIX, "policy-bucket-suffix", true, "The last portion of the name of the S3 bucket where " + "duplication policies can be found."); policyBucketSuffix.setRequired(false); addOption(policyBucketSuffix); }
From source file:org.duracloud.mill.taskproducertool.Driver.java
private static Options getOptions() { Options options = new Options(); Option subdomain = new Option("s", "subdomain", true, "A duracloud subdomain"); subdomain.setArgs(1);// w w w .j a v a 2 s . c om subdomain.setArgName("subdomain"); subdomain.setRequired(true); options.addOption(subdomain); Option queue = new Option("q", "queue", true, "A task queue name"); queue.setArgs(1); queue.setArgName("queue"); queue.setRequired(true); options.addOption(queue); Option username = new Option("u", "username", true, "The queue service username"); username.setArgs(1); username.setArgName("username"); options.addOption(username); Option password = new Option("p", "password", true, "The queue service password"); password.setArgs(1); password.setArgName("password"); options.addOption(password); Option type = new Option("t", "type", true, "The type of operation: NOOP, DUP, BIT, AUDIT"); type.setArgs(1); type.setArgName("type"); type.setRequired(true); options.addOption(type); Option sourceStorageProviderId = new Option("a", "source-provider-id", true, "The id of the source storage provider"); sourceStorageProviderId.setArgs(1); sourceStorageProviderId.setArgName("id"); options.addOption(sourceStorageProviderId); Option destStorageProviderId = new Option("b", "dest-provider-id", true, "The id of the destination storage provider"); destStorageProviderId.setArgs(1); destStorageProviderId.setArgName("id"); options.addOption(destStorageProviderId); Option spaceId = new Option("d", "space-id", true, "The id of the space"); spaceId.setArgs(1); spaceId.setArgName("spaceId"); options.addOption(spaceId); Option contentId = new Option("c", "content-id", true, "The id of the source content"); contentId.setArgs(1); contentId.setArgName("contentId"); options.addOption(contentId); Option contentIdFile = new Option("f", "content-id-file", true, "A file containing a list of content ids"); contentIdFile.setArgs(1); contentIdFile.setArgName("content-id-file"); options.addOption(contentIdFile); return options; }
From source file:org.duracloud.mill.taskreadertool.Driver.java
private static Options getOptions() { Options options = new Options(); Option queue = new Option("q", "queue", true, "A task queue name"); queue.setArgs(1);// www . j a va 2 s . c om queue.setArgName("queue"); queue.setRequired(true); options.addOption(queue); Option username = new Option("u", "username", true, "The queue service username"); username.setArgs(1); username.setArgName("username"); queue.setRequired(true); options.addOption(username); Option password = new Option("p", "password", true, "The queue service password"); password.setArgs(1); password.setArgName("password"); queue.setRequired(true); options.addOption(password); Option output = new Option("o", "output-file-name", true, "The name of the output file"); password.setArgs(1); password.setArgName("output"); options.addOption(output); Option delete = new Option("d", "delete", false, "Indicates that items read from the queue should be deleted"); options.addOption(delete); return options; }
From source file:org.duracloud.mill.util.CommonCommandLineOptions.java
public CommonCommandLineOptions() { super();//from www. j a v a 2 s. c o m Option configFile = new Option(CONFIG_FILE_OPTION, "config-file", true, "A properties file containing configuration info"); configFile.setArgs(1); configFile.setArgName("file"); configFile.setRequired(true); addOption(configFile); }
From source file:org.duracloud.sync.config.SyncToolConfigParser.java
/** * Creates a parser for command line configuration options. *//*from w w w . j a v a 2s . c om*/ public SyncToolConfigParser() { cmdLineUtil = new CommandLineToolUtil(); // Command Line Options cmdOptions = new Options(); Option hostOption = new Option("h", "host", true, "the host address of the DuraCloud " + "DuraStore application"); hostOption.setRequired(true); cmdOptions.addOption(hostOption); Option portOption = new Option("r", "port", true, "the port of the DuraCloud DuraStore application " + "(optional, default value is " + DEFAULT_PORT + ")"); portOption.setRequired(false); cmdOptions.addOption(portOption); Option usernameOption = new Option("u", "username", true, "the username necessary to perform writes to DuraStore"); usernameOption.setRequired(true); cmdOptions.addOption(usernameOption); Option passwordOption = new Option("p", "password", true, "the password necessary to perform writes to DuraStore; NOTICE: " + "if no password is specified in the command line the sync tool will " + "look for an environment variable named " + CommandLineToolUtil.PASSWORD_ENV_VARIABLE_NAME + " containing the password. Finally, if this environment variable " + "does not exist the user will be prompted for the password."); passwordOption.setRequired(false); cmdOptions.addOption(passwordOption); Option storeIdOption = new Option("i", "store-id", true, "the Store ID for the DuraCloud storage provider"); storeIdOption.setRequired(false); cmdOptions.addOption(storeIdOption); Option spaceId = new Option("s", "space-id", true, "the ID of the DuraCloud space where content " + "will be stored"); spaceId.setRequired(true); cmdOptions.addOption(spaceId); Option workDirOption = new Option("w", "work-dir", true, "the state of the sync tool is persisted to " + "this directory (optional, default value is " + "duracloud-sync-work directory in user home)"); workDirOption.setRequired(false); cmdOptions.addOption(workDirOption); Option contentDirs = new Option("c", "content-dirs", true, "the directory paths to monitor and sync with DuraCloud"); contentDirs.setRequired(true); contentDirs.setArgs(Option.UNLIMITED_VALUES); cmdOptions.addOption(contentDirs); Option pollFrequency = new Option("f", "poll-frequency", true, "the time (in ms) to wait between each poll of the " + "sync-dirs (optional, default value is " + DEFAULT_POLL_FREQUENCY + ")"); pollFrequency.setRequired(false); cmdOptions.addOption(pollFrequency); Option numThreads = new Option("t", "threads", true, "the number of threads in the pool used to manage " + "file transfers (optional, default value is " + DEFAULT_NUM_THREADS + ")"); numThreads.setRequired(false); cmdOptions.addOption(numThreads); Option maxFileSize = new Option("m", "max-file-size", true, "the maximum size of a stored file in GB (value must " + "be between 1 and 5), larger files will be split into " + "pieces (optional, default value is " + DEFAULT_MAX_FILE_SIZE + ")"); maxFileSize.setRequired(false); cmdOptions.addOption(maxFileSize); Option renameUpdates = new Option("n", "rename-updates", true, "indicates that updates should be synced to the cloud and renamed. " + "Specify an optional suffix to override default " + "( \"" + SyncToolConfig.DEFAULT_UPDATE_SUFFIX + "\"); " + "To prevent updates altogether, see option -o. " + "(optional, not set by default)"); renameUpdates.setRequired(false); renameUpdates.setArgName("suffix"); renameUpdates.setOptionalArg(true); cmdOptions.addOption(renameUpdates); Option syncUpdates = new Option("o", "no-update", false, "indicates that changed files should not be updated; " + "to perform updates without overwriting, see option -n. " + "(optional, not set by default)"); syncUpdates.setRequired(false); cmdOptions.addOption(syncUpdates); Option syncDeletes = new Option("d", "sync-deletes", false, "indicates that deletes performed on files within the " + "sync directories should also be performed on those " + "files in DuraCloud; if this option is not included " + "all deletes are ignored (optional, not set by default)"); syncDeletes.setRequired(false); cmdOptions.addOption(syncDeletes); Option cleanStart = new Option("l", "clean-start", false, "indicates that the sync tool should perform a clean " + "start, ensuring that all files in all content " + "directories are checked against DuraCloud, even if " + "those files have not changed locally since the last " + "run of the sync tool. (optional, not set by default)"); cleanStart.setRequired(false); cmdOptions.addOption(cleanStart); Option jumpStart = new Option("j", "jump-start", false, "indicates that the sync tool should not attempt to " + "check if content to be synchronized is already in " + "DuraCloud, but should instead transfer all content. " + "This option is best used for new data sets. " + "(optional, not set by default)"); jumpStart.setRequired(false); cmdOptions.addOption(jumpStart); Option exitOnCompletion = new Option("x", "exit-on-completion", false, "indicates that the sync tool should exit once it has " + "completed a scan of the content directories and synced " + "all files; if this option is included, the sync tool " + "will not continue to monitor the sync dirs " + "(optional, not set by default)"); exitOnCompletion.setRequired(false); cmdOptions.addOption(exitOnCompletion); Option excludeOption = new Option("e", "exclude", true, "file which provides a list of files and/or " + "directories to exclude from the sync (one file or " + "directory name rule per line)"); excludeOption.setRequired(false); cmdOptions.addOption(excludeOption); Option prefixOption = new Option("a", "prefix", true, "a prefix that is added to the beginning of the ID of " + "each content item that is stored in DuraCloud. For " + "example, a prefix value of 'a/b/c/' with a content " + "item whose path is 'dir1/file.txt' would result in " + "the file stored in DuraCloud as 'a/b/c/dir1/file.txt " + "(optional)"); prefixOption.setRequired(false); cmdOptions.addOption(prefixOption); // Options to use Backup Config configFileOptions = new Options(); Option configFileOption = new Option("g", "config-file", true, "read configuration from this file (a file containing " + "the most recently used configuration can be found in " + "the work-dir, named " + BACKUP_FILE_NAME + ")"); configFileOption.setRequired(true); configFileOptions.addOption(configFileOption); }
From source file:org.eclipse.jubula.app.autagent.AutAgentApplication.java
/** * method to create an options object, filled with all options * * @return the options/*from w w w.jav a 2s . co m*/ */ private static Options createOptions() { Options options = new Options(); Option portOption = new Option(COMMANDLINE_OPTION_PORT, true, Messages.CommandlineOptionPort); portOption.setArgName(COMMANDLINE_PORT); options.addOption(portOption); options.addOption(COMMANDLINE_OPTION_LENIENT, false, Messages.CommandlineOptionLenient); options.addOption(COMMANDLINE_OPTION_HELP, false, Messages.CommandlineOptionHelp); OptionGroup verbosityOptions = new OptionGroup(); verbosityOptions.addOption(new Option(COMMANDLINE_OPTION_QUIET, false, Messages.CommandlineOptionQuiet)); verbosityOptions .addOption(new Option(COMMANDLINE_OPTION_VERBOSE, false, Messages.CommandlineOptionVerbose)); options.addOptionGroup(verbosityOptions); OptionGroup startStopOptions = new OptionGroup(); startStopOptions.addOption(new Option(COMMANDLINE_OPTION_START, false, Messages.CommandlineOptionStart)); OptionBuilder.hasOptionalArg(); Option stopOption = OptionBuilder.create(COMMANDLINE_OPTION_STOP); stopOption.setDescription(NLS.bind(Messages.OptionStopDescription, DEFAULT_HOSTNAME_LOCALHOST)); stopOption.setArgName(HOSTNAME); startStopOptions.addOption(stopOption); options.addOptionGroup(startStopOptions); return options; }
From source file:org.eclipse.jubula.app.autrun.AutRunApplication.java
/** * @return the command line options available when invoking the main method. *///from w w w . ja v a2s .c o m private static Options createCmdLineOptions() { Options options = new Options(); Option autAgentHostOption = new Option(OPT_AUT_AGENT_HOST, true, NLS.bind(Messages.infoAutAgentHost, DEFAULT_AUT_AGENT_HOST)); autAgentHostOption.setLongOpt(OPT_AUT_AGENT_HOST_LONG); autAgentHostOption.setArgName(HOSTNAME); options.addOption(autAgentHostOption); Option autAgentPortOption = new Option(OPT_AUT_AGENT_PORT, true, NLS.bind(Messages.infoAutAgentPort, DEFAULT_AUT_AGENT_PORT)); autAgentPortOption.setLongOpt(OPT_AUT_AGENT_PORT_LONG); autAgentPortOption.setArgName(PORT); options.addOption(autAgentPortOption); OptionGroup autToolkitOptionGroup = new OptionGroup(); autToolkitOptionGroup.addOption(new Option(TK_SWING, Messages.infoSwingToolkit)); autToolkitOptionGroup.addOption(new Option(TK_SWT, Messages.infoSwtToolkit)); autToolkitOptionGroup.addOption(new Option(TK_RCP, Messages.infoRcpToolkit)); autToolkitOptionGroup.setRequired(true); options.addOptionGroup(autToolkitOptionGroup); Option autIdOption = new Option(OPT_AUT_ID, true, Messages.infoAutId); autIdOption.setLongOpt(OPT_AUT_ID_LONG); autIdOption.setArgName(ID); autIdOption.setRequired(true); options.addOption(autIdOption); Option nameTechnicalComponentsOption = new Option(OPT_NAME_TECHNICAL_COMPONENTS, true, Messages.infoGenerateTechnicalComponentNames); nameTechnicalComponentsOption.setLongOpt(OPT_NAME_TECHNICAL_COMPONENTS_LONG); nameTechnicalComponentsOption.setArgName(TRUE_FALSE); options.addOption(nameTechnicalComponentsOption); Option keyboardLayoutOption = new Option(OPT_KEYBOARD_LAYOUT, true, Messages.infoKbLayout); keyboardLayoutOption.setLongOpt(OPT_KEYBOARD_LAYOUT_LONG); keyboardLayoutOption.setArgName(LOCALE); options.addOption(keyboardLayoutOption); Option workingDirOption = new Option(OPT_WORKING_DIR, true, Messages.infoAutWorkingDirectory); workingDirOption.setLongOpt(OPT_WORKING_DIR_LONG); workingDirOption.setArgName(DIRECTORY); options.addOption(workingDirOption); Option helpOption = new Option(OPT_HELP, false, Messages.infoHelp); helpOption.setLongOpt(OPT_HELP_LONG); options.addOption(helpOption); OptionBuilder.hasArgs(); Option autExecutableFileOption = OptionBuilder.create(OPT_EXECUTABLE); autExecutableFileOption.setDescription(Messages.infoExecutableFile); autExecutableFileOption.setLongOpt(OPT_EXECUTABLE_LONG); autExecutableFileOption.setRequired(true); autExecutableFileOption.setArgName(COMMAND); options.addOption(autExecutableFileOption); return options; }