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

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

Introduction

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

Prototype

public static OptionBuilder hasArg() 

Source Link

Document

The next Option created will require an argument value.

Usage

From source file:org.dcm4chee.proxy.tool.ProxySA.java

@SuppressWarnings("static-access")
private static void addLDAPOptions(Options opts) {
    opts.addOption(OptionBuilder.hasArg().withArgName("url").withDescription(rb.getString("ldap-url"))
            .withLongOpt("ldap-url").create(null));
    opts.addOption(OptionBuilder.hasArg().withArgName("dn").withDescription(rb.getString("ldap-userDN"))
            .withLongOpt("ldap-userDN").create(null));
    opts.addOption(OptionBuilder.hasArg().withArgName("password").withDescription(rb.getString("ldap-pwd"))
            .withLongOpt("ldap-pwd").create(null));
}

From source file:org.dcm4chee.proxy.tool.ProxySA.java

@SuppressWarnings("static-access")
private static void addTLSOptions(Options opts) {
    opts.addOption(OptionBuilder.hasArg().withArgName("file|url").withDescription(rb.getString("key-store"))
            .withLongOpt("key-store").create(null));
    opts.addOption(OptionBuilder.hasArg().withArgName("storetype")
            .withDescription(rb.getString("key-store-type")).withLongOpt("key-store-type").create(null));
    opts.addOption(OptionBuilder.hasArg().withArgName("password").withDescription(rb.getString("key-store-pwd"))
            .withLongOpt("key-store-pwd").create(null));
    opts.addOption(OptionBuilder.hasArg().withArgName("password").withDescription(rb.getString("key-pwd"))
            .withLongOpt("key-pwd").create(null));
}

From source file:org.dcm4chee.proxy.tool.ProxySA.java

@SuppressWarnings("static-access")
private static void addAuditLogOptions(Options opts) {
    opts.addOption(OptionBuilder.hasArg().withArgName("integer").withDescription(rb.getString("log-interval"))
            .withLongOpt("log-interval").create(null));
}

From source file:org.dcm4chee.xds2.src.tool.pnrsnd.PnRSnd.java

@SuppressWarnings("static-access")
private static void addURLOption(Options opts) {
    opts.addOption(OptionBuilder.hasArg().withArgName("url").withDescription("Repository URL")
            .withLongOpt("url").create("u"));
}

From source file:org.dcm4chee.xds2.src.tool.pnrsnd.PnRSnd.java

@SuppressWarnings("static-access")
private static void addPropertyOption(Options opts) {
    opts.addOption(OptionBuilder.hasArg().withArgName("prop")
            .withDescription("<property name>=<property value>").withLongOpt("property").create("p"));
}

From source file:org.eclim.command.Options.java

/**
 * Parses the String representation of an Option to an Option instance.
 *
 * @param option The option String.//w  w  w. j a v  a 2 s . c o m
 * @return The Option.
 */
