Package org.jboss.aesh.cl.exception

Examples of org.jboss.aesh.cl.exception.OptionParserException


        for(int i=0; i < longName.length(); i++) {
            if(findOption(String.valueOf(longName.charAt(i))) == null)
                return longName.charAt(i);
        }
        //all chars are taken
        throw new OptionParserException("All option names are taken, please specify a unique name");
    }
View Full Code Here


        properties = new HashMap<String, String>();
        values = new ArrayList<String>();

        if((shortName == Character.MIN_VALUE) && name.equals("") && optionType != OptionType.ARGUMENT) {
            throw new OptionParserException("Either shortName or name must be set.");
        }
    }
View Full Code Here

        else {
            if((existingOption.getProperties() == null ||
                    existingOption.getProperties().size() == 0) ||
            (option.getProperties() == null || existingOption.getProperties().size() == 0)) {
                setParserError(true);
                setParserException( new OptionParserException("Not allowed to specify the same option ("+option.getDisplayName()+") twice"));
            }
            else
                existingOption.getProperties().putAll(option.getProperties());
        }
View Full Code Here

            return verifyThatNamesAreUnique('\u0000', longName);
    }

    private char verifyThatNamesAreUnique(char name, String longName) throws OptionParserException {
        if(longName != null && longName.length() > 0 && findLongOption(longName) != null) {
            throw new OptionParserException("Option --"+longName+" is already added to Param: "+this.toString());
        }
        if(name != '\u0000' && findOption(String.valueOf(name)) != null) {
            throw new OptionParserException("Option -"+name+" is already added to Param: "+this.toString());
        }

        //if name is null, use one based on name
        if(name == '\u0000' && (longName == null || longName.length() == 0))
            throw new OptionParserException("Neither option name and option long name can be both null");

        return name;
    }
