Example usage for org.apache.commons.cli OptionGroup OptionGroup

List of usage examples for org.apache.commons.cli OptionGroup OptionGroup

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionGroup OptionGroup.

Prototype

OptionGroup

Source Link

Usage

From source file:org.apache.wink.example.googledocs.CLIHelper.java

@SuppressWarnings("static-access")
public CLIHelper() {

    Option userOption = OptionBuilder.withArgName("user").hasArg()
            .withDescription("Full username. Example: user@gmail.com").isRequired(true).withLongOpt("user")
            .create(USER_OPT);//w w  w . ja v  a  2  s. c o  m
    Option passwordOption = OptionBuilder.withArgName("password").isRequired(true).hasArg()
            .withDescription("Password").withLongOpt("password").create(PASSWORD_OPT);
    Option uploadFileOption = OptionBuilder.withArgName("file").isRequired(false).hasArg()
            .withDescription("Path to a file to upload").withLongOpt("upload").create(UPLOAD_FILE_OPT);
    Option listFilesOption = OptionBuilder.hasArg(false).withDescription("List files").withLongOpt("list")
            .create(LIST_OPT);
    Option deleteOption = OptionBuilder.withArgName("document id").hasArg(true)
            .withDescription("Delete document. Use --list to get a document id.").withLongOpt("delete")
            .create(DELETE_OPT);
    Option proxyHostOption = OptionBuilder.isRequired(false).withArgName("host").hasArg(true)
            .withDescription("Proxy host").withLongOpt("proxy").create(PROXY_HOST_ORT);
    Option proxyPortOption = OptionBuilder.isRequired(false).withArgName("port").hasArg(true)
            .withDescription("Proxy port").withLongOpt("port").create(PROXY_PORT_OPT);

    OptionGroup group = new OptionGroup();
    group.setRequired(true);
    group.addOption(uploadFileOption);
    group.addOption(listFilesOption);
    group.addOption(deleteOption);

    options.addOptionGroup(group);
    options.addOption(proxyHostOption);
    options.addOption(proxyPortOption);
    options.addOption(passwordOption);
    options.addOption(userOption);
}

From source file:org.apache.zookeeper.cli.DelQuotaCommand.java

public DelQuotaCommand() {
    super("delquota", "[-n|-b] path");

    OptionGroup og1 = new OptionGroup();
    og1.addOption(new Option("b", false, "bytes quota"));
    og1.addOption(new Option("n", false, "num quota"));
    options.addOptionGroup(og1);//from  www .  j  av a 2  s  . c om
}

From source file:org.apache.zookeeper.cli.SetQuotaCommand.java

public SetQuotaCommand() {
    super("setquota", "-n|-b val path");

    OptionGroup og1 = new OptionGroup();
    og1.addOption(new Option("b", true, "bytes quota"));
    og1.addOption(new Option("n", true, "num quota"));
    og1.setRequired(true);/*w  ww .ja  v  a2  s.c om*/
    options.addOptionGroup(og1);
}

From source file:org.blue.star.plugins.check_ping.java

public void add_command_arguments(Options options) {
    Option p = new Option("p", "packets", true,
            "number of ICMP ECHO packets to send (Default: " + DEFAULT_MAX_PACKETS + ")");
    p.setArgName("packets");
    options.addOption(p);/*from  ww  w  .j  a  v  a2s.  c  o m*/
    Option w = new Option("w", "warning", true, "warning threshold pair (round trip average, % packets lost)");
    w.setArgName("<wrta>,<wpl>%");
    options.addOption(w);
    Option c = new Option("c", "critical", true,
            "critical threshold pair (round trip average, % packets lost)");
    c.setArgName("<crta>,<cpl>%");
    options.addOption(c);
    OptionGroup group = new OptionGroup();
    group.addOption(new Option("4", "use-ipv4", false, "Use IPv4 connection"));
    group.addOption(new Option("6", "use-ipv6", false, "Use IPv6 connection"));
    options.addOptionGroup(group);
    options.addOption("i", "interface", true, "Select the interface name to use.");
}

