Example usage for org.apache.commons.cli OptionBuilder withLongOpt

List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt

Introduction

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

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:org.eclim.plugin.adt.project.AndroidProjectManager.java

@Override
@SuppressWarnings("static-access")
public void create(IProject project, CommandLine commandLine) throws Exception {
    String[] args = commandLine.getValues(Options.ARGS_OPTION);
    GnuParser parser = new GnuParser();
    org.apache.commons.cli.Options options = new org.apache.commons.cli.Options();
    options.addOption(OptionBuilder.hasArg().isRequired().withLongOpt("target").create());
    options.addOption(OptionBuilder.hasArg().isRequired().withLongOpt("package").create());
    options.addOption(OptionBuilder.hasArg().isRequired().withLongOpt("application").create());
    options.addOption(OptionBuilder.hasArg().withLongOpt("activity").create());
    options.addOption(OptionBuilder.withLongOpt("library").create());
    org.apache.commons.cli.CommandLine cli = parser.parse(options, args);

    Sdk sdk = Sdk.getCurrent();/*ww w  .  j a  va  2s  . c  om*/

    String targetHash = cli.getOptionValue("target");
    IAndroidTarget target = sdk.getTargetFromHashString(targetHash);

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("SDK_TARGET", target);
    parameters.put("SRC_FOLDER", SdkConstants.FD_SOURCES);
    parameters.put("IS_NEW_PROJECT", true);
    parameters.put("SAMPLE_LOCATION", null);
    parameters.put("IS_LIBRARY", cli.hasOption("library"));
    parameters.put("ANDROID_SDK_TOOLS", AdtPlugin.getOsSdkToolsFolder());
    parameters.put("PACKAGE", cli.getOptionValue("package"));
    parameters.put("APPLICATION_NAME", "@string/app_name");
    parameters.put("MIN_SDK_VERSION", target.getVersion().getApiString());
    if (cli.hasOption("activity")) {
        parameters.put("ACTIVITY_NAME", cli.getOptionValue("activity"));
    }

    Map<String, String> dictionary = new HashMap<String, String>();
    dictionary.put("app_name", cli.getOptionValue("application"));

    // gross: the android NewProjectCreator expects to be the one to create the
    // project, so we have to, ug, delete the project first.
    IProjectDescription description = project.getDescription();
    project.delete(false/*deleteContent*/, true/*force*/, null/*monitor*/);

    // Would be nice to use public static create method, but it doesn't provide
    // the option for package name, activity name, app name, etc.
    //NewProjectCreator.create(
    //    new NullProgressMonitor(),
    //    project,
    //    target,
    //    null /* ProjectPopulator */,
    //    cli.hasOption("library") /* isLibrary */,
    //    null /* projectLocation */);

    NewProjectCreator creator = new NewProjectCreator(null, null);
    invoke(creator, "createEclipseProject",
            new Class[] { IProgressMonitor.class, IProject.class, IProjectDescription.class, Map.class,
                    Map.class, NewProjectCreator.ProjectPopulator.class, Boolean.TYPE, },
            new NullProgressMonitor(), project, description, parameters, dictionary, null, true);

    project.getNature(AdtConstants.NATURE_DEFAULT).configure();
}

From source file:org.eclipse.emf.mwe.core.WorkflowRunner.java

@SuppressWarnings("static-access")
protected static CommandLine getCommandLine(String[] args) throws ParseException {
    final Options options = new Options();

    options.addOption(OptionBuilder.hasArgs().withArgName("className,moreArgs").withDescription(
            "the name of a class that implements ProgressMonitor. More arguments can be appended that will be injected to the monitor,"
                    + " if it has a init(String[] args) method.")
            .withLongOpt("monitorClass").withValueSeparator(',').create(MONITOR));

    options.addOption(OptionBuilder.withLongOpt("ant").withDescription("must be set when using in Ant context")
            .create(ANT));/*ww w .  j  av a  2 s  . c  o  m*/

    final Option paramOption = OptionBuilder.withArgName("key=value")
            .withDescription("external property that is handled as workflow property").hasArgs().create(PARAM);
    paramOption.setLongOpt("param");
    options.addOption(paramOption);

    options.addOption(OptionBuilder.hasArgs().withArgName("className").withDescription(
            "the name of a class that implements a public method 'public void processCmdLine(String[] cmdLineArgs, Map paramsToUseInWorkflow, WorkflowContext ctx)'.")
            .withLongOpt("cmdLineProcessor").create(CMDL));

    final Option runnerOption = OptionBuilder.withArgName("className")
            .withDescription("WorkflowRunnerEngine class").hasArgs().create(ENGINE);
    runnerOption.setLongOpt("engine");
    options.addOption(runnerOption);

    // create the parser
    final CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args);
    return line;
}

