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

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

Introduction

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

Prototype

public MissingArgumentException(Option option) 

Source Link

Document

Construct a new MissingArgumentException with the specified detail message.

Usage

From source file:org.apache.accumulo.core.util.shell.commands.AddSplitsCommand.java

public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final boolean decode = cl.hasOption(base64Opt.getOpt());

    final TreeSet<Text> splits = new TreeSet<Text>();

    if (cl.hasOption(optSplitsFile.getOpt())) {
        final String f = cl.getOptionValue(optSplitsFile.getOpt());

        String line;/*from  ww w  .  jav  a2 s . c  o  m*/
        java.util.Scanner file = new java.util.Scanner(new File(f), Constants.UTF8.name());
        while (file.hasNextLine()) {
            line = file.nextLine();
            if (!line.isEmpty()) {
                splits.add(
                        decode ? new Text(Base64.decodeBase64(line.getBytes(Constants.UTF8))) : new Text(line));
            }
        }
    } else {
        if (cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("No split points specified");
        }
        for (String s : cl.getArgs()) {
            splits.add(new Text(s.getBytes(Shell.CHARSET)));
        }
    }

    if (!shellState.getConnector().tableOperations().exists(tableName)) {
        throw new TableNotFoundException(null, tableName, null);
    }
    shellState.getConnector().tableOperations().addSplits(tableName, splits);

    return 0;
}

From source file:org.apache.accumulo.core.util.shell.commands.GrepCommand.java

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final PrintFile printFile = getOutputFile(cl);

    final String tableName = OptUtil.getTableOpt(cl, shellState);

    if (cl.getArgList().isEmpty()) {
        throw new MissingArgumentException("No terms specified");
    }//from w ww  .  j a  va 2 s . c o  m
    final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);

    // handle first argument, if present, the authorizations list to
    // scan with
    int numThreads = 20;
    if (cl.hasOption(numThreadsOpt.getOpt())) {
        numThreads = Integer.parseInt(cl.getOptionValue(numThreadsOpt.getOpt()));
    }
    final Authorizations auths = getAuths(cl, shellState);
    final BatchScanner scanner = shellState.getConnector().createBatchScanner(tableName, auths, numThreads);
    scanner.setRanges(Collections.singletonList(getRange(cl, interpeter)));

    scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);

    for (int i = 0; i < cl.getArgs().length; i++) {
        setUpIterator(Integer.MAX_VALUE - cl.getArgs().length + i, "grep" + i, cl.getArgs()[i], scanner, cl);
    }
    try {
        // handle columns
        fetchColumns(cl, scanner, interpeter);

        // output the records
        printRecords(cl, shellState, scanner, formatter, printFile);
    } finally {
        scanner.close();
    }

    return 0;
}