From source file:org.cleanlogic.sxf4j.utils.Sxf2Pgsql.java

public static void main(String... args) {
    Options options = new Options();

    Option sridOption = new Option("s", true,
            "Set the SRID field. Defaults to detect from passport or 0. Optionally reprojects from given SRID");
    sridOption.setArgName("[<from>:]<srid>");
    options.addOption(sridOption);//from   w  w w.  j  av  a2s.  c o  m

    Option stTransformOption = new Option("t", false,
            "Use only PostGIS coordinates transform (ST_Transform), Use with -s option. Not worked with -D. Default: client side convert.");
    options.addOption(stTransformOption);

    Option geometryColumnOption = new Option("g", true, "Specify the name of the geometry/geography column");
    geometryColumnOption.setArgName("geocolumn");
    options.addOption(geometryColumnOption);

    Option pgdumpFormatOption = new Option("D", false,
            "Use postgresql dump format (COPY from stdin) (defaults to SQL insert statements).");
    options.addOption(pgdumpFormatOption);

    Option transactionOption = new Option("e", false,
            "Execute each statement individually, do not use a transaction. Not compatible with -D.");
    options.addOption(transactionOption);

    Option spatialIndexOption = new Option("I", false, "Create a spatial index on the geocolumn.");
    options.addOption(spatialIndexOption);

    Option geometryTypeOption = new Option("w", false,
            "Output WKT instead of WKB.  Note that this can result in coordinate drift.");
    options.addOption(geometryTypeOption);

    Option encodingOption = new Option("W", true,
            "Specify the character encoding of SXF attribute column. (default: \"UTF-8\")");
    encodingOption.setArgName("encoding");
    options.addOption(encodingOption);

    Option tablespaceTableOption = new Option("T", true,
            "Specify the tablespace for the new table. Note that indexes will still use the default tablespace unless the -X flag is also used.");
    tablespaceTableOption.setArgName("tablespace");
    options.addOption(tablespaceTableOption);

    Option tablespaceIndexOption = new Option("X", true,
            "Specify the tablespace for the table's indexes. This applies to the primary key, and the spatial index if the -I flag is used.");
    tablespaceIndexOption.setArgName("tablespace");
    options.addOption(tablespaceIndexOption);

    Option helpOption = new Option("h", "help", false, "Display this help screen.");
    options.addOption(helpOption);

    OptionGroup optionGroup = new OptionGroup();

    Option dropTableOption = new Option("d", false,
            "Drops the table, then recreates it and populates it with current shape file data.");
    optionGroup.addOption(dropTableOption);

    Option createTableOption = new Option("c", false,
            "Creates a new table and populates it, this is the default if you do not specify any options.");
    optionGroup.addOption(createTableOption);

    options.addOptionGroup(optionGroup);

    CommandLineParser commandLineParser = new DefaultParser();
    HelpFormatter helpFormatter = new HelpFormatter();
    CommandLine commandLine;

    try {
        commandLine = commandLineParser.parse(options, args);

        if (commandLine.hasOption("help") || commandLine.getArgList().size() == 0) {
            helpFormatter.printHelp("sxf2pgsql [<options>] <sxfile|dir> [[<schema>.]<table>]", options);
            return;
        }

        if (commandLine.hasOption('s')) {
            String srid = commandLine.getOptionValue('s');
            String[] sridPair = srid.split(":");
            if (sridPair.length == 2) {
                sxf2PgsqlOptions.srcSRID = Integer.parseInt(sridPair[0]);
                sxf2PgsqlOptions.dstSRID = Integer.parseInt(sridPair[1]);
            } else if (sridPair.length == 1) {
                sxf2PgsqlOptions.dstSRID = Integer.parseInt(srid);
            }
        }
        sxf2PgsqlOptions.stTransform = commandLine.hasOption('t');
        sxf2PgsqlOptions.dropTable = commandLine.hasOption('d');
        if (commandLine.hasOption('g')) {
            sxf2PgsqlOptions.geocolumnName = commandLine.getOptionValue('g');
        }
        sxf2PgsqlOptions.pgdumpFormat = commandLine.hasOption('D');
        sxf2PgsqlOptions.transaction = !commandLine.hasOption('e');
        sxf2PgsqlOptions.spatialIndex = commandLine.hasOption('I');
        if (commandLine.hasOption('w')) {
            sxf2PgsqlOptions.geometryFormat = "WKT";
        }
        if (commandLine.hasOption('W')) {
            sxf2PgsqlOptions.encoding = commandLine.getOptionValue('W');
        }

        List<File> files = new ArrayList<>();
        if (commandLine.getArgList().size() > 0) {
            File file = new File(commandLine.getArgList().get(0));

            if (file.isFile()) {
                files.add(file);
            } else if (file.isDirectory()) {
                Utils.search(file, files, ".sxf");
            }
        }
        boolean useNomenclature = true;
        if (commandLine.getArgList().size() == 2) {
            String[] schemaTablePair = commandLine.getArgList().get(1).split(".");
            if (schemaTablePair.length == 2) {
                sxf2PgsqlOptions.schemaName = schemaTablePair[0];
                sxf2PgsqlOptions.tableName = schemaTablePair[1];
            } else if (schemaTablePair.length == 0) {
                sxf2PgsqlOptions.tableName = commandLine.getArgList().get(1);
            }
            useNomenclature = false;
        }

        // Begin document
        System.out.println("SET CLIENT_ENCODING TO UTF8;");
        System.out.println("SET STANDARD_CONFORMING_STRINGS TO ON;");
        System.out.println("SET STATEMENT_TIMEOUT TO 0;");
        System.out.println("SET CLIENT_MIN_MESSAGES TO WARNING;");

        System.out.println("CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;");

        // Create schema.table at once (use from command line params)
        if (!useNomenclature && sxf2PgsqlOptions.dropTable) {
            System.out.print(dropTables());
        }
        // Single table mode
        if (!useNomenclature) {
            //                if (sxf2PgsqlOptions.transaction) {
            //                    System.out.println("BEGIN;");
            //                }
            System.out.print(createTables());
        }

        for (File file : files) {
            try {
                SXFReader sxfReader = new SXFReader(file, true, true);
                SXFPassport sxfPassport = sxfReader.getPassport();
                int srid = sxfPassport.srid();
                //
                if (!Utils.SRID_EX.containsKey(srid)) {
                    Proj4FileReader proj4FileReader = new Proj4FileReader();
                    String params[] = proj4FileReader.readParametersFromFile("EPSG", String.valueOf(srid));
                    if (params == null || params.length == 0) {
                        // Wrong srid. Force from passport.
                        srid = sxfPassport.srid(true);
                    }
                }
                //
                if (srid != 0) {
                    sxf2PgsqlOptions.srcSRID = srid;
                }
                if (!commandLine.hasOption("t")) {
                    if (sxf2PgsqlOptions.srcSRID != sxf2PgsqlOptions.dstSRID && sxf2PgsqlOptions.dstSRID != 0) {
                        coordinateTransform = createCoordinateTransform();
                    }
                }
                // Each file in separate transaction
                if (useNomenclature) {
                    sxf2PgsqlOptions.tableName = sxfPassport.getNomenclature();
                    if (sxf2PgsqlOptions.dropTable) {
                        System.out.print(dropTables());
                    }
                    if (sxf2PgsqlOptions.transaction) {
                        System.out.println("BEGIN;");
                    }
                    System.out.print(createTables());
                }
                if (!sxf2PgsqlOptions.pgdumpFormat) {
                    for (int i = 0; i < sxfReader.getCount(); i++) {
                        SXFRecord sxfRecord = sxfReader.getRecordByIncode(i);
                        if (sxfRecord.getLocal() != null) {
                            System.out.print(createInsert(sxfRecord));
                        }
                    }
                } else {
                    createCopy(sxfReader);
                }
                if (useNomenclature) {
                    if (sxf2PgsqlOptions.spatialIndex) {
                        for (Local local : Local.values()) {
                            System.out.print(createIndex(local));
                        }
                    }
                    System.out.println("END;");
                }
                coordinateTransform = null;
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                coordinateTransform = null;
            }
        }
        if (!useNomenclature) {
            if (sxf2PgsqlOptions.spatialIndex) {
                for (Local local : Local.values()) {
                    System.out.print(createIndex(local));
                }
            }
            //                if (sxf2PgsqlOptions.transaction) {
            //                    System.out.println("END;");
            //                }
        }
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        helpFormatter.printHelp("sxf2pgsql [<options>] <sxfile|dir> [[<schema>.]<table>]", options);

        System.exit(1);
    }
}