From source file:org.eu.gasp.core.bootstrap.Runner.java

@SuppressWarnings("static-access")
public void run(String... args) throws Exception {
    // options for command line
    final Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("base").withArgName("directory").hasArg()
            .withDescription("set the base directory").create('b'));
    options.addOption(OptionBuilder.withLongOpt("log4j").withArgName("file").hasArg()
            .withDescription("path to the log4j property file").create('l'));
    options.addOption(OptionBuilder.withLongOpt("property").withArgName("file").hasArg()
            .withDescription("path to the Gasp property file").create('p'));
    options.addOption(OptionBuilder.withLongOpt("security").withArgName("file").hasArg()
            .withDescription("path to the Java security policy file").create('s'));
    options.addOption(OptionBuilder.withLongOpt("version").withDescription("print version").create("v"));
    options.addOption(OptionBuilder.withLongOpt("help").withDescription("show this help").create("h"));

    // default values for arguments
    String homeDir = System.getProperty("gasp.home", System.getProperty("user.dir"));
    String propFilePath = null;/*  w  w  w  .j a va 2s  . c o  m*/
    String log4jFilePath = null;
    String policyFilePath = null;

    // parsing options from command line
    final CommandLine line = new PosixParser().parse(options, args);
    if (line.hasOption("l")) {
        log4jFilePath = line.getOptionValue("l");
    }
    if (line.hasOption("p")) {
        propFilePath = line.getOptionValue("p");
    }
    if (line.hasOption("s")) {
        policyFilePath = line.getOptionValue("s");
    }
    if (line.hasOption("b")) {
        homeDir = line.getOptionValue("b");
    }
    if (line.hasOption("h")) {
        // print help to the standard output
        final HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(APPLICATION_NAME, options);
        System.exit(0);
    }
    if (line.hasOption("v")) {
        // print version
        final Package pkg = Runner.class.getPackage();
        String app = StringUtils.defaultString(pkg.getSpecificationTitle(), APPLICATION_NAME);
        String version = StringUtils.defaultString(pkg.getSpecificationVersion(), "<?>");

        System.out.println(app + " " + version);
        System.exit(0);
    }

    // we are ready to go!
    final Bootstrap bootstrap = new Bootstrap(homeDir, policyFilePath, log4jFilePath, propFilePath);
    final Thread thread = new BootstrapThread(bootstrap);
    thread.start();
    thread.join();
}

From source file:org.glite.security.voms.admin.integration.orgdb.tools.OrgDBUtil.java

protected void setupCLParser() {

    options.addOption(//from w ww  .j  av  a2s. c o  m
            OptionBuilder.withLongOpt("help").withDescription("Displays helps and exits.").create("h"));

    options.addOption(OptionBuilder.withLongOpt("config")
            .withDescription("Specifies the config to be used to connect to the OrgDB").hasArg().create("c"));

    options.addOption(OptionBuilder.withLongOpt("email")
            .withDescription("Specifies the email to be used when searching/creating users.").hasArg()
            .create("email"));

    options.addOption(OptionBuilder.withLongOpt("name")
            .withDescription("Specifies the name to be used when searching/creating users.").hasArg()
            .create("name"));

    options.addOption(OptionBuilder.withLongOpt("surname")
            .withDescription("Specifies the surname to be used when searching/creating users.").hasArg()
            .create("surname"));

    options.addOption(OptionBuilder.withLongOpt("id")
            .withDescription("Specifies the OrgDB id to be used when searching/creating users.").hasArg()
            .create("id"));

    options.addOption(OptionBuilder.withLongOpt("institute")
            .withDescription("Specifies the OrgDB id to be used when searching/creating users.").hasArg()
            .create("institute"));

    options.addOption(OptionBuilder.withLongOpt("experiment")
            .withDescription("Specifies the OrgDB id to be used when searching/creating users.").hasArg()
            .create("experiment"));

    options.addOption(OptionBuilder.withLongOpt("user_file")
            .withDescription("A file containing user information to be used when creating multiple users.")
            .hasArg().create("user_file"));

    options.addOption(
            OptionBuilder.withLongOpt("verbose").withDescription("Produce verbose output.").create("v"));

}