View Full Code Here

                            active.getOptionType() == OptionType.GROUP) {
                        commandLine.addOption(active);
                        active = null;
                    }
                    else {
                        commandLine.setParserException(new OptionParserException("Option: "+active.getDisplayName()+" must be given a value"));
                        break;
                    }
                }

                active = findLongOption(command, parseLine.substring(2));
                if(active != null)
                    active.setLongNameUsed(true);
                if(active != null && active.isProperty()) {
                    if(parseLine.length() <= (2+active.getName().length()) ||
                            !parseLine.contains(EQUALS))
                        commandLine.setParserException(new OptionParserException(
                                "Option "+active.getDisplayName()+", must be part of a property"));
                    else {
                        String name =
                                parseLine.substring(2+active.getName().length(),
                                        parseLine.indexOf(EQUALS));
                        String value = parseLine.substring( parseLine.indexOf(EQUALS)+1);
                        if(value.length() < 1)
                            commandLine.setParserException(new OptionParserException("Option "+active.getDisplayName()+", must have a value"));
                        else {
                            active.addProperty(name, value);
                            commandLine.addOption(active);
                            active = null;
                            if(addedArgument)
                                commandLine.setParserException(new ArgumentParserException("An argument was given to an option that do not support it."));
                        }
                    }
                }
                else if(active != null && (!active.hasValue() || active.getValue() != null)) {
                    active.addValue("true");
                    commandLine.addOption(active);
                    active = null;
                    if(addedArgument)
                        commandLine.setParserException(new ArgumentParserException("An argument was given to an option that do not support it."));
                }
                else if(active == null)
                    commandLine.setParserException(new OptionParserException("Option: "+parseLine+" is not a valid option for this command"));
            }
            //name
            else if(parseLine.startsWith("-")) {
                //make sure that we dont have any "active" options lying around
                //except list and group
                if(active != null) {
                    if(active.getOptionType() == OptionType.LIST ||
                            active.getOptionType() == OptionType.GROUP) {
                        commandLine.addOption(active);
                        active = null;
                    }
                    else {
                        commandLine.setParserException(new OptionParserException("Option: "+active.getDisplayName()+" must be given a value"));
                        break;
                    }
                }
                else if(parseLine.length() != 2 && !parseLine.contains("=")) {
                    //we might have two or more options in a group
                    //if so, we only allow options (boolean) without value
                    if(parseLine.length() > 2) {
                        for(char shortName : parseLine.substring(1).toCharArray()) {
                            active = findOption(command, String.valueOf(shortName));
                            if(active != null) {
                                if(!active.hasValue()) {
                                    active.setLongNameUsed(false);
                                    active.addValue("true");
                                    commandLine.addOption(active);
                                }
                                else
                                    commandLine.setParserException( new OptionParserException("Option: -"+shortName+
                                            " can not be grouped with other options since it need to be given a value"));
                            }
                            else
                                commandLine.setParserException(new OptionParserException("Option: -"+shortName+" was not found."));
                        }
                        //make sure to reset active
                        active = null;
                    }
                    else
                        commandLine.setParserException(new OptionParserException("Option: - must be followed by a valid operator"));
                }
                else {
                    active = findOption(command, parseLine.substring(1));
                    if(active != null)
                        active.setLongNameUsed(false);

                    if(active != null && active.isProperty()) {
                        if(parseLine.length() <= 2 ||
                                !parseLine.contains(EQUALS))
                            commandLine.setParserException(new OptionParserException(
                                    "Option "+active.getDisplayName()+", must be part of a property"));
                        else {
                            String name =
                                    parseLine.substring(2, // 2+char.length
                                            parseLine.indexOf(EQUALS));
                            String value = parseLine.substring( parseLine.indexOf(EQUALS)+1);
                            if(value.length() < 1)
                                commandLine.setParserException( new OptionParserException("Option "+active.getDisplayName()+", must have a value"));
                            else {
                                active.addProperty(name, value);
                                commandLine.addOption(active);
                                active = null;
                                if(addedArgument)
                                    commandLine.setParserException( new OptionParserException("An argument was given to an option that do not support it."));
                            }
                        }
                    }

                    else if(active != null && (!active.hasValue() || active.getValue() != null)) {
                        active.addValue("true");
                        commandLine.addOption(active);
                        active = null;
                        if(addedArgument)
                            commandLine.setParserException(new OptionParserException("An argument was given to an option that do not support it."));
                    }
                    else if(active == null)
                        commandLine.setParserException(new OptionParserException("Option: "+parseLine+" is not a valid option for this command"));
                }
            }
            else if(active != null) {
                if(active.hasMultipleValues()) {
                    if(parseLine.contains(String.valueOf(active.getValueSeparator()))) {
                        for(String value : parseLine.split(String.valueOf(active.getValueSeparator()))) {
                            active.addValue(value.trim());
                        }
                        if(parseLine.endsWith(String.valueOf(active.getValueSeparator())))
                            active.setEndsWithSeparator(true);
                        commandLine.addOption(active);
                        active = null;
                    }
                    else
                        active.addValue(parseLine);
                }
                else
                    active.addValue(parseLine);

                if(active != null &&
                        (active.getOptionType() == OptionType.NORMAL ||
                                active.getOptionType() == OptionType.BOOLEAN)) {
                    commandLine.addOption(active);
                    active = null;
                }
                if(addedArgument)
                    commandLine.setParserException(new OptionParserException("An argument was given to an option that do not support it."));
            }
            //if no command is "active", we add it as an argument
            else {
                if(command.getArgument() == null) {
                    commandLine.setParserException(new OptionParserException("An argument was given to a command that do not support it."));
                }
                else {
                    commandLine.addArgumentValue(parseLine);
                    addedArgument = true;
                }
View Full Code Here

        return verifyThatNamesAreUnique(name.charAt(0), longName);
    }

    private char verifyThatNamesAreUnique(char name, String longName) throws OptionParserException {
        if(longName != null && longName.length() > 0 && findLongOption(longName) != null) {
            throw new OptionParserException("Option --"+longName+" is already added to Param: "+this.toString());
        }
        if(name != '\u0000'&& findOption(String.valueOf(name)) != null) {
            throw new OptionParserException("Option -"+name+" is already added to Param: "+this.toString());
        }

        //if name is null, use one based on longName
        if(name == '\u0000') {
            if(longName != null && longName.length() > 0)
                return findPossibleName(longName);
            else
                throw new OptionParserException("Neither option name and option long name can be both null");
        }
        return name;
    }
View Full Code Here

        for(int i=0; i < longName.length(); i++) {
            if(findOption(String.valueOf(longName.charAt(i))) == null)
                return longName.charAt(i);
        }
        //all chars are taken
        throw new OptionParserException("All option names are taken, please specify a unique name");
    }
View Full Code Here

        properties = new HashMap<String, String>();
        values = new ArrayList<String>();

        if((name == Character.MIN_VALUE) && longName.equals("")) {
            throw new OptionParserException("Either name or long name must be set.");
        }
    }
