private void parseArguments()

in src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLArgsParser.java [531:613]


    private void parseArguments() throws ParseException {
        if (STATE_REQUIRE_ARG == this.state) {
            if ('=' == this.ch || 0 == this.ch) {
                getChar();
            }

            final Token token = nextToken(NULL_SEPARATORS);
            this.option.addArgument(token.getValue());

            addOption(this.option);
            this.state = STATE_NORMAL;
        } else if (STATE_OPTIONAL_ARG == this.state) {
            if ('-' == this.ch || 0 == this.ch) {
                getChar(); // consume stray character
                addOption(this.option);
                this.state = STATE_NORMAL;
                return;
            }

            if (this.isLong && '=' != this.tokesep){ // Long optional arg must have = as separator
                addOption(this.option);
                this.state = STATE_NORMAL;
                return;
            }

            if ('=' == this.ch) {
                getChar();
            }

            final Token token = nextToken(NULL_SEPARATORS);
            this.option.addArgument(token.getValue());

            addOption(this.option);
            this.state = STATE_NORMAL;
        } else if (STATE_REQUIRE_2ARGS == this.state) {
            if (0 == this.option.getArgumentCount()) {
                /*
                 * Fix bug: -D arg1=arg2 was causing parse error; however
                 * --define arg1=arg2 is OK This seems to be because the parser
                 * skips the terminator for the long options, but was not doing
                 * so for the short options.
                 */
                if (!this.isLong) {
                    if (0 == peekAtChar()) {
                        getChar();
                    }
                }
                final Token token = nextToken(ARG_SEPARATORS);

                if (TOKEN_SEPARATOR == token.getType()) {
                    final CLOptionDescriptor descriptor = getDescriptorFor(this.option.getDescriptor().getId());
                    final String message = "Unable to parse first argument for option "
                            + getOptionDescription(descriptor);
                    throw new ParseException(message, 0);
                } else {
                    this.option.addArgument(token.getValue());
                }
                // Are we about to start a new option?
                if (0 == this.ch && '-' == peekAtChar()) {
                    // Yes, so the second argument is missing
                    this.option.addArgument("");
                    this.options.add(this.option);
                    this.state = STATE_NORMAL;
                }
            } else // 2nd argument
            {
                final StringBuilder sb = new StringBuilder();

                this.ch = getChar();
                while (!isSeparator(this.ch, NULL_SEPARATORS)) {
                    sb.append(this.ch);
                    this.ch = getChar();
                }

                final String argument = sb.toString();

                this.option.addArgument(argument);
                addOption(this.option);
                this.option = null;
                this.state = STATE_NORMAL;
            }
        }
    }