From source file:org.glite.security.voms.admin.persistence.deployer.SchemaDeployer.java

protected void setupCLParser() {

    options = new Options();

    options.addOption(/* www .  j a v a  2 s  . c om*/
            OptionBuilder.withLongOpt("help").withDescription("Displays helps and exits.").create("h"));

    options.addOption(OptionBuilder.withLongOpt("command")
            .withDescription("Specifies the command to be executed: deploy,undeploy,upgrade,add-admin").hasArg()
            .create("command"));

    options.addOption(
            OptionBuilder.withLongOpt("vo").withDescription("Specifies the vo name.").hasArg().create("vo"));

    options.addOption(OptionBuilder.withLongOpt("config")
            .withDescription("Specifies the hibernate config file to be used.").hasArg().create("config"));

    options.addOption(OptionBuilder.withLongOpt("properties")
            .withDescription("Specifies the hibernate properties file to be used.").hasArg()
            .create("properties"));

    options.addOption(OptionBuilder.withLongOpt("dn")
            .withDescription(
                    "Specifies the dn for the admin to add (valid only if add-admin command is given).")
            .hasArg().create("dn"));

    options.addOption(OptionBuilder.withLongOpt("ca")
            .withDescription(
                    "Specifies the ca for the admin to add (valid only if add-admin command is given).")
            .hasArg().create("ca"));

    options.addOption(OptionBuilder.withLongOpt("email").withDescription(
            "Specifies the email address for the admin to add (valid only if add-admin command is given).")
            .hasArg().create("email"));

}

From source file:org.goobi.eadmgr.Cli.java

@Override
@SuppressWarnings("AccessStaticViaInstance") // workaround for screwed OptionBuilder API
public void initOptions() {
    options = new Options();

    // mutually exclusive main commands
    OptionGroup mainCommands = new OptionGroup();
    mainCommands.addOption(new Option("h", "help", false, "Print this usage information"));
    mainCommands.addOption(/*w w  w . j  a v  a 2s .  c om*/
            new Option("l", "list-folder-ids", false, "List all folder IDs available for process creation."));
    mainCommands.addOption(new Option("c", "create-process", true,
            "Extracted data for given folder ID as process creation message to configured ActiveMQ server."));
    options.addOptionGroup(mainCommands);

    // additional switches
    options.addOption(OptionBuilder.withLongOpt("validate").withDescription(
            "Validate XML structure of the EAD document. Exits with error code 1 if validation fails. Can be used without other commands for just validating files.")
            .create());
    options.addOption(OptionBuilder.withLongOpt("dry-run")
            .withDescription("Print folder information instead of sending it.").create());
    options.addOption("v", "verbose", false, "Be verbose about what is going on.");
    options.addOption("u", "url", true,
            MessageFormat.format("ActiveMQ Broker URL. If not given the broker is contacted at \"{0}\".\n"
                    + "Note that using the failover protocol will block the program forever if the ActiveMQ host is not reachable unless you specify the \"timeout\" parameter in the URL. See {1} for more information.",
                    DEFAULT_BROKER_URL, ACTIVEMQ_CONFIGURING_URL));
    options.addOption("q", "queue", true, MessageFormat.format(
            "ActiveMQ Subject Queue. If not given messages get enqueue at \"{0}\".", DEFAULT_SUBJECT_QUEUE));
    options.addOption(OptionBuilder.withLongOpt("topic-queue")
            .withDescription(MessageFormat.format(
                    "ActiveMQ result topic Queue. If not given wait for result message posting at \"{0}\".",
                    DEFAULT_RESULT_TOPIC))
            .hasArg().create());
    options.addOption("t", "template", true, MessageFormat
            .format("Goobi Process Template name. If not given \"{0}\" is used.", DEFAULT_PROCESS_TEMPLATE));
    options.addOption("d", "doctype", true,
            MessageFormat.format("Goobi Doctype name. If not given \"{0}\" is used.", DEFAULT_DOCTYPE));
    options.addOption(OptionBuilder.withLongOpt("use-folder-id").withDescription(
            "Use folder ID when generating ActiveMQ Message IDs. If not given a random 128 bit universally unique identifier (UUID) is generated.")
            .create());
    options.addOption(OptionBuilder.withLongOpt("collection")
            .withDescription("Name of a collection to which the newly created process should be assigned.")
            .hasArg().create("C"));
    options.addOption(OptionBuilder
            .withDescription(
                    "User defined option in the form of <key>=<value> to append to the ActiveMQ message.")
            .hasArgs().create("O"));
    options.addOption("x", "extraction-profile", true, MessageFormat.format(
            "XSLT EAD extraction profile name. Either an absolute pathname or a file that can be found on the classpath. If not given \"{0}\" is used.",
            DEFAULT_EXTRACTION_PROFILE));
}

