List of usage examples for org.apache.commons.cli OptionGroup OptionGroup
OptionGroup
From source file:de.moritzrupp.stockreader.Main.java
/** * initOptions/*ww w.j a va 2 s . co m*/ * <p>Initializes the options for the console application</p> */ @SuppressWarnings("static-access") private static void initOptions() { Option help = new Option("h", "help", false, "prints the help message"); Option version = new Option("v", "version", false, "prints version and license information and exists"); Option price = new Option("p", "price", false, "prints only the symbol, the date and the price of the stock"); Option csv = OptionBuilder.withArgName("FILE").withLongOpt("file") .withDescription("the path and file name to the exported file").hasArg().create("f"); Option host = OptionBuilder.withArgName("HOST").withLongOpt("host") .withDescription("the SMTP host for sending mails").hasArg().withValueSeparator('=').isRequired() .create(); Option password = OptionBuilder.withArgName("PASS").withLongOpt("password") .withDescription("the password of the mail user").hasArg().withValueSeparator('=').isRequired() .create(); Option user = OptionBuilder.withArgName("USERNAME").withLongOpt("user").withDescription("the mail user") .hasArg().withValueSeparator('=').isRequired().create(); Option from = OptionBuilder.withArgName("FROM").withLongOpt("from").withDescription("the FROM address") .hasArg().withValueSeparator('=').isRequired().create(); Option to = OptionBuilder.withArgName("TO").withLongOpt("to").withDescription("the TO address").hasArg() .withValueSeparator('=').isRequired().create(); OptionGroup mailGroup = new OptionGroup(); mailGroup.addOption(host); mailGroup.addOption(user); mailGroup.addOption(password); mailGroup.addOption(from); mailGroup.addOption(to); mailGroup.setRequired(true); options = new Options(); options.addOption(help); options.addOption(version); options.addOption(price); options.addOption(csv); options.addOptionGroup(mailGroup); formatter = new HelpFormatter(); header = "Pass the stock symbols as arguments and seperate them by spaces. At least one stock symbol is required.\n" + "Example: stockreader DBK.DE SAP.DE\n\n"; footer = "\nFor more information see http://www.moritzrupp.de."; }
From source file:esg.node.security.shell.cmds.ESGFgroupadd.java
public void doInitOptions() { OptionGroup autoGroup = new OptionGroup(); autoGroup.addOption(new Option("auto", "auto-approve", false, "Set auto approval for joining this group")); autoGroup.addOption(/* ww w .j av a 2 s. c o m*/ new Option("no_auto", "no-auto-approve", false, "Set auto approval for joining this group")); getOptions().addOptionGroup(autoGroup); OptionGroup visGroup = new OptionGroup(); visGroup.addOption(new Option("vis", "visible", false, "Sets whether this group is visible to registry")); visGroup.addOption( new Option("no_vis", "not-visible", false, "Sets whether this group is visible to registry")); getOptions().addOptionGroup(visGroup); Option description = OptionBuilder.withArgName("description").hasArg(true) .withDescription("Description of group").withLongOpt("description").create("d"); getOptions().addOption(description); Option name = OptionBuilder.withArgName("name").hasArg(true).withDescription("Description of group") .withLongOpt("name").isRequired(true).create("n"); getOptions().addOption(name); }
From source file:esg.node.security.shell.cmds.ESGFgroupmod.java
public void doInitOptions() { OptionGroup autoGroup = new OptionGroup(); autoGroup.addOption(new Option("auto", "auto-approve", false, "Set auto approval for joining this group")); autoGroup.addOption(//from w w w . ja v a 2 s . c o m new Option("no_auto", "no-auto-approve", false, "Set auto approval for joining this group")); getOptions().addOptionGroup(autoGroup); OptionGroup visGroup = new OptionGroup(); visGroup.addOption(new Option("vis", "visible", false, "Sets whether this group is visible to registry")); visGroup.addOption( new Option("no_vis", "not-visible", false, "Sets whether this group is visible to registry")); getOptions().addOptionGroup(visGroup); Option description = OptionBuilder.withArgName("description").hasArgs() .withDescription("Description of group").withLongOpt("description").create("d"); getOptions().addOption(description); Option rename = OptionBuilder.withArgName("current-name new-name").hasArgs(2) .withDescription("rename current groupname to new name").withLongOpt("rename").create("mv"); getOptions().addOption(rename); }
From source file:com.netspective.sparx.security.authenticator.SingleUserServletLoginAuthenticator.java
private Options createAuthenticatorOptions() { Options authenticatorOptions = new Options(); authenticatorOptions.addOption(/*from w w w . j a v a2 s . c o m*/ OptionBuilder.withLongOpt("help").withDescription("Print options to stdout").create('?')); authenticatorOptions.addOption(OptionBuilder.withLongOpt("user-id").hasArg().withArgName("id") .withDescription("The user id that should be used to log the user in").isRequired().create('u')); authenticatorOptions.addOption(OptionBuilder.withLongOpt("show-encrypted-password") .withDescription("Prints the encrypted version of plain-text password to stdout").create('s')); OptionGroup passwordOptionGroup = new OptionGroup(); passwordOptionGroup.setRequired(true); passwordOptionGroup.addOption(OptionBuilder.withLongOpt("plain-text-password").hasArg() .withArgName("plain-text").withDescription("The plain-text password for the user").create('p')); passwordOptionGroup.addOption(OptionBuilder.withLongOpt("encrypted-password").hasArg() .withArgName("encrypted-text").withDescription("The encrypted password for the user").create('P')); authenticatorOptions.addOptionGroup(passwordOptionGroup); return authenticatorOptions; }
From source file:net.sourceforge.czt.gnast.Gnast.java
/** * Parses the arguments from the command line. * * @return a configured GnAST builder if parsing was successful; * {@code null} otherwise./* w w w . ja va 2 s . c o m*/ * @throws NullPointerException if {@code args} is {@code null} */ @SuppressWarnings("static-access") private static GnastBuilder parseArguments(String[] args) { Options argOptions = new Options(); OptionGroup verboseOptions = new OptionGroup(); verboseOptions.addOption(OptionBuilder.withLongOpt("verbose") .withDescription("Verbose; display verbose debugging messages").create("v")); verboseOptions.addOption(OptionBuilder.withLongOpt("vverbose") .withDescription("Very verbose; more verbose debugging messages").create("vv")); verboseOptions.addOption(OptionBuilder.withLongOpt("vvverbose") .withDescription("Very very verbose; even more verbose debugging messages").create("vvv")); argOptions.addOptionGroup(verboseOptions); argOptions.addOption(OptionBuilder.withLongOpt("finalizers") .withDescription("Add AST finalisers. WARNING: ASTs will consume more memory!").create("f")); argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("destination") .withDescription("Generated files go into this directory").create("d")); argOptions.addOption(OptionBuilder.withArgName("dir1 dir2").hasArgs().withValueSeparator(',') .withLongOpt("templates").withDescription("Additional template directories").create("t")); argOptions.addOption(OptionBuilder.withArgName("file").hasArg().withLongOpt("mapping") .withDescription("XML type mapping properties file").create("m")); argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("source").withDescription( "The directory with all ZML schema files. The requested project namespace must be present, as well as all its parents.") .create("s")); argOptions.addOption(OptionBuilder.withArgName("url").hasArg().withLongOpt("namespace") .withDescription("The namespace of the project to be generated.").create("n")); // use GNU parser that allows longer option name (e.g. `-vvv`) CommandLineParser parser = new GnuParser(); CommandLine line; try { // parse the command line arguments line = parser.parse(argOptions, args); } catch (ParseException exp) { // oops, something went wrong System.err.println(exp.getMessage()); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("gnast", argOptions, true); return null; } Level verbosity = line.hasOption("v") ? Level.INFO : (line.hasOption("vv") ? Level.FINE : (line.hasOption("vvv") ? Level.FINER : Level.OFF)); String[] templates = line.getOptionValues("t"); List<URL> templateDirs = new ArrayList<URL>(); for (String path : templates) { templateDirs.add(toURL(path)); } return new GnastBuilder().verbosity(verbosity).finalizers(line.hasOption("f")) .destination(toFile(line.getOptionValue("d"))).templates(templateDirs) .mapping(toURL(line.getOptionValue("m"))).sourceSchemas(schemaDirToURL(line.getOptionValue("s"))) .namespace(line.getOptionValue("n")); }
From source file:de.uni_koblenz.ist.utilities.option_handler.OptionHandler.java
/** * The only constructor of this class. It sets the toolString and the * versionString. In this constructor the two options -h and -v are created * and added. It also ensures that only -h or -v can be set. * /*from w ww.j a v a 2 s .c o m*/ * @param toolString * the name of the tool * @param versionString * the version information of the tool */ public OptionHandler(String toolString, String versionString) { options = new Options(); optionList = new ArrayList<>(); optionGroupList = new ArrayList<>(); requiredOptions = new HashSet<>(); requiredOptionGroups = new HashSet<>(); helpFormatter = new HelpFormatter(); parserType = ParserType.GNU; this.toolString = toolString; this.versionString = versionString; Option help = new Option("h", "help", false, "(optional): print this help message."); help.setRequired(false); addOption(help); Option version = new Option("v", "version", false, "(optional): print version information"); version.setRequired(false); addOption(version); OptionGroup mainOptions = new OptionGroup(); mainOptions.setRequired(false); mainOptions.addOption(help); mainOptions.addOption(version); options.addOptionGroup(mainOptions); argumentCount = 0; argumentName = "parameter"; optionalArgument = false; }
From source file:com.example.dlp.Inspect.java
/** * Command line application to inspect data using the Data Loss Prevention API. * Supported data formats: string, file, text file on GCS, BigQuery table, and Datastore entity *//*from ww w . j a v a 2 s. c o m*/ public static void main(String[] args) throws Exception { OptionGroup optionsGroup = new OptionGroup(); optionsGroup.setRequired(true); Option stringOption = new Option("s", "string", true, "inspect string"); optionsGroup.addOption(stringOption); Option fileOption = new Option("f", "file path", true, "inspect input file path"); optionsGroup.addOption(fileOption); Option gcsOption = new Option("gcs", "Google Cloud Storage", false, "inspect GCS file"); optionsGroup.addOption(gcsOption); Option datastoreOption = new Option("ds", "Google Datastore", false, "inspect Datastore kind"); optionsGroup.addOption(datastoreOption); Option bigqueryOption = new Option("bq", "Google BigQuery", false, "inspect BigQuery table"); optionsGroup.addOption(bigqueryOption); Options commandLineOptions = new Options(); commandLineOptions.addOptionGroup(optionsGroup); Option minLikelihoodOption = Option.builder("minLikelihood").hasArg(true).required(false).build(); commandLineOptions.addOption(minLikelihoodOption); Option maxFindingsOption = Option.builder("maxFindings").hasArg(true).required(false).build(); commandLineOptions.addOption(maxFindingsOption); Option infoTypesOption = Option.builder("infoTypes").hasArg(true).required(false).build(); infoTypesOption.setArgs(Option.UNLIMITED_VALUES); commandLineOptions.addOption(infoTypesOption); Option includeQuoteOption = Option.builder("includeQuote").hasArg(true).required(false).build(); commandLineOptions.addOption(includeQuoteOption); Option bucketNameOption = Option.builder("bucketName").hasArg(true).required(false).build(); commandLineOptions.addOption(bucketNameOption); Option gcsFileNameOption = Option.builder("fileName").hasArg(true).required(false).build(); commandLineOptions.addOption(gcsFileNameOption); Option datasetIdOption = Option.builder("datasetId").hasArg(true).required(false).build(); commandLineOptions.addOption(datasetIdOption); Option tableIdOption = Option.builder("tableId").hasArg(true).required(false).build(); commandLineOptions.addOption(tableIdOption); Option projectIdOption = Option.builder("projectId").hasArg(true).required(false).build(); commandLineOptions.addOption(projectIdOption); Option datastoreNamespaceOption = Option.builder("namespace").hasArg(true).required(false).build(); commandLineOptions.addOption(datastoreNamespaceOption); Option datastoreKindOption = Option.builder("kind").hasArg(true).required(false).build(); commandLineOptions.addOption(datastoreKindOption); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(commandLineOptions, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp(Inspect.class.getName(), commandLineOptions); System.exit(1); return; } Likelihood minLikelihood = Likelihood.valueOf( cmd.getOptionValue(minLikelihoodOption.getOpt(), Likelihood.LIKELIHOOD_UNSPECIFIED.name())); int maxFindings = Integer.parseInt(cmd.getOptionValue(maxFindingsOption.getOpt(), "0")); boolean includeQuote = Boolean.parseBoolean(cmd.getOptionValue(includeQuoteOption.getOpt(), "true")); List<InfoType> infoTypesList = Collections.emptyList(); if (cmd.hasOption(infoTypesOption.getOpt())) { infoTypesList = new ArrayList<>(); String[] infoTypes = cmd.getOptionValues(infoTypesOption.getOpt()); for (String infoType : infoTypes) { infoTypesList.add(InfoType.newBuilder().setName(infoType).build()); } } // string inspection if (cmd.hasOption("s")) { String val = cmd.getOptionValue(stringOption.getOpt()); inspectString(val, minLikelihood, maxFindings, infoTypesList, includeQuote); } else if (cmd.hasOption("f")) { String filePath = cmd.getOptionValue(fileOption.getOpt()); inspectFile(filePath, minLikelihood, maxFindings, infoTypesList, includeQuote); // gcs file inspection } else if (cmd.hasOption("gcs")) { String bucketName = cmd.getOptionValue(bucketNameOption.getOpt()); String fileName = cmd.getOptionValue(gcsFileNameOption.getOpt()); inspectGcsFile(bucketName, fileName, minLikelihood, infoTypesList); // datastore kind inspection } else if (cmd.hasOption("ds")) { String namespaceId = cmd.getOptionValue(datastoreNamespaceOption.getOpt(), ""); String kind = cmd.getOptionValue(datastoreKindOption.getOpt()); // use default project id when project id is not specified String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId()); inspectDatastore(projectId, namespaceId, kind, minLikelihood, infoTypesList); } else if (cmd.hasOption("bq")) { String datasetId = cmd.getOptionValue(datasetIdOption.getOpt()); String tableId = cmd.getOptionValue(tableIdOption.getOpt()); // use default project id when project id is not specified String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId()); inspectBigquery(projectId, datasetId, tableId, minLikelihood, infoTypesList); } }
From source file:com.github.jmabuin.blaspark.examples.options.GeneralOptions.java
public Options initOptions() { Options privateOptions = new Options(); OptionGroup general = new OptionGroup(); // Options: h, d, s, c, j, i, l, o, b, p // Help//from www . j av a 2 s . c om Option help = new Option("h", "help", false, "Shows documentation"); general.addOption(help); privateOptions.addOptionGroup(general); // Operations OptionGroup operations = new OptionGroup(); Option dmxv = new Option("d", "dmxv", false, "Performs a distributed dense matrix dot vector operation"); operations.addOption(dmxv); Option smxv = new Option("s", "smxv", false, "Performs a distributed sparse matrix dot vector operation"); operations.addOption(smxv); Option conjGrad = new Option("c", "conjGrad", false, "Solves a system by using the conjugate gradient method"); operations.addOption(conjGrad); Option jacobi = new Option("j", "jacobi", false, "Solves a system by using the Jacobi method"); operations.addOption(jacobi); Option dmxdm = new Option("m", "dmxdm", false, "Performs a distributed dense matrix dot distributed dense matrix operation"); operations.addOption(dmxdm); privateOptions.addOptionGroup(operations); // Number of iterations for CG Option iteration = new Option("i", "iteration", true, "Number of iterations to perform the conjugate gradient method"); privateOptions.addOption(iteration); // Matrix formats OptionGroup matrixFormat = new OptionGroup(); Option pairLine = new Option("l", "pairLine", false, "The matrix format will be a IndexedRowMatrix"); matrixFormat.addOption(pairLine); Option coordinate = new Option("o", "coordinate", false, "The matrix format will be a CoordinateMatrix"); matrixFormat.addOption(coordinate); Option blocked = new Option("b", "blocked", false, "The matrix format will be a BlockMatrix"); matrixFormat.addOption(blocked); privateOptions.addOptionGroup(matrixFormat); // Partition number Option partitions = new Option("p", "partitions", true, "Number of partitions to divide the matrix"); privateOptions.addOption(partitions); // Rows and cols per block for blocked format Option rowsPerBlock = new Option(null, "rows", true, "Number of rows for block in BlockMatrix format"); privateOptions.addOption(rowsPerBlock); Option colsPerBlock = new Option(null, "cols", true, "Number of cols for block in BlockMatrix format"); privateOptions.addOption(colsPerBlock); // Alpha and beta for DMxV operation Option alpha = new Option(null, "alpha", true, "Alpha value for DMxV example"); privateOptions.addOption(alpha); Option beta = new Option(null, "beta", true, "Beta value for DMxV example"); privateOptions.addOption(beta); return privateOptions; }
From source file:gobblin.cli.JobCommand.java
private Options createCommandLineOptions() { Options options = new Options(); OptionGroup actionGroup = new OptionGroup(); actionGroup.addOption(new Option("h", HELP_OPT, false, "Shows the help message.")); actionGroup.addOption(new Option("d", DETAILS_OPT, false, "Show details about a job/task.")); actionGroup.addOption(new Option("l", LIST_OPT, false, "List jobs/tasks.")); actionGroup.addOption(new Option("p", PROPS_OPT, false, "Fetch properties with the query.")); actionGroup.setRequired(true);//from w ww. j av a2 s . com options.addOptionGroup(actionGroup); OptionGroup idGroup = new OptionGroup(); idGroup.addOption(new Option("j", NAME_OPT, true, "Find job(s) matching given job name.")); idGroup.addOption(new Option("i", ID_OPT, true, "Find the job/task with the given id.")); options.addOptionGroup(idGroup); options.addOption("n", true, "Limit the number of results returned. (default:" + DEFAULT_RESULTS_LIMIT + ")"); options.addOption("r", RECENT_OPT, false, "List the most recent jobs (instead of a list of unique jobs)"); return options; }
From source file:de.zib.chordsharp.Main.java
/** * creates the options the command line should understand * /*from w ww . j av a2 s . c om*/ * @return the options the program understands */ private static Options getOptions() { Options options = new Options(); OptionGroup group = new OptionGroup(); options.addOption(new Option("help", "print this message")); Option read = OptionBuilder.create("read"); read.setArgName("key"); read.setArgs(1); read.setDescription("read an item"); // Option read = OptionBuilder.withArgName("key").hasArg() // .withDescription("read an item").create("read"); group.addOption(read); Option write = OptionBuilder.create("write"); write.setArgName("params"); write.setArgs(2); write.setDescription("write an item: <key> <value>"); // Option write = OptionBuilder.withArgName("params").hasArgs(2) // .withDescription("write an item: <key> <value>") // .create("write"); group.addOption(write); Option publish = OptionBuilder.create("publish"); publish.setArgName("params"); publish.setArgs(2); publish.setDescription("publish a new message for a topic: <topic> <message>"); // Option publish = OptionBuilder.withArgName("params").hasArgs(2) // .withDescription( // "publish a new message for a topic: <topic> <message>") // .create("publish"); group.addOption(publish); Option subscribe = OptionBuilder.create("subscribe"); subscribe.setArgName("params"); subscribe.setArgs(2); subscribe.setDescription("subscribe to a topic: <topic> <url>"); // Option subscribe = OptionBuilder.withArgName("params").hasArgs(2) // .withDescription("subscribe to a topic: <topic> <url>").create( // "subscribe"); group.addOption(subscribe); Option unsubscribe = OptionBuilder.create("unsubscribe"); unsubscribe.setArgName("params"); unsubscribe.setArgs(2); unsubscribe.setDescription("unsubscribe from a topic: <topic> <url>"); // Option subscribe = OptionBuilder.withArgName("params").hasArgs(2) // .withDescription("unsubscribe from a topic: <topic> <url>").create( // "unsubscribe"); group.addOption(unsubscribe); Option getSubscribers = OptionBuilder.create("getsubscribers"); getSubscribers.setArgName("topic"); getSubscribers.setArgs(1); getSubscribers.setDescription("get subscribers of a topic"); // Option getSubscribers = OptionBuilder.withArgName("topic").hasArgs(1) // .withDescription("get subscribers of a topic").create( // "getsubscribers"); group.addOption(getSubscribers); options.addOption(new Option("minibench", "run mini benchmark")); options.addOptionGroup(group); return options; }