From source file:org.codesecure.dependencycheck.utils.CliParser.java

/**
 * Generates an Options collection that is used to parse the command line
 * and to display the help message.//from   www . java  2 s .co  m
 *
 * @return the command line options used for parsing the command line
 */
@SuppressWarnings("static-access")
private Options createCommandLineOptions() {
    Option help = new Option(ArgumentName.HELP_SHORT, ArgumentName.HELP, false, "print this message.");

    Option advancedHelp = new Option(ArgumentName.ADVANCED_HELP_SHORT, ArgumentName.ADVANCED_HELP, false,
            "shows additional help regarding properties file.");

    Option version = new Option(ArgumentName.VERSION_SHORT, ArgumentName.VERSION, false,
            "print the version information.");

    Option noupdate = new Option(ArgumentName.DISABLE_AUTO_UPDATE_SHORT, ArgumentName.DISABLE_AUTO_UPDATE,
            false, "disables the automatic updating of the CPE data.");

    Option appname = OptionBuilder.withArgName("name").hasArg().withLongOpt(ArgumentName.APPNAME)
            .withDescription("the name of the application being scanned.").create(ArgumentName.APPNAME_SHORT);

    Option path = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.SCAN)
            .withDescription("the path to scan - this option can be specified multiple times.")
            .create(ArgumentName.SCAN_SHORT);

    Option load = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.CPE)
            .withDescription("load the CPE xml file.").create(ArgumentName.CPE_SHORT);

    Option props = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.PROP)
            .withDescription("a property file to load.").create(ArgumentName.PROP_SHORT);

    Option out = OptionBuilder.withArgName("folder").hasArg().withLongOpt(ArgumentName.OUT)
            .withDescription("the folder to write reports to.").create(ArgumentName.OUT_SHORT);

    //TODO add the ability to load a properties file to override the defaults...

    OptionGroup og = new OptionGroup();
    og.addOption(path);
    og.addOption(load);

    Options opts = new Options();
    opts.addOptionGroup(og);
    opts.addOption(out);
    opts.addOption(appname);
    opts.addOption(version);
    opts.addOption(help);
    opts.addOption(noupdate);
    opts.addOption(props);
    opts.addOption(advancedHelp);
    return opts;
}