public Option parseOption(String option) {
    String[] parts = StringUtils.split(option);

    // command can have any additional arguments.
    //if(parts.length == 1 && ANY.equals(parts[0])){
    //}

    if (REQUIRED.equals(parts[0])) {
        OptionBuilder.isRequired();
    }
    if (ARG.equals(parts[3])) {
        OptionBuilder.hasArg();
        //OptionBuilder.withArgName(parts[2]);
    } else if (ANY.equals(parts[3])) {
        OptionBuilder.hasOptionalArgs();
    }
    OptionBuilder.withLongOpt(parts[2]);
    return OptionBuilder.create(parts[1]);
}

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();//www.j  av  a 2s.co  m

    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.eclim.plugin.dltk.project.DltkProjectManager.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().withLongOpt("interpreter").create());
    org.apache.commons.cli.CommandLine cli = parser.parse(options, args);

    IInterpreterInstall interpreter = null;
    if (cli.hasOption("interpreter")) {
        String interpreterName = cli.getOptionValue("interpreter");
        IInterpreterInstallType[] types = ScriptRuntime.getInterpreterInstallTypes(getNatureId());

        loop: for (IInterpreterInstallType type : types) {
            IInterpreterInstall[] installs = type.getInterpreterInstalls();
            for (IInterpreterInstall install : installs) {
                if (install.getName().equals(interpreterName)) {
                    interpreter = install;
                    break loop;
                }/*from   w  w w. j  a  v a 2s  .  c o m*/
            }
        }

        if (interpreter == null) {
            throw new IllegalArgumentException(
                    Services.getMessage("interpreter.name.not.found", interpreterName));
        }
    }

    String dependsString = commandLine.getValue(Options.DEPENDS_OPTION);

    IScriptProject scriptProject = DLTKCore.create(project);

    if (!project.getFile(BUILDPATH).exists()) {
        IDLTKLanguageToolkit toolkit = getLanguageToolkit(getNatureId());
        BuildpathDetector detector = new BuildpathDetector(project, toolkit);
        detector.detectBuildpath(null);
        IBuildpathEntry[] detected = detector.getBuildpath();

        // remove any entries the detector may have added that are not valid for
        // this project (currently happens on php projects with the
        // org.eclipse.dltk.launching.INTERPRETER_CONTAINER entry).
        ArrayList<IBuildpathEntry> entries = new ArrayList<IBuildpathEntry>();
        for (IBuildpathEntry entry : detected) {
            IModelStatus status = BuildpathEntry.validateBuildpathEntry(scriptProject, entry, true);
            if (status.isOK()) {
                entries.add(entry);
            }
        }
        detected = entries.toArray(new IBuildpathEntry[entries.size()]);

        IBuildpathEntry[] depends = createOrUpdateDependencies(scriptProject, dependsString);

        IBuildpathEntry[] buildpath = merge(new IBuildpathEntry[][] { detected, depends });
        //scriptProject.readRawClasspath(), detected, depends, container

        scriptProject.setRawBuildpath(buildpath, null);
    }

    if (interpreter != null) {
        IBuildpathEntry[] buildpath = scriptProject.getRawBuildpath();
        int containerIndex = 0;
        for (int i = 0; i < buildpath.length; i++) {
            if (buildpath[i].getEntryKind() == IBuildpathEntry.BPE_CONTAINER) {
                containerIndex = i;
                break;
            }
        }

        if (containerIndex == 0) {
            throw new RuntimeException("No container buildpath entry found.");
        }

        IBuildpathEntry container = buildpath[containerIndex];
        buildpath[containerIndex] = DLTKCore.newContainerEntry(
                ScriptRuntime.newInterpreterContainerPath(interpreter), container.getAccessRules(),
                container.getExtraAttributes(), container.isExported());
        scriptProject.setRawBuildpath(buildpath, null);
    }

    scriptProject.makeConsistent(null);
    scriptProject.save(null, false);
}

From source file:org.eclim.plugin.pydev.project.PydevProjectManager.java

@SuppressWarnings("static-access")
@Override//w  w w. j  av a 2  s.c o m
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("interpreter").create());
    org.apache.commons.cli.CommandLine cli = parser.parse(options, args);

    // remove the python nature added by ProjectManagement since pydev will
    // skip all the other setup if the nature is already present.
    IProjectDescription desc = project.getDescription();
    String[] natureIds = desc.getNatureIds();
    ArrayList<String> modified = new ArrayList<String>();
    CollectionUtils.addAll(modified, natureIds);
    modified.remove(PythonNature.PYTHON_NATURE_ID);
    desc.setNatureIds(modified.toArray(new String[modified.size()]));
    project.setDescription(desc, new NullProgressMonitor());

    String pythonPath = project.getFullPath().toString();
    String interpreter = cli.getOptionValue("interpreter");
    IInterpreterManager manager = PydevPlugin.getPythonInterpreterManager();
    IInterpreterInfo info = manager.getInterpreterInfo(interpreter, null);
    if (info == null) {
        throw new RuntimeException("Python interpreter not found: " + interpreter);
    }

    // construct version from the interpreter chosen.
    String version = "python " + IGrammarVersionProvider.grammarVersionToRep.get(info.getGrammarVersion());

    // see src.org.python.pydev.plugin.PyStructureConfigHelpers
    PythonNature.addNature(project, null, version, pythonPath, null, interpreter, null);
}

From source file:org.eclipse.jubula.documentation.gen.TexGen.java

/**
 * @return The command line options//from  w  w w  .  j a  va 2 s.  c  o  m
 */
private static Options createOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("generate type"); //$NON-NLS-1$
    OptionBuilder
            .withDescription("The type of output to generate (i.e. 'actions', 'errors'). Default: 'actions'"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    // Not required. Default to type 'actions'.
    options.addOption(OptionBuilder.create("gt")); //$NON-NLS-1$

    OptionBuilder.withArgName("template directory"); //$NON-NLS-1$
    OptionBuilder.withDescription("The directory which contains the template files"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create("td")); //$NON-NLS-1$

    OptionBuilder.withArgName("output directory"); //$NON-NLS-1$
    OptionBuilder.withDescription("The output directory"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create("od")); //$NON-NLS-1$

    OptionBuilder.withArgName("language"); //$NON-NLS-1$
    OptionBuilder.withDescription("The language, e.g. 'en' or 'de'"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("nl")); //$NON-NLS-1$
    return options;
}