List of usage examples for org.apache.commons.cli OptionGroup addOption
public OptionGroup addOption(Option option)
Option
to this group. From source file:org.nuxeo.launcher.NuxeoLauncher.java
/** * @since 5.6//from www . ja v a 2 s .co m */ protected static void initParserOptions() { if (launcherOptions == null) { launcherOptions = new Options(); // help option OptionBuilder.withLongOpt(OPTION_HELP); OptionBuilder.withDescription(OPTION_HELP_DESC); launcherOptions.addOption(OptionBuilder.create("h")); // Quiet option OptionBuilder.withLongOpt(OPTION_QUIET); OptionBuilder.withDescription(OPTION_QUIET_DESC); launcherOptions.addOption(OptionBuilder.create("q")); // Debug option OptionBuilder.withLongOpt(OPTION_DEBUG); OptionBuilder.withDescription(OPTION_DEBUG_DESC); launcherOptions.addOption(OptionBuilder.create("d")); // Debug category option OptionBuilder.withDescription(OPTION_DEBUG_CATEGORY_DESC); OptionBuilder.hasArg(); launcherOptions.addOption(OptionBuilder.create(OPTION_DEBUG_CATEGORY)); OptionGroup outputOptions = new OptionGroup(); // Hide deprecation warnings option OptionBuilder.withLongOpt(OPTION_HIDE_DEPRECATION); OptionBuilder.withDescription(OPTION_HIDE_DEPRECATION_DESC); outputOptions.addOption(OptionBuilder.create()); // XML option OptionBuilder.withLongOpt(OPTION_XML); OptionBuilder.withDescription(OPTION_XML_DESC); outputOptions.addOption(OptionBuilder.create()); // JSON option OptionBuilder.withLongOpt(OPTION_JSON); OptionBuilder.withDescription(OPTION_JSON_DESC); outputOptions.addOption(OptionBuilder.create()); launcherOptions.addOptionGroup(outputOptions); // GUI option OptionBuilder.withLongOpt(OPTION_GUI); OptionBuilder.hasArg(); OptionBuilder.withArgName("true|false"); OptionBuilder.withDescription(OPTION_GUI_DESC); launcherOptions.addOption(OptionBuilder.create()); // Package management option OptionBuilder.withLongOpt(OPTION_NODEPS); OptionBuilder.withDescription(OPTION_NODEPS_DESC); launcherOptions.addOption(OptionBuilder.create()); // Relax on target platform option OptionBuilder.withLongOpt(OPTION_RELAX); OptionBuilder.hasArg(); OptionBuilder.withArgName("true|false|ask"); OptionBuilder.withDescription(OPTION_RELAX_DESC); launcherOptions.addOption(OptionBuilder.create()); // Accept option OptionBuilder.withLongOpt(OPTION_ACCEPT); OptionBuilder.hasArg(); OptionBuilder.withArgName("true|false|ask"); OptionBuilder.withDescription(OPTION_ACCEPT_DESC); launcherOptions.addOption(OptionBuilder.create()); } }
From source file:org.objectweb.proactive.extensions.ssl.KeyStoreCreator.java
public void parseOptions(String[] args) throws Exception { Options options = new Options(); options.addOption(OPT_HELP[0], OPT_HELP[1], false, OPT_HELP[2]); options.addOption(OPT_KEYSTORE[0], OPT_KEYSTORE[1], true, OPT_KEYSTORE[2]); OptionGroup group = new OptionGroup(); group.addOption(new Option(OPT_CREATE[0], OPT_CREATE[1], false, OPT_CREATE[2])); group.addOption(new Option(OPT_UPDATE[0], OPT_UPDATE[1], false, OPT_UPDATE[2])); group.addOption(new Option(OPT_VERIFY[0], OPT_VERIFY[1], false, OPT_VERIFY[2])); options.addOptionGroup(group);// w w w . j a va 2 s. c om CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(OPT_HELP[0])) { printHelp(options); } String keyStore = null; if (cmd.hasOption(OPT_KEYSTORE[0])) { keyStore = cmd.getOptionValue(OPT_KEYSTORE[0]); } else { System.err.println("The " + OPT_KEYSTORE[1] + " option is mandatory"); return; } boolean hasAction = false; if (cmd.hasOption(OPT_CREATE[0])) { hasAction = true; if (!this.create(keyStore)) { System.exit(1); } } if (cmd.hasOption(OPT_UPDATE[0])) { hasAction = true; if (!this.update(keyStore)) { System.exit(1); } } if (cmd.hasOption(OPT_VERIFY[0])) { hasAction = true; if (!this.verify(keyStore)) { System.exit(1); } } if (!hasAction) { System.err.println("One of " + OPT_CREATE[1] + ", " + OPT_UPDATE[1] + ", " + OPT_VERIFY[1] + " has is needed\n"); printHelp(options); } } catch (ParseException e) { System.err.println(e); } }
From source file:org.openmainframe.ade.ext.main.AdeUtilMain.java
/** * Parse the input arguments//w ww .j a va 2s . c o m */ @SuppressWarnings("static-access") @Override protected void parseArgs(String[] args) throws AdeUsageException { Options options = new Options(); Option helpOpt = new Option("h", "help", false, "Print help message and exit"); options.addOption(helpOpt); Option versionOpt = OptionBuilder.withLongOpt("version").hasArg(false).isRequired(false) .withDescription("Print current Ade version (JAR) and exit").create('v'); options.addOption(versionOpt); Option dbVersionOpt = OptionBuilder.withLongOpt("db-version") .withDescription("Print current Ade DB version and exit").create('b'); options.addOption(dbVersionOpt); Option outputFileOpt = OptionBuilder.withLongOpt("output").hasArg(true).withArgName("FILE") .isRequired(false).withDescription("Output file name (where relevant)").create('o'); options.addOption(outputFileOpt); OptionGroup optGroup = new OptionGroup(); optGroup.setRequired(false); Option DumpModelDebugOpt = OptionBuilder.withLongOpt("debugPrint").hasArg(true).withArgName("MODEL FILE") .isRequired(false).withDescription("Extract a text version of a model debug information and exit") .create('d'); optGroup.addOption(DumpModelDebugOpt); Option verifyFlowOpt = OptionBuilder.withLongOpt("verifyFlow").hasArg(true).withArgName("FLOW FILE") .isRequired(false).withDescription("Verify the flow file matches the XSD standard and exit") .create('f'); optGroup.addOption(verifyFlowOpt); options.addOptionGroup(optGroup); CommandLineParser parser = new GnuParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); } catch (MissingOptionException exp) { System.out.println("Command line parsing failed. Reason: " + exp.getMessage()); System.out.println(); new HelpFormatter().printHelp(ControlDB.class.getName(), options); System.exit(0); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); throw new AdeUsageException("Argument Parsing failed", exp); } if (line.hasOption('h')) { new HelpFormatter().printHelp(this.getClass().getSimpleName(), options); System.exit(0); } if (line.hasOption(helpOpt.getLongOpt())) { new HelpFormatter().printHelp(getClass().getSimpleName(), options); } if (line.hasOption(outputFileOpt.getLongOpt())) { m_outputFile = new File(line.getOptionValue(outputFileOpt.getLongOpt())); } m_inputFile = null; m_cmd = null; if (line.hasOption('v')) { m_cmd = "version"; } if (line.hasOption('b')) { m_cmd = "db-version"; } if (line.hasOption('d')) { m_inputFile = new File(line.getOptionValue(DumpModelDebugOpt.getLongOpt())); m_cmd = "debugPrint"; } if (line.hasOption('f')) { m_inputFilename = line.getOptionValue(verifyFlowOpt.getLongOpt()); m_cmd = "verifyFlow"; } }
From source file:org.openmainframe.ade.main.AdeUtilMain.java
@SuppressWarnings("static-access") @Override/*from w w w . j a v a 2 s. c om*/ protected void parseArgs(String[] args) throws AdeException { Options options = new Options(); Option helpOpt = new Option("h", "help", false, "Print help message and exit"); options.addOption(helpOpt); Option versionOpt = OptionBuilder.withLongOpt("version").hasArg(false).isRequired(false) .withDescription("Print current Ade version (JAR) and exit").create('V'); options.addOption(versionOpt); Option dbVersionOpt = OptionBuilder.withLongOpt("db-version") .withDescription("Print current Ade DB version and exit").create(); options.addOption(dbVersionOpt); Option outputFileOpt = OptionBuilder.withLongOpt("output").hasArg(true).withArgName("FILE") .isRequired(false).withDescription("Output file name (where relevant)").create('o'); options.addOption(outputFileOpt); OptionGroup optGroup = new OptionGroup(); optGroup.setRequired(false); Option DumpModelOpt = OptionBuilder.withLongOpt("model").hasArg(true).withArgName("MODEL FILE") .isRequired(false).withDescription("Extract a text version of a model (csv) and exit").create('m'); optGroup.addOption(DumpModelOpt); Option DumpModelDebugOpt = OptionBuilder.withLongOpt("debugPrint").hasArg(true).withArgName("MODEL FILE") .isRequired(false).withDescription("Extract a text version of a model debug information and exit") .create('d'); optGroup.addOption(DumpModelDebugOpt); Option verifyFlowOpt = OptionBuilder.withLongOpt("verifyFlow").hasArg(true).withArgName("FLOW FILE") .isRequired(false).withDescription("Verify the flow file matches the XSD standard and exit") .create('f'); optGroup.addOption(verifyFlowOpt); options.addOptionGroup(optGroup); CommandLineParser parser = new GnuParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); } catch (MissingOptionException exp) { System.out.println("Command line parsing failed. Reason: " + exp.getMessage()); System.out.println(); new HelpFormatter().printHelp(ControlDB.class.getName(), options); System.exit(0); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); throw new AdeUsageException("Argument Parsing failed", exp); } if (line.hasOption(helpOpt.getLongOpt())) { new HelpFormatter().printHelp(getClass().getSimpleName(), options); closeAll(); System.exit(0); } if (line.hasOption(versionOpt.getLongOpt())) { System.out.println("Current Ade version (JAR): " + Ade.getAde().getVersion()); closeAll(); System.exit(0); } if (line.hasOption(dbVersionOpt.getLongOpt())) { System.out.println("Current Ade DB version: " + Ade.getAde().getDbVersion()); closeAll(); System.exit(0); } File outputFile = null; if (line.hasOption(outputFileOpt.getLongOpt())) { outputFile = new File(line.getOptionValue(outputFileOpt.getLongOpt())); } if (line.hasOption(DumpModelDebugOpt.getLongOpt())) { File modelFile = new File(line.getOptionValue(DumpModelDebugOpt.getLongOpt())); dumpModelDebug(modelFile, outputFile); } if (line.hasOption(verifyFlowOpt.getLongOpt())) { String flowFilename = line.getOptionValue(verifyFlowOpt.getLongOpt()); File flowFile = new File(flowFilename); try { validateGood(flowFile); } catch (Exception e) { throw new AdeUsageException("Failed when verifiying " + flowFile.getName(), e); } } }
From source file:org.orbeon.oxf.main.SecureResource.java
private void parseArgs(String[] args) { Options options = new Options(); OptionGroup group = new OptionGroup(); group.addOption(new Option("e", "encrypt", false, "Encrypt")); group.addOption(new Option("d", "decrypt", false, "Decrypt")); group.addOption(new Option("v", "view", false, "View")); options.addOptionGroup(group);/*w w w . j av a 2s . c o m*/ Option o = new Option("r", "root", true, "Resource Root"); o.setRequired(false); options.addOption(o); options.addOption("a", "archive", true, "Archive Name"); try { CommandLine cmd = new PosixParser().parse(options, args, true); if (cmd.hasOption('e')) { mode = ENCRYPT_MODE; } else if (cmd.hasOption('d')) { mode = DECRYPT_MODE; } else if (cmd.hasOption('v')) { mode = VIEW_MODE; } resourceRoot = cmd.getOptionValue('r', "."); archiveName = cmd.getOptionValue('a'); } catch (MissingArgumentException e) { new HelpFormatter().printHelp("Missing argument", options); System.exit(1); } catch (UnrecognizedOptionException e) { new HelpFormatter().printHelp("Unrecognized option", options); System.exit(1); } catch (MissingOptionException e) { new HelpFormatter().printHelp("Missing option", options); System.exit(1); } catch (Exception e) { new HelpFormatter().printHelp("Unknown error", options); System.exit(1); } }
From source file:org.ow2.proactive.authentication.crypto.CreateCredentials.java
/** * Entry point/*w w w . java 2 s .c om*/ * * @see org.ow2.proactive.authentication.crypto.Credentials * @param args arguments, try '-h' for help * @throws IOException * @throws ParseException * */ public static void main(String[] args) throws IOException, ParseException { SecurityManagerConfigurator.configureSecurityManager( CreateCredentials.class.getResource("/all-permissions.security.policy").toString()); Console console = System.console(); /** * default values */ boolean interactive = true; String pubKeyPath = null; PublicKey pubKey = null; String login = null; String pass = null; String keyfile = null; String cipher = "RSA/ECB/PKCS1Padding"; String path = Credentials.getCredentialsPath(); String rm = null; String scheduler = null; String url = null; Options options = new Options(); Option opt = new Option("h", "help", false, "Display this help"); opt.setRequired(false); options.addOption(opt); OptionGroup group = new OptionGroup(); group.setRequired(false); opt = new Option("F", "file", true, "Public key path on the local filesystem [default:" + Credentials.getPubKeyPath() + "]"); opt.setArgName("PATH"); opt.setArgs(1); opt.setRequired(false); group.addOption(opt); opt = new Option("R", "rm", true, "Request the public key to the Resource Manager at URL"); opt.setArgName("URL"); opt.setArgs(1); opt.setRequired(false); group.addOption(opt); opt = new Option("S", "scheduler", true, "Request the public key to the Scheduler at URL"); opt.setArgName("URL"); opt.setArgs(1); opt.setRequired(false); group.addOption(opt); options.addOptionGroup(group); opt = new Option("l", "login", true, "Generate credentials for this specific user, will be asked interactively if not specified"); opt.setArgName("LOGIN"); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option("p", "password", true, "Use this password, will be asked interactively if not specified"); opt.setArgName("PWD"); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option("k", "keyfile", true, "Use specified ssh private key, asked interactively if specified without PATH, not specified otherwise."); opt.setArgName("PATH"); opt.setOptionalArg(true); opt.setRequired(false); options.addOption(opt); opt = new Option("o", "output", true, "Output the resulting credentials to the specified file [default:" + path + "]"); opt.setArgName("PATH"); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option("c", "cipher", true, "Use specified cipher parameters, need to be compatible with the specified key [default:" + cipher + "]"); opt.setArgName("PARAMS"); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(newline + "ERROR : " + e.getMessage() + newline); System.out.println("type -h or --help to display help screen"); System.exit(1); } if (cmd.hasOption("help")) { displayHelp(options); } if (cmd.hasOption("file")) { pubKeyPath = cmd.getOptionValue("file"); } if (cmd.hasOption("rm")) { rm = cmd.getOptionValue("rm"); } if (cmd.hasOption("scheduler")) { scheduler = cmd.getOptionValue("scheduler"); } if (cmd.hasOption("login")) { login = cmd.getOptionValue("login"); } if (cmd.hasOption("password")) { pass = cmd.getOptionValue("password"); } if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) { keyfile = cmd.getOptionValue("keyfile"); } if (cmd.hasOption("output")) { path = cmd.getOptionValue("output"); } if (cmd.hasOption("cipher")) { cipher = cmd.getOptionValue("cipher"); } int acc = 0; if (pubKeyPath != null) { acc++; } if (scheduler != null) { url = Connection.normalize(scheduler) + "SCHEDULER"; acc++; } if (rm != null) { url = Connection.normalize(rm) + "RMAUTHENTICATION"; acc++; } if (acc > 1) { System.out.println("--rm, --scheduler and --file arguments cannot be combined."); System.out.println("try -h for help."); System.exit(1); } if (url != null) { try { Connection<AuthenticationImpl> conn = new Connection<AuthenticationImpl>(AuthenticationImpl.class) { public Logger getLogger() { return Logger.getLogger("pa.scheduler.credentials"); } }; AuthenticationImpl auth = conn.connect(url); pubKey = auth.getPublicKey(); } catch (Exception e) { System.err.println("ERROR : Could not retrieve public key from '" + url + "'"); e.printStackTrace(); System.exit(3); } System.out.println("Successfully obtained public key from " + url + newline); } else if (pubKeyPath != null) { try { pubKey = Credentials.getPublicKey(pubKeyPath); } catch (KeyException e) { System.err .println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)"); System.exit(4); } } else { System.out.println("No public key specified, attempting to retrieve it from default location."); pubKeyPath = Credentials.getPubKeyPath(); try { pubKey = Credentials.getPublicKey(pubKeyPath); } catch (KeyException e) { System.err .println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)"); System.exit(5); } } if (login != null && pass != null && (!cmd.hasOption("keyfile") || cmd.getOptionValues("keyfile") != null)) { System.out.println("Running in non-interactive mode." + newline); interactive = false; } else { System.out.println("Running in interactive mode."); } if (interactive) { System.out.println("Please enter Scheduler credentials,"); System.out.println("they will be stored encrypted on disk for future logins." + newline); System.out.print("login: "); if (login == null) { login = console.readLine(); } else { System.out.println(login); } System.out.print("password: "); if (pass == null) { pass = new String(console.readPassword()); } else { System.out.println("*******"); } System.out.print("keyfile: "); if (!cmd.hasOption("keyfile")) { System.out.println("no key file specified"); } else if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) { System.out.println(keyfile); } else { keyfile = console.readLine(); } } try { CredData credData; if (keyfile != null && keyfile.length() > 0) { byte[] keyfileContent = FileToBytesConverter.convertFileToByteArray(new File(keyfile)); credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass, keyfileContent); } else { System.out.println("--> Ignoring keyfile, credential does not contain SSH key"); credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass); } Credentials cred = Credentials.createCredentials(credData, pubKey, cipher); cred.writeToDisk(path); } catch (FileNotFoundException e) { System.err.println("ERROR : Could not retrieve ssh private key from '" + keyfile + "' (no such file)"); System.exit(6); } catch (Throwable t) { t.printStackTrace(); System.exit(7); } System.out.println("Successfully stored encrypted credentials on disk at :"); System.out.println("\t" + path); System.exit(0); }
From source file:org.ow2.proactive.resourcemanager.utils.console.ResourceManagerController.java
protected OptionGroup addCommandLineOptions(Options options) { OptionGroup actionGroup = new OptionGroup(); Option addNodesOpt = new Option("a", "addnodes", true, control + "Add nodes by their URLs"); addNodesOpt.setArgName("node URLs"); addNodesOpt.setRequired(false);/*from w w w .jav a2 s . c o m*/ addNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(addNodesOpt); Option removeNodesOpt = new Option("d", "removenodes", true, control + "Remove nodes by their URLs"); removeNodesOpt.setArgName("node URLs"); removeNodesOpt.setRequired(false); removeNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(removeNodesOpt); Option lockNodesOpt = new Option("locknodes", true, control + "Lock nodes by their URLs"); lockNodesOpt.setArgName("node URLs"); lockNodesOpt.setRequired(false); lockNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(lockNodesOpt); Option unlockNodesOpt = new Option("unlocknodes", true, control + "Unlock nodes by their URLs"); unlockNodesOpt.setArgName("node URLs"); unlockNodesOpt.setRequired(false); unlockNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(unlockNodesOpt); Option createNSOpt = new Option("cn", "createns", true, control + "Create new node sources"); createNSOpt.setArgName("names"); createNSOpt.setRequired(false); createNSOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(createNSOpt); Option infrastuctureOpt = new Option("i", "infrastructure", true, "Specify an infrastructure when node source is created"); infrastuctureOpt.setArgName("params"); infrastuctureOpt.setRequired(false); infrastuctureOpt.setOptionalArg(true); infrastuctureOpt.setArgs(Option.UNLIMITED_VALUES); options.addOption(infrastuctureOpt); Option policyOpt = new Option("p", "policy", true, "Specify a policy when node source is created"); policyOpt.setArgName("params"); policyOpt.setOptionalArg(true); policyOpt.setRequired(false); policyOpt.setArgs(Option.UNLIMITED_VALUES); options.addOption(policyOpt); Option listNodesOpt = new Option("ln", "listnodes", true, control + "List nodes handled by Resource Manager. Display is : NODESOURCE HOSTNAME STATE NODE_URL"); listNodesOpt.setRequired(false); listNodesOpt.setOptionalArg(true); listNodesOpt.setArgName("nodeSourceName"); actionGroup.addOption(listNodesOpt); Option listNSOpt = new Option("lns", "listns", false, control + "List node sources on Resource Manager. Display is : NODESOURCE TYPE"); listNSOpt.setRequired(false); actionGroup.addOption(listNSOpt); Option topologyOpt = new Option("t", "topology", false, control + "Displays nodes topology."); topologyOpt.setRequired(false); actionGroup.addOption(topologyOpt); Option removeNSOpt = new Option("r", "removens", true, control + "Remove given node sources"); removeNSOpt.setArgName("names"); removeNSOpt.setRequired(false); removeNSOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(removeNSOpt); Option shutdownOpt = new Option("s", "shutdown", false, control + "Shutdown Resource Manager"); shutdownOpt.setRequired(false); actionGroup.addOption(shutdownOpt); Option acopt = new Option("stats", "statistics", false, control + "Display some statistics about the Resource Manager"); acopt.setRequired(false); acopt.setArgs(0); actionGroup.addOption(acopt); acopt = new Option("ma", "myaccount", false, control + "Display current user account informations"); acopt.setRequired(false); acopt.setArgs(0); actionGroup.addOption(acopt); acopt = new Option("ua", "useraccount", false, control + "Display account information by username"); acopt.setRequired(false); acopt.setArgs(1); acopt.setArgName("username"); actionGroup.addOption(acopt); acopt = new Option("ni", "nodeinfo", true, control + "Display node information"); acopt.setRequired(false); acopt.setArgs(1); acopt.setArgName("nodeURL"); actionGroup.addOption(acopt); acopt = new Option("rc", "reloadconfig", false, control + "Reloads the resource manager permission policy and log4j config"); acopt.setRequired(false); acopt.setArgs(0); actionGroup.addOption(acopt); options.addOptionGroup(actionGroup); Option nodeSourceNameOpt = new Option("ns", "nodesource", true, control + "Specify an existing node source name for adding nodes"); nodeSourceNameOpt.setArgName("nodes URLs"); nodeSourceNameOpt.setRequired(false); nodeSourceNameOpt.setArgs(1); options.addOption(nodeSourceNameOpt); Option preeemptiveRemovalOpt = new Option("f", "force", false, control + "Do not wait for busy nodes to be freed before " + "nodes removal, node source removal and shutdown actions (-d, -r and -s)"); preeemptiveRemovalOpt.setRequired(false); options.addOption(preeemptiveRemovalOpt); Option script = new Option("sf", "script", true, control + "Execute the given javascript file with optional arguments."); script.setArgName("filePath arg1=val1 arg2=val2 ..."); script.setArgs(Option.UNLIMITED_VALUES); script.setOptionalArg(true); script.setRequired(false); options.addOption(script); script = new Option("env", "environment", true, "Execute the given script and go into interactive mode"); script.setArgName("filePath"); script.setRequired(false); script.setOptionalArg(true); options.addOption(script); Option opt = new Option("c", "credentials", true, "Path to the credentials (" + Credentials.getCredentialsPath() + ")."); opt.setRequired(false); opt.setArgs(1); options.addOption(opt); return actionGroup; }
From source file:org.ow2.proactive.scheduler.authentication.ManageUsers.java
/** * Build the command line options and parse *///from w w w . j av a 2 s . c o m private static CommandLine getCommandLine(String[] args, String loginFilePath, String groupFilePath, Options options) throws ManageUsersException { Option opt = new Option(HELP_OPTION, HELP_OPTION_NAME, false, "Display this help"); opt.setRequired(false); options.addOption(opt); OptionGroup optionGroup = new OptionGroup(); optionGroup.setRequired(false); opt = new Option(CREATE_OPTION, CREATE_OPTION_NAME, true, "Action to create a user"); opt.setArgName(CREATE_OPTION_NAME.toUpperCase()); opt.setArgs(0); opt.setRequired(false); optionGroup.addOption(opt); opt = new Option(UPDATE_OPTION, UPDATE_OPTION_NAME, true, "Action to update an existing user. Updating a user means to change the user's password or group membership."); opt.setArgName(UPDATE_OPTION_NAME.toUpperCase()); opt.setArgs(0); opt.setRequired(false); optionGroup.addOption(opt); opt = new Option(DELETE_OPTION, DELETE_OPTION_NAME, true, "Action to delete an existing user"); opt.setArgName(DELETE_OPTION_NAME.toUpperCase()); opt.setArgs(0); opt.setRequired(false); optionGroup.addOption(opt); options.addOptionGroup(optionGroup); opt = new Option(LOGIN_OPTION, LOGIN_OPTION_NAME, true, "Generate credentials for this specific user, will be asked interactively if not specified"); opt.setArgName(LOGIN_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(PWD_OPTION, PWD_OPTION_NAME, true, "Password of the user, if the user is created or updated, will be asked interactively if not specified"); opt.setArgName(PWD_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(GROUPS_OPTION, GROUPS_OPTION_NAME, true, "A comma-separated list of groups the user must be member of. Can be used when the user is created or updated"); opt.setArgName(GROUPS_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); optionGroup.setRequired(false); opt = new Option(KEYFILE_OPTION, KEYFILE_OPTION_NAME, true, "Public key path on the local filesystem [default:" + getPublicKeyFilePath() + "]"); opt.setArgName(KEYFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(LOGINFILE_OPTION, LOGINFILE_OPTION_NAME, true, "Path to the login file in use [default:" + loginFilePath + "]"); opt.setArgName(LOGINFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(GROUPFILE_OPTION, GROUPFILE_OPTION_NAME, true, "Path to the group file in use [default:" + groupFilePath + "]"); opt.setArgName(GROUPFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(SOURCE_LOGINFILE_OPTION, SOURCE_LOGINFILE_OPTION_NAME, true, "Path to a source login file, used for bulk creation or bulk update. The source login file must contain clear text passwords in the format username:password"); opt.setArgName(SOURCE_LOGINFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(SOURCE_GROUPFILE_OPTION, SOURCE_GROUPFILE_OPTION_NAME, true, "Path to a source group file, used for bulk creation or bulk update. The source group file must contain group assignements in the format username:group"); opt.setArgName(SOURCE_GROUPFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { exitWithErrorMessage(newline + e.getMessage() + newline, "type -h or --help to display help screen", null); } return cmd; }
From source file:org.ow2.proactive.scheduler.util.console.SchedulerController.java
protected OptionGroup addCommandLineOptions(Options options) { OptionGroup actionGroup = new OptionGroup(); Option opt = new Option("s", "submit", true, control + "Submit the given job XML file"); opt.setArgName("XMLDescriptor"); opt.setRequired(false);/* www . j a v a 2s.c o m*/ opt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(opt); opt = new Option("sa", "submitarchive", true, control + "Submit the given job archive"); opt.setArgName("jobarchive"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("cmd", "command", false, control + "If mentionned, -submit argument becomes a command line, ie: -submit command args..."); opt.setRequired(false); options.addOption(opt); opt = new Option("cmdf", "commandf", false, control + "If mentionned, -submit argument becomes a text file path containing command lines to schedule"); opt.setRequired(false); options.addOption(opt); opt = new Option("ss", "selectscript", true, control + "Used with -cmd or -cmdf, specify a selection script"); opt.setArgName("selectScript"); opt.setRequired(false); opt.setArgs(1); options.addOption(opt); opt = new Option("jn", "jobname", true, control + "Used with -cmd or -cmdf, specify the job name"); opt.setArgName("jobName"); opt.setRequired(false); opt.setArgs(1); options.addOption(opt); opt = new Option("pj", "pausejob", true, control + "Pause the given job (pause every non-running tasks)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("rj", "resumejob", true, control + "Resume the given job (restart every paused tasks)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("kj", "killjob", true, control + "Kill the given job (cause the job to finish)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("rmj", "removejob", true, control + "Remove the given job"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("pt", "preempttask", true, control + "Stop the given task and re-schedules it after specified delay."); opt.setArgName("jobId taskName delay"); opt.setRequired(false); opt.setArgs(3); actionGroup.addOption(opt); opt = new Option("rt", "restarttask", true, control + "Terminate the given task and re-schedules it after specified delay."); opt.setArgName("jobId taskName delay"); opt.setRequired(false); opt.setArgs(3); actionGroup.addOption(opt); opt = new Option("kt", "killtask", true, control + "Kill the given task."); opt.setArgName("jobId taskName"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("jr", "jobresult", true, control + "Get the result of the given job"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("tr", "taskresult", true, control + "Get the result of the given task"); opt.setArgName("jobId taskName [inc]"); opt.setRequired(false); opt.setArgs(3); opt.setOptionalArg(true); actionGroup.addOption(opt); opt = new Option("jo", "joboutput", true, control + "Get the output of the given job"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("to", "taskoutput", true, control + "Get the output of the given task"); opt.setArgName("jobId taskName"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("jp", "jobpriority", true, control + "Change the priority of the given job (Idle, Lowest, Low, Normal, High, Highest)"); opt.setArgName("jobId newPriority"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("js", "jobstate", true, control + "Get the current state of the given job (Also tasks description)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("lj", "listjobs", false, control + "Display the list of jobs managed by the scheduler"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("stats", "statistics", false, control + "Display some statistics about the Scheduler"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("ma", "myaccount", false, control + "Display current user account information"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("ua", "useraccount", false, control + "Display account information by username"); opt.setRequired(false); opt.setArgs(1); opt.setArgName("username"); actionGroup.addOption(opt); opt = new Option("rc", "reloadconfig", false, control + "Reloads the scheduler permission policy and log4j config"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("sf", "script", true, control + "Execute the given javascript file with optional arguments."); opt.setArgName("filePath arg1=val1 arg2=val2 ..."); opt.setRequired(false); opt.setArgs(Option.UNLIMITED_VALUES); opt.setOptionalArg(true); actionGroup.addOption(opt); opt = new Option("env", "environment", true, "Execute the given script as an environment for the interactive mode"); opt.setArgName("filePath"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("test", false, control + "Test if the Scheduler is successfully started by committing some examples"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("c", "credentials", true, "Path to the credentials (" + Credentials.getCredentialsPath() + ")."); opt.setRequired(false); opt.setOptionalArg(true); options.addOption(opt); options.addOptionGroup(actionGroup); opt = new Option("start", "schedulerstart", false, control + "Start the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("stop", "schedulerstop", false, control + "Stop the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("pause", "schedulerpause", false, control + "Pause the Scheduler (cause all non-running jobs to be paused)"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("freeze", "schedulerfreeze", false, control + "Freeze the Scheduler (cause all non-running tasks to be paused)"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("resume", "schedulerresume", false, control + "Resume the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("shutdown", "schedulershutdown", false, control + "Shutdown the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("kill", "schedulerkill", false, control + "Kill the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("lrm", "linkrm", true, control + "Reconnect a RM to the scheduler"); opt.setArgName("rmURL"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("pr", "policyreload", false, control + "Reload the policy configuration"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("p", "policy", true, control + "Change the current scheduling policy"); opt.setArgName("fullName"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("ll", "logs", true, control + "Get server logs of given job or task"); opt.setArgName("jobId [taskName]"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); options.addOptionGroup(actionGroup); return actionGroup; }
From source file:org.owasp.dependencycheck.cli.CliParser.java
/** * Adds the standard command line options to the given options collection. * * @param options a collection of command line arguments * @throws IllegalArgumentException thrown if there is an exception */// ww w . j a v a 2 s .co m @SuppressWarnings("static-access") private void addStandardOptions(final Options options) throws IllegalArgumentException { final Option help = new Option(ArgumentName.HELP_SHORT, ArgumentName.HELP, false, "Print this message."); final Option advancedHelp = OptionBuilder.withLongOpt(ArgumentName.ADVANCED_HELP) .withDescription("Print the advanced help message.").create(); final Option version = new Option(ArgumentName.VERSION_SHORT, ArgumentName.VERSION, false, "Print the version information."); final Option noUpdate = new Option(ArgumentName.DISABLE_AUTO_UPDATE_SHORT, ArgumentName.DISABLE_AUTO_UPDATE, false, "Disables the automatic updating of the CPE data."); final Option appName = OptionBuilder.withArgName("name").hasArg().withLongOpt(ArgumentName.APP_NAME) .withDescription("The name of the application being scanned. This is a required argument.") .create(ArgumentName.APP_NAME_SHORT); final Option path = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.SCAN) .withDescription("The path to scan - this option can be specified multiple times. To limit the scan" + " to specific file types *.[ext] can be added to the end of the path.") .create(ArgumentName.SCAN_SHORT); final Option props = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.PROP) .withDescription("A property file to load.").create(ArgumentName.PROP_SHORT); final Option out = OptionBuilder.withArgName("folder").hasArg().withLongOpt(ArgumentName.OUT) .withDescription("The folder to write reports to. This defaults to the current directory.") .create(ArgumentName.OUT_SHORT); final Option outputFormat = OptionBuilder.withArgName("format").hasArg() .withLongOpt(ArgumentName.OUTPUT_FORMAT) .withDescription("The output format to write to (XML, HTML, VULN, ALL). The default is HTML.") .create(ArgumentName.OUTPUT_FORMAT_SHORT); final Option verboseLog = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.VERBOSE_LOG) .withDescription("The file path to write verbose logging information.") .create(ArgumentName.VERBOSE_LOG_SHORT); final Option suppressionFile = OptionBuilder.withArgName("file").hasArg() .withLongOpt(ArgumentName.SUPPRESSION_FILE) .withDescription("The file path to the suppression XML file.").create(); //This is an option group because it can be specified more then once. final OptionGroup og = new OptionGroup(); og.addOption(path); options.addOptionGroup(og).addOption(out).addOption(outputFormat).addOption(appName).addOption(version) .addOption(help).addOption(advancedHelp).addOption(noUpdate).addOption(props).addOption(verboseLog) .addOption(suppressionFile); }