From source file:org.apache.accumulo.server.util.VerifyTabletAssignments.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();

    Option zooKeeperInstance = new Option("z", "zooKeeperInstance", true,
            "use a zookeeper instance with the given instance name and list of zoo hosts");
    zooKeeperInstance.setArgName("name hosts");
    zooKeeperInstance.setArgs(2);//from   w  w  w . j  av a2  s  .  com
    opts.addOption(zooKeeperInstance);

    Option usernameOption = new Option("u", "user", true, "username (required)");
    usernameOption.setArgName("user");
    usernameOption.setRequired(true);
    opts.addOption(usernameOption);

    Option passwOption = new Option("p", "password", true,
            "password (prompt for password if this option is missing)");
    passwOption.setArgName("pass");
    opts.addOption(passwOption);

    Option verboseOption = new Option("v", "verbose", false, "verbose mode (prints locations of tablets)");
    opts.addOption(verboseOption);

    CommandLine cl = null;
    String user = null;
    String passw = null;
    Instance instance = null;
    ConsoleReader reader = new ConsoleReader();
    try {
        cl = new BasicParser().parse(opts, args);

        if (cl.hasOption(zooKeeperInstance.getOpt())
                && cl.getOptionValues(zooKeeperInstance.getOpt()).length != 2)
            throw new MissingArgumentException(zooKeeperInstance);

        user = cl.getOptionValue(usernameOption.getOpt());
        passw = cl.getOptionValue(passwOption.getOpt());

        if (cl.hasOption(zooKeeperInstance.getOpt())) {
            String[] zkOpts = cl.getOptionValues(zooKeeperInstance.getOpt());
            instance = new ZooKeeperInstance(zkOpts[0], zkOpts[1]);
        } else {
            instance = HdfsZooInstance.getInstance();
        }

        if (passw == null)
            passw = reader.readLine(
                    "Enter current password for '" + user + "'@'" + instance.getInstanceName() + "': ", '*');
        if (passw == null) {
            reader.printNewline();
            return;
        } // user canceled

        if (cl.getArgs().length != 0)
            throw new ParseException("Unrecognized arguments: " + cl.getArgList());

    } catch (ParseException e) {
        PrintWriter pw = new PrintWriter(System.err);
        new HelpFormatter().printHelp(pw, Integer.MAX_VALUE,
                "accumulo " + VerifyTabletAssignments.class.getName(), null, opts, 2, 5, null, true);
        pw.flush();
        System.exit(1);
    }

    Connector conn = instance.getConnector(user, passw.getBytes());

    for (String table : conn.tableOperations().list())
        checkTable(user, passw, table, null, cl.hasOption(verboseOption.getOpt()));

}

From source file:org.apache.accumulo.shell.commands.AddSplitsCommand.java

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final boolean decode = cl.hasOption(base64Opt.getOpt());

    final TreeSet<Text> splits = new TreeSet<Text>();

    if (cl.hasOption(optSplitsFile.getOpt())) {
        splits.addAll(ShellUtil.scanFile(cl.getOptionValue(optSplitsFile.getOpt()), decode));
    } else {//from  w  w  w.  j a va  2  s. c om
        if (cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("No split points specified");
        }
        for (String s : cl.getArgs()) {
            splits.add(new Text(s.getBytes(Shell.CHARSET)));
        }
    }

    if (!shellState.getConnector().tableOperations().exists(tableName)) {
        throw new TableNotFoundException(null, tableName, null);
    }
    shellState.getConnector().tableOperations().addSplits(tableName, splits);

    return 0;
}

From source file:org.apache.accumulo.shell.commands.GrepCommand.java

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final PrintFile printFile = getOutputFile(cl);

    final String tableName = OptUtil.getTableOpt(cl, shellState);

    if (cl.getArgList().isEmpty()) {
        throw new MissingArgumentException("No terms specified");
    }/* www . j  a va  2  s. c  o m*/
    final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);

    // handle first argument, if present, the authorizations list to
    // scan with
    int numThreads = 20;
    if (cl.hasOption(numThreadsOpt.getOpt())) {
        numThreads = Integer.parseInt(cl.getOptionValue(numThreadsOpt.getOpt()));
    }
    final Authorizations auths = getAuths(cl, shellState);
    final BatchScanner scanner = shellState.getConnector().createBatchScanner(tableName, auths, numThreads);
    scanner.setRanges(Collections.singletonList(getRange(cl, interpeter)));

    scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);

    setupSampling(tableName, cl, shellState, scanner);

    for (int i = 0; i < cl.getArgs().length; i++) {
        setUpIterator(Integer.MAX_VALUE - cl.getArgs().length + i, "grep" + i, cl.getArgs()[i], scanner, cl);
    }
    try {
        // handle columns
        fetchColumns(cl, scanner, interpeter);

        // output the records
        final FormatterConfig config = new FormatterConfig();
        config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
        printRecords(cl, shellState, config, scanner, formatter, printFile);
    } finally {
        scanner.close();
    }

    return 0;
}

From source file:org.apache.flex.compiler.clients.ASC.java

