Index: lutinutil/src/java/org/codelutin/util/OptionParser.java diff -u lutinutil/src/java/org/codelutin/util/OptionParser.java:1.8 lutinutil/src/java/org/codelutin/util/OptionParser.java:1.9 --- lutinutil/src/java/org/codelutin/util/OptionParser.java:1.8 Wed Dec 12 22:11:52 2007 +++ lutinutil/src/java/org/codelutin/util/OptionParser.java Thu Dec 13 01:29:10 2007 @@ -336,7 +336,7 @@ int lastPosition; int pos = 0; String key = optionDefinition.key; - OptionGroupArgumentDefinition optionalGroup = getOptionalGroupDefinition(key); + OptionGroupArgumentDefinition[] optionalGroup = getOptionalGroupDefinition(key); OptionGroupArgumentDefinition[] mandatoriesGroup = getMandatoryGroupDefinition(key); OptionGroupArgumentDefinition group = null; @@ -351,15 +351,13 @@ // try to find a mandatory group to matching from the // current one - while (pos < max) { + while (co == null && pos < max) { // take current group group = mandatoriesGroup[pos]; // try to find it in the group co = detectArgumentDefinition(argument, group); - - if (co != null) { // found in this group - break; - } else { // go to next group + if (co == null) { + // try next group pos++; } } @@ -367,10 +365,16 @@ if (co == null) { // put back pos pos = lastPosition; - if (optionalGroup != null) { - group = optionalGroup; + if (optionalGroup != null && optionalGroup.length > 0) { + int optionIndex = 0; // try in optional group - co = detectArgumentDefinition(argument, group); + while (co == null && optionIndex < optionalGroup.length) { + group = optionalGroup[optionIndex]; + co = detectArgumentDefinition(argument, group); + if (co == null) { + optionIndex++; + } + } } } if (co == null) { @@ -384,6 +388,14 @@ log.info(argument + " : " + co); if (group.pos > -1) { pos = group.pos; + // we found a matching argument + if (co.getMax() == 1) { + // the argument is not repetable, so go to next group + pos++; + } else { + //TODO We should a marker to say we are on a repetable argument + //TODO to guess the next one argument with this definition + } } checkAndAddOptionArgument(co, group.pos, argument, valueStr, result); } @@ -463,9 +475,10 @@ addError(_("could not convert argument value {0} to type {1}", valueStr, valueType.name())); return; } - if (definition.max != -1 && list.size() == definition.max) { - addError(_("too much of this argument {0} was found (maximum {1})", definition, definition.max)); - return; + if (definition.max != -1) { + //TODO Test the number of time of this argument in list + //addError(_("too much of this argument {0} was found (maximum {1})", definition, definition.max)); + //return; } // the argument is valid, save it @@ -475,7 +488,7 @@ definition.valueType, pos, argument, - valueStr + value ); log.info("success for " + definition.key + " : " + optionArgument); list.add(optionArgument); @@ -486,14 +499,15 @@ return _odefinitions.get(key); } - public OptionGroupArgumentDefinition getOptionalGroupDefinition(String key) { + public OptionGroupArgumentDefinition[] getOptionalGroupDefinition(String key) { OptionDefinition definition = _odefinitions.get(key); + List result = new ArrayList(); for (OptionGroupArgumentDefinition group : definition.groups) { if (!group.isMandatory()) { - return group; + result.add(group); } } - return null; + return result.toArray(new OptionGroupArgumentDefinition[result.size()]); } public OptionGroupArgumentDefinition[] getMandatoryGroupDefinition(String key) {