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

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

Introduction

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

Prototype

PosixParser

Source Link

Usage

From source file:com.yahoo.flowetl.commons.runner.BaseRunner.java

public final void runProgram(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    Options opts = getOptions();//  w  w  w .j  ava2s  .com
    CommandLine cmd = parser.parse(opts, args);
    if (helpNeeded(cmd)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(getProgramName(), opts);
        return;
    }
    runProgram(cmd);
}

From source file:net.orpiske.ssps.sdm.actions.Uninstall.java

@Override
protected void processCommand(String[] args) {
    CommandLineParser parser = new PosixParser();

    options = new Options();

    options.addOption("h", "help", false, "prints the help");
    options.addOption("g", "groupid", true, "package group id");
    options.addOption("p", "package", true, "package name");
    options.addOption("v", "version", true, "version");
    options.addOption(null, "deep", false, "deep uninstall (removes dependencies)");

    try {/* ww  w  .  j  a v  a 2 s . com*/
        cmdLine = parser.parse(options, args);
    } catch (ParseException e) {
        help(options, -1);
    }

    isHelp = cmdLine.hasOption("help");

    packageName = cmdLine.getOptionValue('p');
    if (packageName == null) {
        help(options, -1);
    }

    groupId = cmdLine.getOptionValue('g');
    version = cmdLine.getOptionValue('v');

    deep = cmdLine.hasOption("deep");
}