/**
 * Helper method used by command line parsing logic to convert historical
 * ASC language codes into a java {@link Locale} objecst.
 * //from www .j a  v  a 2  s  .  com
 * @param language ASC language code to convert
 * @return A {@link Locale} object for the specified asc language code.
 * @throws MissingArgumentException Thrown if the specified language code is
 * not a valid asc language code.
 */
private static Locale getLocaleForLanguage(String language) throws MissingArgumentException {
    Locale result = localeMap.get(language);
    if (result != null)
        return result;
    throw new MissingArgumentException(
            "Language option must be one of: " + Joiner.on(", ").join(localeMap.keySet()));
}

From source file:org.apache.flex.compiler.clients.ASC.java

/**
 * Apache Common CLI did the lexer work. This function does the parser work
 * to construct an {@code ASC} job from the command-line options.
 * //from w w  w  .j ava  2 s . c o  m
 * @param line - the tokenized command-line
 * @return a new ASC client for the given command-line configuration; null
 * if no arguments were given.
 */
private Boolean createClient(final CommandLine line) throws ParseException {
    // First, process parsed command line options.
    final Option[] options = line.getOptions();

    if (options == null)
        return false;

    for (int i = 0; i < options.length; i++) {
        final Option option = options[i];
        final String shortName = option.getOpt();

        if ("import".equals(shortName)) {
            String[] imports = option.getValues();
            for (int j = 0; j < imports.length; j++) {
                this.addImportFilename(imports[j]);
            }
        } else if ("in".equals(shortName)) {
            String[] includes = option.getValues();
            for (int j = 0; j < includes.length; j++) {
                this.addIncludeFilename(includes[j]);
            }
        } else if ("swf".equals(shortName)) {
            String[] swfValues = option.getValue().split(",");
            if (swfValues.length < 3)
                throw new MissingArgumentException(
                        "The swf option requires three arguments, only " + swfValues.length + " were found.");

            for (int j = 0; j < swfValues.length; j++) {
                String value = swfValues[j];
                if (j == 0)
                    this.setSymbolClass(value);
                else if (j == 1)
                    this.setWidth(value);
                else if (j == 2)
                    this.setHeight(value);
                else if (j == 3)
                    this.setFrameRate(value);
            }
        } else if ("use".equals(shortName)) {
            String[] namespaces = option.getValues();
            for (String namespace : namespaces) {
                this.addNamespace(namespace);
            }
        } else if ("config".equals(shortName)) {
            String[] config = option.getValues();
            if (config.length == 2) {
                // The config option will have been split around '='
                // e.g. CONFIG::Foo='hi' will be split into
                // 2 values - 'CONFIG::Foo' and 'hi'
                String name = config[0];
                String value = config[1];
                value = fixupMissingQuote(value);
                this.putConfigVar(name, value);
            }
        } else if ("strict".equals(shortName) || "!".equals(shortName)) {
            this.setUseStaticSemantics(true);
        } else if ("d".equals(shortName)) {
            this.setEmitDebugInfo(true);
        } else if ("warnings".equals(shortName) || "coach".equals(shortName)) {
            if ("coach".equals(shortName))
                err.println("'coach' has been deprecated. Please use 'warnings' instead.");
            this.setShowWarnings(true);
        } else if ("log".equals(shortName)) {
            this.setShowLog(true);
        } else if ("md".equals(shortName)) {
            this.setEmitMetadata(true);
        } else if ("merge".equals(shortName)) {
            this.setMergeABCs(true);
        } else if ("language".equals(shortName)) {
            String value = option.getValue();
            this.setLocale(getLocaleForLanguage(value));
        } else if ("doc".equals(shortName)) {
            this.setEmitDocInfo(true);
        } else if ("avmtarget".equals(shortName)) {
            String value = option.getValue();
            this.setTargetAVM(value);
        } else if ("AS3".equals(shortName)) {
            this.setDialect("AS3");
        } else if ("ES".equals(shortName)) {
            this.setDialect("ES");
        } else if ("o".equalsIgnoreCase(shortName) || "optimize".equalsIgnoreCase(shortName)) {
            this.setOptimize(true);
        } else if ("o2".equalsIgnoreCase(shortName)) {
            this.setOptimize(true);
        } else if ("out".equalsIgnoreCase(shortName)) {
            this.setOutputBasename(option.getValue());
        } else if ("outdir".equalsIgnoreCase(shortName)) {
            this.setOutputDirectory(option.getValue());
        } else if ("abcfuture".equals(shortName)) {
            this.setABCFuture(true);
        } else if ("p".equals(shortName)) {
            this.setShowParseTrees(true);
        } else if ("i".equals(shortName)) {
            this.setShowInstructions(true);
        } else if ("m".equals(shortName)) {
            this.setShowMachineCode(true);
        } else if ("f".equals(shortName)) {
            this.setShowFlowGraph(true);
        } else if ("exe".equals(shortName)) {
            String exe = option.getValue();
            this.setAvmplusFilename(exe);
        } else if ("movieclip".equals(shortName)) {
            this.setMakeMovieClip(true);
        } else if ("ES4".equals(shortName)) {
            this.setDialect("ES4");
        } else if ("li".equals(shortName)) {
            this.internalLibraries.add(option.getValue());
        } else if ("le".equals(shortName)) {
            this.externalLibraries.add(option.getValue());
        } else if ("parallel".equals(shortName)) {
            this.setParallel(true);
        } else if ("inline".equals(shortName)) {
            this.setMergeABCs(true); // inlining requires merging of ABCs
            this.setEnableInlining(true);
        } else if ("removedeadcode".equals(shortName)) {
            this.setRemoveDeadCode(true);
        } else {
            throw new UnrecognizedOptionException("Unrecognized option '" + shortName + "'", shortName);
        }
    }

    // Then any remaining arguments that were not options are interpreted as
    // source files to compile.
    final String[] remainingArgs = line.getArgs();
    if (remainingArgs != null) {
        for (int i = 0; i < remainingArgs.length; i++) {
            this.addSourceFilename(remainingArgs[i]);
        }
    } else {
        throw new MissingArgumentException(
                "At least one source file must be specified after the list of options.");
    }

    return true;
}