From source file:org.codeseed.common.config.ext.CommandLineOptionsBuilder.java

/**
 * Potentially adds an option to the supplied collection. Used by the
 * {@link #build()} method to populate an options collection.
 *
 * @param options/*from ww w.j  a va2 s. c o  m*/
 *            the current collection of options
 * @param groups
 *            mappings of argument group identifiers to groups
 * @param method
 *            the configuration method to look up
 */
protected void addOption(Options options, Map<String, OptionGroup> groups, Method method) {
    final CommandLine commandLine = method.getAnnotation(CommandLine.class);

    // Iterate over the triggers; take the first values
    String opt = null;
    String longOpt = null;
    for (String trigger : commandLine.value()) {
        if (!options.hasOption(trigger)) {
            if (opt == null && trigger.length() == 1) {
                opt = trigger;
            } else if (longOpt == null) {
                longOpt = trigger;
            }
        }
    }

    // Either we can use the method name or there is no option being added
    if (opt == null && longOpt == null) {
        String methodOpt = LOWER_CAMEL.to(LOWER_HYPHEN, method.getName());
        if (!options.hasOption(methodOpt)) {
            longOpt = methodOpt;
        } else {
            // TODO Warn?
            return;
        }
    }

    // Create a new option
    Option option = new Option(opt, null);
    option.setLongOpt(longOpt);

    // Set the number of arguments based on the return type
    final Class<?> returnType = Primitives.wrap(method.getReturnType());
    if (returnType.equals(Boolean.class)) {
        option.setArgs(0);
    } else if (Iterable.class.isAssignableFrom(returnType)) {
        option.setArgs(commandLine.maximum());
    } else if (Map.class.isAssignableFrom(returnType)) {
        option.setArgs(2);
        option.setValueSeparator('=');
    } else {
        option.setArgs(1);
    }

    // Add some descriptive text
    if (bundle != null) {
        try {
            // TODO Does this make sense?
            String key = option.hasLongOpt() ? option.getLongOpt() : method.getName();
            option.setDescription(bundle.getString(key + ".description"));
        } catch (MissingResourceException e) {
            option.setDescription(null);
        }
    }

    // Set argument names
    if (bundle != null && option.getArgs() > 0) {
        try {
            option.setArgName(bundle.getString(method.getName() + ".argName"));
        } catch (MissingResourceException e) {
            option.setArgName(null);
        }
    }

    // Add to either the collection or to the option groups
    String groupKey = commandLine.groupId();
    if (groupKey.isEmpty()) {
        options.addOption(option);
    } else {
        OptionGroup group = groups.get(groupKey);
        if (group == null) {
            group = new OptionGroup();
            groups.put(groupKey, group);
        }
        group.addOption(option);
    }
}