From source file:TmlCommandLine.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    long time = System.nanoTime();

    options = new Options();

    // Repository
    options.addOption(OptionBuilder.withDescription(
            "Full path of the repository folder, where TML will retrieve (or insert) documents. (e.g. /home/user/lucene).")
            .hasArg().withArgName("folder").isRequired().create("repo"));

    // Verbosity//from   w w  w.j a v a2 s . c om
    options.addOption(
            OptionBuilder.withDescription("Verbose output in the console (it goes verbose to the log file).")
                    .hasArg(false).isRequired(false).create("v"));

    // Operation on corpus
    options.addOption(OptionBuilder.hasArg(false).withDescription("Performs an operation on a corpus.")
            .isRequired(false).create("O"));

    // The list of operations
    options.addOption(OptionBuilder.withDescription(
            "The list of operations you want to execute on the corpus. (e.g. PassageDistances,PassageSimilarity .")
            .hasArgs().withValueSeparator(',').withArgName("list").isRequired(false).withLongOpt("operations")
            .create());

    // The file to store the results
    options.addOption(OptionBuilder.withDescription("Folder where to store the results. (e.g. results/run01/).")
            .hasArg().withArgName("folder").isRequired(false).withLongOpt("oresults").create());

    // The corpus on which operate
    options.addOption(OptionBuilder.withDescription(
            "Lucene query that defines the corpus to operate with. (e.g. \"type:sentence AND reference:Document01\").")
            .hasArg().withArgName("query").isRequired(false).withLongOpt("ocorpus").create());

    // The corpus on which operate
    options.addOption(OptionBuilder.withDescription(
            "Use all documents in repository as single document corpora, it can be sentence or paragraph based. (e.g. sentence).")
            .hasArgs().withArgName("type").isRequired(false).withLongOpt("oalldocs").create());

    // The properties file for the corpus
    options.addOption(OptionBuilder.withDescription("Properties file with the corpus parameters (optional).")
            .hasArg().withArgName("parameter file").isRequired(false).withLongOpt("ocpar").create());

    // Background knowledge corpus
    options.addOption(OptionBuilder.withDescription(
            "Lucene query that defines a background knowledge on which the corpus will be projected. (e.g. \"type:sentences AND reference:Document*\").")
            .hasArg().withArgName("query").isRequired(false).withLongOpt("obk").create());

    // Background knowledge parameters
    options.addOption(OptionBuilder.withDescription(
            "Properties file with the background knowledge corpus parameters, if not set it will use the same as the corpus.")
            .hasArg().withArgName("parameter file").isRequired(false).withLongOpt("obkpar").create());

    // Term selection
    String criteria = "";
    for (TermSelection tsel : TermSelection.values()) {
        criteria += "," + tsel.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("name")
            .withDescription("Name of the Term selection criteria (" + criteria + ").").isRequired(false)
            .withValueSeparator(',').withLongOpt("otsel").create());

    //   Term selection threshold
    options.addOption(OptionBuilder.hasArgs().withArgName("number")
            .withDescription("Threshold for the tsel criteria option.").withType(Integer.TYPE).isRequired(false)
            .withValueSeparator(',').withLongOpt("otselth").create());

    //   Dimensionality reduction
    criteria = "";
    for (DimensionalityReduction dim : DimensionalityReduction.values()) {
        criteria += "," + dim.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Name of the Dimensionality Reduction criteria. (e.g. " + criteria + ").")
            .isRequired(false).withValueSeparator(',').withLongOpt("odim").create());

    //   Dimensionality reduction threshold
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Threshold for the dim options. (e.g. 0,1,2).").isRequired(false)
            .withValueSeparator(',').withLongOpt("odimth").create());

    //   Local weight
    criteria = "";
    for (LocalWeight weight : LocalWeight.values()) {
        criteria += "," + weight.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Name of the Local Weight to apply. (e.g." + criteria + ").").isRequired(false)
            .withValueSeparator(',').withLongOpt("otwl").create());

    //   Global weight
    criteria = "";
    for (GlobalWeight weight : GlobalWeight.values()) {
        criteria += "," + weight.name();
    }
    criteria = criteria.substring(1);
    options.addOption(OptionBuilder.hasArgs().withArgName("list")
            .withDescription("Name of the Global Weight to apply. (e.g. " + criteria + ").").isRequired(false)
            .withValueSeparator(',').withLongOpt("otwg").create());

    //   Use Lanczos
    options.addOption(OptionBuilder.hasArg(false).withDescription("Use Lanczos for SVD decomposition.")
            .isRequired(false).withLongOpt("olanczos").create());

    // Inserting documents in repository
    options.addOption(OptionBuilder.hasArg(false).withDescription("Insert documents into repository.")
            .isRequired(false).create("I"));

    // Max documents to insert
    options.addOption(OptionBuilder.hasArg().withArgName("number")
            .withDescription("Maximum number of documents to index or use in an operation.")
            .withType(Integer.TYPE).isRequired(false).withLongOpt("imaxdocs").create());

    // Clean repository
    options.addOption(
            OptionBuilder.hasArg(false).withDescription("Empties the repository before inserting new ones.")
                    .isRequired(false).withLongOpt("iclean").create());

    // Use annotator
    options.addOption(OptionBuilder.hasArgs()
            .withDescription(
                    "List of annotators to use when inserting the documents. (e.g. PennTreeAnnotator).")
            .isRequired(false).withValueSeparator(',').withLongOpt("iannotators").create());

    // Documents folder
    options.addOption(OptionBuilder.hasArg().withArgName("folder")
            .withDescription("The folder that contains the documens to insert.").isRequired(false)
            .withLongOpt("idocs").create());

    // Initializing the line parser
    CommandLineParser parser = new PosixParser();
    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        printHelp(options);
        return;
    }

    // Validate that either inserting or an operation are given
    if (!line.hasOption("I") && !line.hasOption("O")) {
        System.out.println("One of the options -I or -O must be present.");
        printHelp(options);
        return;
    }

    repositoryFolder = line.getOptionValue("repo");

    try {
        if (line.hasOption("I")) {
            indexing();
        } else if (line.hasOption("O")) {
            operation();
        }
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        printHelp(options);
        return;
    }

    System.out.println("TML finished successfully in " + (System.nanoTime() - time) * 10E-9 + " seconds.");
    return;
}

From source file:ch.cyberduck.cli.TerminalTransferFactoryTest.java