View Full Code Here

            String parseLine = lines.get(i);
            //longName
            if(parseLine.startsWith("--")) {
                //make sure that we dont have any "active" options lying around
                if(active != null)
                    throw new OptionParserException("Option: "+active.getDisplayName()+" must be given a value");

                active = findLongOption(param, parseLine.substring(2));
                if(active != null && active.isProperty()) {
                    if(parseLine.length() <= (2+active.getLongName().length()) ||
                        !parseLine.contains(EQUALS))
                        throw new OptionParserException(
                                "Option "+active.getDisplayName()+", must be part of a property");

                    String name =
                            parseLine.substring(2+active.getLongName().length(),
                                    parseLine.indexOf(EQUALS));
                    String value = parseLine.substring( parseLine.indexOf(EQUALS)+1);

                    commandLine.addOption(new
                            ParsedOption(active.getName(), active.getLongName(),
                            new OptionProperty(name, value), active.getType()));
                    active = null;
                    if(addedArgument)
                        throw new ArgumentParserException("An argument was given to an option that do not support it.");
                }
                else if(active != null && (!active.hasValue() || active.getValue() != null)) {
                    commandLine.addOption(new ParsedOption(active.getName(), active.getLongName(),
                            active.getValue(), active.getType()));
                    active = null;
                    if(addedArgument)
                        throw new ArgumentParserException("An argument was given to an option that do not support it.");
                }
                else if(active == null)
                    throw new OptionParserException("Option: "+parseLine+" is not a valid option for this command");
            }
            //name
            else if(parseLine.startsWith("-")) {
                //make sure that we dont have any "active" options lying around
                if(active != null)
                    throw new OptionParserException("Option: "+active.getDisplayName()+" must be given a value");
                if(parseLine.length() != 2 && !parseLine.contains("="))
                    throw new OptionParserException("Option: - must be followed by a valid operator");

                active = findOption(param, parseLine.substring(1));

                if(active != null && active.isProperty()) {
                    if(parseLine.length() <= 2 ||
                            !parseLine.contains(EQUALS))
                    throw new OptionParserException(
                            "Option "+active.getDisplayName()+", must be part of a property");
                    String name =
                            parseLine.substring(2, // 2+char.length
                                    parseLine.indexOf(EQUALS));
                    String value = parseLine.substring( parseLine.indexOf(EQUALS)+1);

                    commandLine.addOption(new
                            ParsedOption(active.getName(), active.getLongName(),
                            new OptionProperty(name, value), active.getType()));
                    active = null;
                    if(addedArgument)
                        throw new OptionParserException("An argument was given to an option that do not support it.");
                }

                else if(active != null && (!active.hasValue() || active.getValue() != null)) {
                    commandLine.addOption(new ParsedOption(String.valueOf(active.getName()),
                            active.getLongName(), active.getValue(), active.getType()));
                    active = null;
                    if(addedArgument)
                        throw new OptionParserException("An argument was given to an option that do not support it.");
                }
                else if(active == null)
                    throw new OptionParserException("Option: "+parseLine+" is not a valid option for this command");
            }
            else if(active != null) {
                if(active.hasMultipleValues()) {
                    if(parseLine.contains(String.valueOf(active.getValueSeparator()))) {
                        for(String value : parseLine.split(String.valueOf(active.getValueSeparator()))) {
                            active.addValue(value.trim());
                        }
                    }
                }
                else
                    active.addValue(parseLine);

                commandLine.addOption(new ParsedOption(active.getName(),
                        active.getLongName(), active.getValues(), active.getType()));
                active = null;
                if(addedArgument)
                    throw new OptionParserException("An argument was given to an option that do not support it.");
            }
            //if no param is "active", we add it as an argument
            else {
                commandLine.addArgument(parseLine);
                addedArgument = true;
View Full Code Here

        }
        else {
            if((existingOption.getProperties() == null ||
                    existingOption.getProperties().size() == 0) ||
            (option.getProperties() == null || existingOption.getProperties().size() == 0))
                throw new OptionParserException("Not allowed to specify the same option ("+option.getDisplayName()+") twice");
            else
                existingOption.getProperties().addAll(option.getProperties());
        }

    }
View Full Code Here

TOP

Related Classes of org.jboss.aesh.cl.exception.OptionParserException

Copyright © 2018 www.massapicom. 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.