From source file:org.dataaccessioner.DataAccessioner.java

/**
 * @param args the command line arguments
 * @throws org.apache.commons.cli.ParseException
 */// ww w . j av  a 2 s .  c  o  m
public static void main(String[] args) throws ParseException {
    DataAccessioner da = new DataAccessioner();
    //Default settings
    String collectionName = "";
    String accessionNumber = "";
    String submitterName = "";
    String srcNote = "";
    String addNote = "";
    String runTime = "";

    Options options = new Options();
    options.addOption("c", true, "Collection Name (required if no GUI)");
    options.addOption("a", true, "Accession Number (required if no GUI)");
    options.addOption("n", true, "Submitter name (required if no GUI)");
    options.addOption(Option.builder().hasArg().longOpt("about-srcnote")
            .desc("Note about the source (optional)").argName("SRC NOTE").build());
    options.addOption(Option.builder().hasArg().longOpt("add-note").desc("Additional note (optional)")
            .argName("ADDL NOTE").build());
    options.addOption("u", false, "Do not start GUI; requires a source and destination");
    options.addOption("v", false, "print version information");
    options.addOption("h", false, "print this message");

    OptionGroup fitsOptions = new OptionGroup();
    fitsOptions.addOption(new Option("s", false, "Run FITS on source"));
    fitsOptions.addOption(new Option("x", false, "Don't run FITS; only copy"));
    options.addOptionGroup(fitsOptions);

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("h")) {
        printHelp(options);
        System.exit(0);
    }
    if (cmd.hasOption("v")) {
        System.out.println(DataAccessioner.VERSION);
        System.exit(0);
    }
    if (cmd.hasOption("c")) {
        collectionName = cmd.getOptionValue("c");
    }
    if (cmd.hasOption("a")) {
        accessionNumber = cmd.getOptionValue("a");
    }
    if (cmd.hasOption("n")) {
        submitterName = cmd.getOptionValue("n");
    }
    if (cmd.hasOption("about-srcnote")) {
        srcNote = cmd.getOptionValue("about-srcnote");
    }
    if (cmd.hasOption("add-note")) {
        addNote = cmd.getOptionValue("add-note");
    }

    try {
        if (cmd.hasOption("x")) {
            da.fits = null;
        } else {
            logger.info("Starting FITS");
            da.fits = new Fits();
        }
    } catch (FitsException ex) {
        System.err.println("FITS failed to initialize.");
        Exceptions.printStackTrace(ex);
    }
    //Get the destination & source
    File destination = null;
    List<File> sources = new ArrayList<File>();
    if (!cmd.getArgList().isEmpty()) {
        destination = new File((String) cmd.getArgList().remove(0));

        //validate sources or reject them
        for (Object sourceObj : cmd.getArgList()) {
            File source = new File(sourceObj.toString());
            if (source.canRead()) {
                sources.add(source);
            }
        }
    }

    if (cmd.hasOption("u")) {//Unattended
        if (collectionName.isEmpty() || accessionNumber.isEmpty() || submitterName.isEmpty()) {
            System.err.println(
                    "A collection name, a submitter name, and an accession number must be provided if not using the GUI.");
            printHelp(options);
        } else if (destination == null || !(destination.isDirectory() && destination.canWrite())) {
            String destinationStr = "<blank>";
            if (destination != null) {
                destinationStr = destination.toString();
            }
            System.err.println("Cannot run automatically. The destination (" + destinationStr
                    + ") is either not a valid or writable directory.");
            printHelp(options);
        } else if (sources.isEmpty()) {
            System.err.println("Cannot run automatically. At least one valid source is required.");
            printHelp(options);
        } else {
            HashMap<String, String> daCmdlnMetadata = new HashMap<>();
            daCmdlnMetadata.put("collectionName", collectionName);
            daCmdlnMetadata.put("accessionNumber", accessionNumber);
            daCmdlnMetadata.put("submitterName", submitterName);
            daCmdlnMetadata.put("aboutSourceNote", srcNote);
            daCmdlnMetadata.put("addNote", addNote);
            da.runUnattended(destination, sources, daCmdlnMetadata);
        }

    } else { //Start GUI
        try {
            // Set cross-platform Java L&F (also called "Metal")
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
        } catch (ClassNotFoundException e) {
            // handle exception
        } catch (InstantiationException e) {
            // handle exception
        } catch (IllegalAccessException e) {
            // handle exception
        }
        DASwingView view = new DASwingView(da);
        view.pack();
        view.setVisible(true);
    }

}

