List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:com.addthis.bark.ZkCmdLine.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "something helpful."); options.addOption("z", "zk", true, "zk servers,port"); options.addOption("c", "chroot", true, "chroot"); options.addOption("n", "znode", true, "znode"); options.addOption("d", "dir", true, "directory root"); options.addOption("p", "put-data", true, "directory root"); // for copying options.addOption("", "to-zk", true, "zk servers,port"); options.addOption("", "to-chroot", true, "chroot"); options.addOption("", "to-znode", true, "znode"); CommandLineParser parser = new PosixParser(); CommandLine cmdline = null; try {//w w w.j a va 2s . c o m cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); System.exit(0); } HelpFormatter formatter = new HelpFormatter(); if (cmdline.hasOption("help") || cmdline.getArgList().size() < 1) { System.out.println("commands: get jclean jcleanrecur kids grandkids"); formatter.printHelp("ZkCmdLine", options); System.exit(0); } ZkCmdLine zkcl = new ZkCmdLine(cmdline); zkcl.runCmd((String) cmdline.getArgList().get(0)); }
From source file:com.tomdoel.mpg2dcm.Xml2Dicom.java
public static void main(String[] args) { try {//from w w w .ja va2s . co m final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an endoscopic xml and video files to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Xml2Dcm xml-file dicom-output-path", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String xmlInputFileName = remainingArgs.get(0); final String dicomOutputPath = remainingArgs.get(1); EndoscopicXmlToDicomConverter.convert(new File(xmlInputFileName), dicomOutputPath); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } }
From source file:edu.ksu.cis.indus.staticanalyses.concurrency.escape.EscapeAndReadWriteCLI.java
/** * The entry point to this class./*ww w. j ava 2 s . co m*/ * * @param args command line arguments. * @throws RuntimeException when escape information and side-effect information calculation fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("h", "help", false, "Display message."); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final CommandLineParser _parser = new GnuParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { final String _cmdLineSyn = "java " + EscapeAndReadWriteCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, _options); System.exit(1); } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final EscapeAndReadWriteCLI _cli = new EscapeAndReadWriteCLI(); if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.setClassNames(_cl.getArgList()); _cli.<ITokens>execute(); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line." + _e); final String _cmdLineSyn = "java " + EscapeAndReadWriteCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, ""); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:Dcm2Txt.java
public static void main(String[] args) { CommandLine cl = parse(args); Dcm2Txt dcm2txt = new Dcm2Txt(); dcm2txt.setWithNames(!cl.hasOption("c")); if (cl.hasOption("w")) dcm2txt.setMaxWidth(parseInt(cl.getOptionValue("w"), "w", MIN_MAX_WIDTH, MAX_MAX_WIDTH)); if (cl.hasOption("l")) dcm2txt.setMaxValLen(parseInt(cl.getOptionValue("l"), "l", MIN_MAX_VAL_LEN, MAX_MAX_VAL_LEN)); File ifile = new File((String) cl.getArgList().get(0)); try {/*from ww w. jav a 2s . c o m*/ dcm2txt.dump(ifile); } catch (IOException e) { System.err.println("dcm2txt: Failed to dump " + ifile + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } }
From source file:com.aerospike.example.cache.AsACache.java
public static void main(String[] args) throws AerospikeException { try {//from w w w.j a v a 2 s . c o m Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } AsACache as = new AsACache(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:com.github.jasmo.Bootstrap.java
public static void main(String[] args) { Options options = new Options().addOption("h", "help", false, "Print help message") .addOption("v", "verbose", false, "Increase verbosity") .addOption("c", "cfn", true, "Enable 'crazy fucking names and set name length (large names == large output size)'") .addOption("p", "package", true, "Move obfuscated classes to this package") .addOption("k", "keep", true, "Don't rename this class"); try {/* w w w. ja v a 2 s.c o m*/ CommandLineParser clp = new DefaultParser(); CommandLine cl = clp.parse(options, args); if (cl.hasOption("help")) { help(options); return; } if (cl.hasOption("verbose")) { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers(); } String[] keep = cl.getOptionValues("keep"); if (cl.getArgList().size() < 2) { throw new ParseException("Expected at-least two arguments"); } log.debug("Input: {}, Output: {}", cl.getArgList().get(0), cl.getArgList().get(1)); Obfuscator o = new Obfuscator(); try { o.supply(Paths.get(cl.getArgList().get(0))); } catch (Exception e) { log.error("An error occurred while reading the source target", e); return; } try { UniqueStringGenerator usg; if (cl.hasOption("cfn")) { int size = Integer.parseInt(cl.getOptionValue("cfn")); usg = new UniqueStringGenerator.Crazy(size); } else { usg = new UniqueStringGenerator.Default(); } o.apply(new FullAccessFlags()); o.apply(new ScrambleStrings()); o.apply(new ScrambleClasses(usg, cl.getOptionValue("package", ""), keep == null ? new String[0] : keep)); o.apply(new ScrambleFields(usg)); o.apply(new ScrambleMethods(usg)); o.apply(new InlineAccessors()); o.apply(new RemoveDebugInfo()); o.apply(new ShuffleMembers()); } catch (Exception e) { log.error("An error occurred while applying transform", e); return; } try { o.write(Paths.get(cl.getArgList().get(1))); } catch (Exception e) { log.error("An error occurred while writing to the destination target", e); return; } } catch (ParseException e) { log.error("Failed to parse command line arguments", e); help(options); } }
From source file:com.aerospike.examples.BatchUpdateTTL.java
public static void main(String[] args) throws AerospikeException { try {/* w ww. j a v a2 s . co m*/ Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } BatchUpdateTTL as = new BatchUpdateTTL(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:com.aerospike.examples.pk.StorePrimaryKey.java
public static void main(String[] args) throws AerospikeException { try {// w ww. j ava2 s . c o m Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 172.28.128.6)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "172.28.128.6"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } StorePrimaryKey as = new StorePrimaryKey(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:com.netflix.exhibitor.application.ExhibitorMain.java
public static void main(String[] args) throws Exception { String hostname = Exhibitor.getHostname(); Options options = new Options(); options.addOption(null, FILESYSTEMCONFIG_DIRECTORY, true, "Directory to store Exhibitor properties (cannot be used with s3config). Exhibitor uses file system locks so you can specify a shared location so as to enable complete ensemble management. Default location is " + System.getProperty("user.dir")); options.addOption(null, FILESYSTEMCONFIG_NAME, true, "The name of the file to store config in. Used in conjunction with " + FILESYSTEMCONFIG_DIRECTORY + ". Default is " + DEFAULT_FILESYSTEMCONFIG_NAME); options.addOption(null, FILESYSTEMCONFIG_PREFIX, true, "A prefix for various config values such as heartbeats. Used in conjunction with " + FILESYSTEMCONFIG_DIRECTORY + ". Default is " + DEFAULT_FILESYSTEMCONFIG_PREFIX); options.addOption(null, FILESYSTEMCONFIG_LOCK_PREFIX, true, "A prefix for a locking mechanism. Used in conjunction with " + FILESYSTEMCONFIG_DIRECTORY + ". Default is " + DEFAULT_FILESYSTEMCONFIG_LOCK_PREFIX); options.addOption(null, S3_CREDENTIALS, true, "Optional credentials to use for s3backup or s3config. Argument is the path to an AWS credential properties file with two properties: " + PropertyBasedS3Credential.PROPERTY_S3_KEY_ID + " and " + PropertyBasedS3Credential.PROPERTY_S3_SECRET_KEY); options.addOption(null, S3_BACKUP, true, "If true, enables AWS S3 backup of ZooKeeper log files (s3credentials may be provided as well)."); options.addOption(null, S3_CONFIG, true, "Enables AWS S3 shared config files as opposed to file system config files (s3credentials may be provided as well). Argument is [bucket name]:[key]."); options.addOption(null, S3_CONFIG_PREFIX, true, "When using AWS S3 shared config files, the prefix to use for values such as heartbeats. Default is " + DEFAULT_FILESYSTEMCONFIG_PREFIX); options.addOption(null, FILESYSTEMBACKUP, true, "If true, enables file system backup of ZooKeeper log files."); options.addOption(null, TIMEOUT, true, "Connection timeout (ms) for ZK connections. Default is 30000."); options.addOption(null, LOGLINES, true, "Max lines of logging to keep in memory for display. Default is 1000."); options.addOption(null, HOSTNAME, true, "Hostname to use for this JVM. Default is: " + hostname); options.addOption(null, CONFIGCHECKMS, true, "Period (ms) to check config file. Default is: 30000"); options.addOption(null, HTTP_PORT, true, "Port for the HTTP Server. Default is: 8080"); options.addOption(null, EXTRA_HEADING_TEXT, true, "Extra text to display in UI header"); options.addOption(null, NODE_MUTATIONS, true, "If true, the Explorer UI will allow nodes to be modified (use with caution)."); options.addOption(null, JQUERY_STYLE, true, "Styling used for the JQuery-based UI. Currently available options: " + getStyleOptions()); options.addOption(null, BASIC_AUTH_REALM, true, "Basic Auth Realm to Protect the Exhibitor UI"); options.addOption(null, CONSOLE_USER, true, "Basic Auth Username to Protect the Exhibitor UI"); options.addOption(null, CONSOLE_PASSWORD, true, "Basic Auth Password to Protect the Exhibitor UI"); options.addOption(null, CURATOR_USER, true, "Basic Auth Password to Protect the cluster list api"); options.addOption(null, CURATOR_PASSWORD, true, "Basic Auth Password to Protect cluster list api"); options.addOption(ALT_HELP, HELP, false, "Print this help"); CommandLine commandLine; try {//from w ww.java 2s .co m CommandLineParser parser = new PosixParser(); commandLine = parser.parse(options, args); if (commandLine.hasOption('?') || commandLine.hasOption(HELP) || (commandLine.getArgList().size() > 0)) { printHelp(options); return; } } catch (ParseException e) { printHelp(options); return; } if (!checkMutuallyExclusive(options, commandLine, S3_BACKUP, FILESYSTEMBACKUP)) { return; } if (!checkMutuallyExclusive(options, commandLine, S3_CONFIG, FILESYSTEMCONFIG_DIRECTORY)) { return; } PropertyBasedS3Credential awsCredentials = null; if (commandLine.hasOption(S3_CREDENTIALS)) { awsCredentials = new PropertyBasedS3Credential(new File(commandLine.getOptionValue(S3_CREDENTIALS))); } BackupProvider backupProvider = null; if ("true".equalsIgnoreCase(commandLine.getOptionValue(S3_BACKUP))) { backupProvider = new S3BackupProvider(new S3ClientFactoryImpl(), awsCredentials); } else if ("true".equalsIgnoreCase(commandLine.getOptionValue(FILESYSTEMBACKUP))) { backupProvider = new FileSystemBackupProvider(); } int timeoutMs = Integer.parseInt(commandLine.getOptionValue(TIMEOUT, "30000")); int logWindowSizeLines = Integer.parseInt(commandLine.getOptionValue(LOGLINES, "1000")); int configCheckMs = Integer.parseInt(commandLine.getOptionValue(CONFIGCHECKMS, "30000")); String useHostname = commandLine.getOptionValue(HOSTNAME, hostname); int httpPort = Integer.parseInt(commandLine.getOptionValue(HTTP_PORT, "8080")); String extraHeadingText = commandLine.getOptionValue(EXTRA_HEADING_TEXT, null); boolean allowNodeMutations = "true".equalsIgnoreCase(commandLine.getOptionValue(NODE_MUTATIONS)); ConfigProvider configProvider; if (commandLine.hasOption(S3_CONFIG)) { configProvider = getS3Provider(options, commandLine, awsCredentials, useHostname); } else { configProvider = getFileSystemProvider(commandLine, backupProvider); } if (configProvider == null) { printHelp(options); return; } JQueryStyle jQueryStyle; try { jQueryStyle = JQueryStyle.valueOf(commandLine.getOptionValue(JQUERY_STYLE, "red").toUpperCase()); } catch (IllegalArgumentException e) { printHelp(options); return; } String realm = commandLine.getOptionValue(BASIC_AUTH_REALM); String user = commandLine.getOptionValue(CONSOLE_USER); String password = commandLine.getOptionValue(CONSOLE_PASSWORD); String curatorUser = commandLine.getOptionValue(CURATOR_USER); String curatorPassword = commandLine.getOptionValue(CURATOR_PASSWORD); SecurityHandler handler = null; if (notNullOrEmpty(realm) && notNullOrEmpty(user) && notNullOrEmpty(password) && notNullOrEmpty(curatorUser) && notNullOrEmpty(curatorPassword)) { handler = getSecurityHandler(realm, user, password, curatorUser, curatorPassword); } ExhibitorArguments.Builder builder = ExhibitorArguments.builder().connectionTimeOutMs(timeoutMs) .logWindowSizeLines(logWindowSizeLines).thisJVMHostname(useHostname).configCheckMs(configCheckMs) .extraHeadingText(extraHeadingText).allowNodeMutations(allowNodeMutations).jQueryStyle(jQueryStyle) .restPort(httpPort); ExhibitorMain exhibitorMain = new ExhibitorMain(backupProvider, configProvider, builder, httpPort, handler); setShutdown(exhibitorMain); exhibitorMain.start(); try { exhibitorMain.join(); } finally { exhibitorMain.close(); } }
From source file:com.cws.esolutions.security.main.UserManagementUtility.java
public static final void main(final String[] args) { final String methodName = UserManagementUtility.CNAME + "#main(final String[] args)"; if (DEBUG) {//from w w w . ja v a2 s.c o m DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", (Object) args); } if (args.length == 0) { HelpFormatter usage = new HelpFormatter(); usage.printHelp(UserManagementUtility.CNAME, options, true); return; } try { CommandLineParser parser = new PosixParser(); CommandLine commandLine = parser.parse(options, args); if (DEBUG) { DEBUGGER.debug("CommandLineParser parser: {}", parser); DEBUGGER.debug("CommandLine commandLine: {}", commandLine); DEBUGGER.debug("CommandLine commandLine.getOptions(): {}", (Object[]) commandLine.getOptions()); DEBUGGER.debug("CommandLine commandLine.getArgList(): {}", commandLine.getArgList()); } if ((commandLine.hasOption("configFile")) && (!(StringUtils.isBlank(commandLine.getOptionValue("configFile"))))) { SecurityServiceInitializer.initializeService(commandLine.getOptionValue("configFile"), UserManagementUtility.LOG_CONFIG, true); } else { SecurityServiceInitializer.initializeService(UserManagementUtility.SEC_CONFIG, UserManagementUtility.LOG_CONFIG, true); } AccountControlResponse response = null; final UserAccount userAccount = new UserAccount(); final RequestHostInfo reqInfo = new RequestHostInfo(); final SecurityConfigurationData secConfigData = UserManagementUtility.svcBean.getConfigData(); final SecurityConfig secConfig = secConfigData.getSecurityConfig(); try { reqInfo.setHostAddress(InetAddress.getLocalHost().getHostAddress()); reqInfo.setHostName(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException uhx) { reqInfo.setHostAddress("127.0.0.1"); reqInfo.setHostName("localhost"); } if (DEBUG) { DEBUGGER.debug("SecurityConfigurationData secConfig: {}", secConfigData); DEBUGGER.debug("SecurityConfig secConfig: {}", secConfig); DEBUGGER.debug("RequestHostInfo reqInfo: {}", reqInfo); } AccountControlRequest request = new AccountControlRequest(); request.setApplicationId(secConfig.getApplicationId()); request.setApplicationName(secConfig.getApplicationName()); request.setHostInfo(reqInfo); request.setRequestor(secConfig.getSvcAccount()); if (DEBUG) { DEBUGGER.debug("AccountControlRequest request: {}", request); } if (commandLine.hasOption("search")) { if (StringUtils.isEmpty(commandLine.getOptionValue("search"))) { throw new ParseException("No entry option was provided. Cannot continue."); } userAccount.setEmailAddr(commandLine.getOptionValue("search")); if (DEBUG) { DEBUGGER.debug("UserAccount userAccount: {}", userAccount); } request.setUserAccount(userAccount); if (DEBUG) { DEBUGGER.debug("AccountControlRequest: {}", request); } response = processor.searchAccounts(request); } else if (commandLine.hasOption("load")) { if (StringUtils.isEmpty(commandLine.getOptionValue("load"))) { throw new ParseException("No entry option was provided. Cannot continue."); } userAccount.setGuid(commandLine.getOptionValue("load")); request.setUserAccount(userAccount); if (DEBUG) { DEBUGGER.debug("AccountControlRequest: {}", request); } response = processor.loadUserAccount(request); } if (DEBUG) { DEBUGGER.debug("AccountControlResponse response: {}", response); } if ((response != null) && (response.getRequestStatus() == SecurityRequestStatus.SUCCESS)) { UserAccount account = response.getUserAccount(); if (DEBUG) { DEBUGGER.debug("UserAccount: {}", account); } System.out.println(account); } } catch (ParseException px) { ERROR_RECORDER.error(px.getMessage(), px); System.err.println("An error occurred during processing: " + px.getMessage()); } catch (SecurityException sx) { ERROR_RECORDER.error(sx.getMessage(), sx); System.err.println("An error occurred during processing: " + sx.getMessage()); } catch (SecurityServiceException ssx) { ERROR_RECORDER.error(ssx.getMessage(), ssx); System.err.println("An error occurred during processing: " + ssx.getMessage()); } }