Examples of ArgumentParserException


Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

            if (size == 1) {
                ap = parsers_.get(cand.get(0));
            } else if (size > 1) {
                // Sort it to make unit test easier
                Collections.sort(cand);
                throw new ArgumentParserException(String.format(
                        TextHelper.LOCALE_ROOT,
                        "ambiguous command: %s could match %s", command,
                        TextHelper.concat(cand, 0, ", ")), mainParser_);
            }
        }
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

        }
        // At this point, more than 1 flags were found from optargIndex_
        // and/or flag forms concatenated short options.
        // Sort in order to make unit test easier.
        Collections.sort(cand);
        throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT,
                "ambiguous option: %s could match %s", flag,
                TextHelper.concat(cand, 0, ", ")), this);
    }
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

                checkRequiredArgument(state, used, posargIndex);
                checkRequiredMutex(state, groupUsed);
                subparsers_.parseArg(state, attrs);
                return;
            } else {
                throw new ArgumentParserException(
                        formatUnrecognizedArgumentErrorMessage(state,
                                TextHelper.concat(state.args, state.index, " ")),
                        this);
            }
        }
        if (subparsers_.hasSubCommand()) {
            throw new ArgumentParserException("too few arguments", this);
        }
        while (posargIndex < posargsLen) {
            ArgumentImpl arg = posargs_.get(posargIndex++);
            processArg(attrs, state, arg, null, null);
        }
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

                ArgumentImpl usedMutexArg = groupUsed[arg.getArgumentGroup()
                        .getIndex()];
                if (usedMutexArg == null) {
                    groupUsed[arg.getArgumentGroup().getIndex()] = arg;
                } else if (usedMutexArg != arg) {
                    throw new ArgumentParserException(String.format(
                            TextHelper.LOCALE_ROOT,
                            "not allowed with argument %s",
                            usedMutexArg.textualName()), this, arg);
                }
            }
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

        if (!arg.getAction().consumeArgument()) {
            if (embeddedValue == null) {
                arg.run(this, res, flag, null);
                return;
            } else {
                throw new ArgumentParserException(String.format(
                        TextHelper.LOCALE_ROOT,
                        "ignore implicit argument '%s'", embeddedValue), this,
                        arg);
            }
        }
        if (arg.getMinNumArg() == -1
                || (arg.getMinNumArg() == 0 && arg.getMaxNumArg() == 1)) {
            // In case of: option takes exactly one argument, or nargs("?")
            String argval = null;
            if (embeddedValue == null) {
                if (state.isArgAvail() && !flagFound(state)) {
                    argval = state.getArg();
                    ++state.index;
                }
            } else {
                argval = embeddedValue;
            }
            if (argval == null) {
                if (arg.getMinNumArg() == -1) {
                    if (arg.isOptionalArgument()) {
                        throw new ArgumentParserException(
                                "expected one argument", this, arg);
                    } else {
                        throw new ArgumentParserException("too few arguments",
                                this);
                    }
                } else if (arg.isOptionalArgument()) {
                    // This is a special treatment for nargs("?"). If flag is
                    // given but no argument follows, produce const value.
                    arg.run(this, res, flag, arg.getConst());
                }
            } else {
                arg.run(this, res, flag, arg.convert(this, argval));
            }
        } else {
            List<Object> list = new ArrayList<Object>();
            if (embeddedValue == null) {
                for (int i = 0; i < arg.getMaxNumArg() && state.isArgAvail(); ++i, ++state.index) {
                    if (flagFound(state)) {
                        break;
                    }
                    list.add(arg.convert(this, state.getArg()));
                }
            } else {
                list.add(arg.convert(this, embeddedValue));
            }
            if (list.size() < arg.getMinNumArg()) {
                if (arg.isOptionalArgument()) {
                    throw new ArgumentParserException(String.format(
                            TextHelper.LOCALE_ROOT, "expected %d argument(s)",
                            arg.getMinNumArg()), this, arg);
                } else {
                    throw new ArgumentParserException("too few arguments", this);
                }
            }
            // For optional arguments, always process the list even if it is
            // empty.
            // For positional arguments, empty list means no positional argument
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

            String line;
            while ((line = reader.readLine()) != null) {
                list.add(line);
            }
        } catch (IOException e) {
            throw new ArgumentParserException(String.format(
                    TextHelper.LOCALE_ROOT,
                    "Could not read arguments from file '%s'", file), e, this);
        } finally {
            try {
                if (reader != null) {
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

        if (state.deferredException != null) {
            return;
        }
        for (ArgumentImpl arg : optargs_) {
            if (arg.isRequired() && !used.contains(arg)) {
                state.deferredException = new ArgumentParserException(
                        String.format(TextHelper.LOCALE_ROOT,
                                "argument %s is required", arg.textualName()),
                        this);
            }
        }
        if (posargs_.size() > posargIndex) {
            state.deferredException = new ArgumentParserException(
                    "too few arguments", this);
        }

    }
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

                for (ArgumentImpl arg : group.getArgs()) {
                    if (arg.getHelpControl() != Arguments.SUPPRESS) {
                        sb.append(arg.textualName()).append(" ");
                    }
                }
                state.deferredException = new ArgumentParserException(
                        String.format(TextHelper.LOCALE_ROOT,
                                "one of the arguments %sis required",
                                sb.toString()), this);
            }
        }
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

    }

    private void throwArgumentParserException(ArgumentParser parser,
            Argument arg, String value, Throwable t)
            throws ArgumentParserException {
        throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT,
                "could not convert '%s' to %s (%s)", value,
                type_.getSimpleName(), t.getMessage()), t, parser, arg);
    }
View Full Code Here

Examples of net.sourceforge.argparse4j.inf.ArgumentParserException

        try {
            return Enum.valueOf(type_, value);
        } catch (IllegalArgumentException e) {
            String choices = TextHelper.concat(type_.getEnumConstants(), 0,
                    ",", "{", "}");
            throw new ArgumentParserException(String.format(
                    TextHelper.LOCALE_ROOT,
                    "could not convert '%s' (choose from %s)", value, choices),
                    e, parser, arg);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.