From source file:org.dcm4che.tool.common.CLIUtils.java

@SuppressWarnings("static-access")
public static void addPriorityOption(Options opts) {
    OptionGroup group = new OptionGroup();
    group.addOption(/*  w  w w . j  a va2 s.  c o m*/
            OptionBuilder.withLongOpt("prior-high").withDescription(rb.getString("prior-high")).create());
    group.addOption(OptionBuilder.withLongOpt("prior-low").withDescription(rb.getString("prior-low")).create());
    opts.addOptionGroup(group);
}

From source file:org.dcm4che.tool.common.CLIUtils.java

@SuppressWarnings("static-access")
public static void addEncodingOptions(Options opts) {
    opts.addOption(null, "group-len", false, rb.getString("group-len"));
    OptionGroup sqlenGroup = new OptionGroup();
    sqlenGroup.addOption(OptionBuilder.withLongOpt("expl-seq-len").withDescription(rb.getString("expl-seq-len"))
            .create(null));//  w w  w  .  ja va 2  s .com
    sqlenGroup.addOption(OptionBuilder.withLongOpt("undef-seq-len")
            .withDescription(rb.getString("undef-seq-len")).create(null));
    opts.addOptionGroup(sqlenGroup);
    OptionGroup itemlenGroup = new OptionGroup();
    itemlenGroup.addOption(OptionBuilder.withLongOpt("expl-item-len")
            .withDescription(rb.getString("expl-item-len")).create(null));
    itemlenGroup.addOption(OptionBuilder.withLongOpt("undef-item-len")
            .withDescription(rb.getString("undef-item-len")).create(null));
    opts.addOptionGroup(itemlenGroup);
}