From source file:org.apache.james.modules.CommonServicesModule.java

@Provides
@Singleton/*from   w ww.  ja  v a 2 s  .  c o  m*/
public JamesDirectoriesProvider directories() throws MissingArgumentException {
    String rootDirectory = Optional.ofNullable(System.getProperty("working.directory"))
            .orElseThrow(() -> new MissingArgumentException("Server needs a working.directory env entry"));
    return new JamesServerResourceLoader(rootDirectory);
}

From source file:org.apache.parquet.tools.command.ArgsOnlyCommand.java

@Override
public void execute(CommandLine options) throws Exception {
    String[] args = options.getArgs();
    if (args.length < min) {
        throw new MissingArgumentException("missing required arguments");
    }/*from  ww w . ja va 2  s . c  om*/

    if (args.length > max) {
        throw new UnrecognizedOptionException("unknown extra argument \"" + args[max] + "\"");
    }
}

From source file:org.dcm4che3.tool.qc.QC.java

public static IDWithIssuer toIDWithIssuer(String optionValue) throws MissingArgumentException {
    String[] components = optionValue.split(":");
    if (components.length < 2)
        throw new MissingArgumentException("Missing issuer information");
    if (components.length == 2) // pid and local entity uid
        return new IDWithIssuer(components[0], components[1]);
    else if (components.length == 3) // pid with universal entity and type
        return new IDWithIssuer(components[0], new Issuer(null, components[1], components[2]));
    else//from  w  ww .  j a v  a2  s  .  c  om
        return new IDWithIssuer(components[0], new Issuer(components[1], components[2], components[3]));
}