From source file:org.gudy.azureus2.ui.console.commands.AddFind.java

public AddFind() {
    super("add", "a");

    OptionBuilder.withArgName("outputDir");
    OptionBuilder.withLongOpt("output");
    OptionBuilder.hasArg();/*from   w w w  .  j a v a2  s .  c  o  m*/
    OptionBuilder.withDescription("override default download directory");
    OptionBuilder.withType(File.class);
    getOptions().addOption(OptionBuilder.create('o'));
    getOptions().addOption("r", "recurse", false, "recurse sub-directories.");
    getOptions().addOption("f", "find", false, "only find files, don't add.");
    getOptions().addOption("h", "help", false, "display help about this command");
    getOptions().addOption("l", "list", false, "list previous find results");
}

From source file:org.jage.platform.cli.CommandLineArgumentsService.java

@SuppressWarnings("static-access")
private void initOptions() {
    options.addOption(HELP_OPTION, "help", false, HELP_DESCRIPTION);

    final Option lifecycleManagerClass = OptionBuilder.withLongOpt("lifecycle-manager").withArgName("classname")
            .hasArg().withDescription(LIFECYCLE_MANAGER_DESCRIPTION).create(LIFECYCLE_MANAGER_OPTION);
    options.addOption(lifecycleManagerClass);

    // -Dproperty=value
    final Option property = OptionBuilder.withArgName(PROPERTIES_NAME).hasArgs(2).withValueSeparator()
            .withDescription(PROPERTIES_DESCRIPTION).create(PROPERTIES_PREFIX);
    options.addOption(property);//from www.  j a va 2 s  .co  m
}

From source file:org.jcodec.samples.splitter.H264SplitterMain.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("num-idr")
            .withDescription("Maximum number of IDR sequences to be written into one slice. Default is 1.")
            .hasArg().withArgName("number").create("n"));
    options.addOption(OptionBuilder.withLongOpt("pattern")
            .withDescription("File name pattern for output slices."
                    + " Use '{index}' as a placeholder for slice index." + " Default is 'output{index}.264'.")
            .hasArg().withArgName("pattern").create("p"));
    options.addOption("v", "verbose", false, "Generate verbose output.");
    options.addOption(OptionBuilder.withLongOpt("exec")
            .withDescription("A command to execute after a new slice is created."
                    + " A full path to the new slice file is" + " passed as a first parameter to the command."
                    + " This should be a full path to executable module." + " Use shell to execute a script.")
            .hasArg().withArgName("command").create("e"));

    options.addOption("h", "help", false, "Print this message.");

    try {//from   w w  w.jav a  2s .c  o  m
        CommandLine line = parser.parse(options, args);

        String[] files = line.getArgs();
        if (line.hasOption("help") || files.length == 0) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("split264", options);
            System.exit(0);
        }

        String filePattern = "output{index}.264";
        if (line.hasOption("p")) {
            filePattern = line.getOptionValue("p");
        }

        File file = new File(produceFilePath(filePattern, 0));
        if (!file.isAbsolute()) {
            String fileName = files[0];
            filePattern = new File(new File(fileName).getParentFile(), filePattern).getAbsolutePath();
        }

        int numIDR = 1;
        if (line.hasOption("n")) {
            numIDR = Integer.parseInt(line.getOptionValue("n"));
        }

        String execute = null;
        if (line.hasOption("e")) {
            execute = line.getOptionValue("e");
        }

        boolean verbose = false;
        if (line.hasOption("v")) {
            verbose = true;
        }

        new H264SplitterMain().doTheJob(filePattern, numIDR, execute, verbose, files[0]);
    } catch (ParseException exp) {
        System.out.println("Unexpected exception:" + exp.getMessage());
    }
}