@Test
public void testFilter() throws Exception {
    final CommandLineParser parser = new PosixParser();

    final Transfer transfer = new TerminalTransferFactory().create(
            parser.parse(TerminalOptionsBuilder.options(),
                    new String[] { "--download", "rackspace://cdn.cyberduck.ch/remote/*.css" }),
            new Host(new SwiftProtocol()), new Path("/remote/*.css", EnumSet.of(Path.Type.directory)),
            Collections.<TransferItem>emptyList());
    assertEquals(Transfer.Type.download, transfer.getType());
    final PathCache cache = new PathCache(1);
    transfer.withCache(cache);// ww w . j av  a  2s  .  c o m
    cache.clear();
    cache.put(new Path("/remote", EnumSet.of(Path.Type.directory)), new AttributedList<Path>(
            Collections.singletonList(new Path("/remote/file.css", EnumSet.of(Path.Type.file)))));
    assertFalse(transfer.list(null, null, new Path("/remote", EnumSet.of(Path.Type.directory)),
            new Local("/tmp"), new DisabledListProgressListener()).isEmpty());
    cache.clear();
    cache.put(new Path("/remote", EnumSet.of(Path.Type.directory)), new AttributedList<Path>(
            Collections.singletonList(new Path("/remote/file.png", EnumSet.of(Path.Type.file)))));
    assertTrue(transfer.list(null, null, new Path("/remote", EnumSet.of(Path.Type.directory)),
            new Local("/tmp"), new DisabledListProgressListener()).isEmpty());
}

From source file:com.github.riccardove.easyjasub.commandline.CommandLineOptionList.java

public CommandLineContent parse(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args);
    return new CommandLineContent(line);
}

From source file:net.alegen.datpass.cli.input.PasswordCommand.java

@Override
public void execute() {
    try {//  ww w  .  ja  v  a2s . co m
        CommandLineParser parser = new PosixParser();
        String[] arrayArgs = new String[this.args.size()];
        this.args.toArray(arrayArgs);
        CommandLine line = parser.parse(this.options, arrayArgs);
        String input = "";
        int length = -1;
        if (line.hasOption(OPTION_INPUT))
            input = line.getOptionValue(OPTION_INPUT);
        else {
            System.out.print("Input: ");
            input = String.valueOf(System.console().readPassword());
        }
        if (line.hasOption(OPTION_LENGTH))
            length = Integer.parseInt(line.getOptionValue(OPTION_LENGTH));
        else
            length = 100;
        String password = Generator.getInstance().password(input, length);
        if (Settings.echo())
            System.out.println(password);
        if (Settings.clipboard())
            ClipboardHandler.getInstance().set(password);
    } catch (Generator.GeneratorException e) {

    } catch (ParseException e) {

    }
}

From source file:ch.cyberduck.cli.GlobTransferItemFinderTest.java

@Test
public void testNoLocalInOptionsUploadFile() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(TerminalOptionsBuilder.options(),
            new String[] { "--upload", "rackspace://cdn.cyberduck.ch/remote" });

    final Set<TransferItem> found = new GlobTransferItemFinder().find(input, TerminalAction.upload,
            new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)));
    assertTrue(found.isEmpty());/*from  ww w .j  a  v  a2 s. co  m*/
}

From source file:jmxsh.CloseCmd.java

private CommandLine parseCommandLine(TclObject argv[]) throws ParseException {

    String[] args = new String[argv.length - 1];

    for (int i = 0; i < argv.length - 1; i++)
        args[i] = argv[i + 1].toString();

    CommandLine cl = (new PosixParser()).parse(this.opts, args);
    return cl;//from w  ww  . ja  va  2 s .c o  m
}

From source file:ca.appbox.monitoring.jmx.jmxbox.commons.context.parser.JmxContextParserImpl.java

private JmxContextParserImpl() {
    super();
    commandLineParser = new PosixParser();
    options = buildOptions();
}

From source file:eu.alpinweiss.filegen.service.impl.FdrServiceImpl.java

@Override
public void run(String[] args) {

    if (injector == null) {
        throw new RuntimeException("Injector is null");
    }/*from   w  ww. ja  v  a  2  s. c o m*/

    Model model = new Model();
    Map<String, Class<? extends CommandStep>> commandSteps = optionHolder.getCommandStepMap();
    Options options = optionHolder.getAppOptions();

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        Option[] cmdOptions = cmd.getOptions();
        for (Option cmdOption : cmdOptions) {
            model.addParameter(cmdOption.getOpt(), cmdOption.getValue());
            model.addCommand(injector.getInstance(commandSteps.get(cmdOption.getOpt())));
        }
    } catch (ParseException e) {
        LOGGER.error(e.getMessage(), e);
    }

    commandRunner.run(model);
}