Index: lutinutil/src/java/org/codelutin/util/OptionParser.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/OptionParser.java:1.1 --- /dev/null Mon Nov 19 20:50:17 2007 +++ lutinutil/src/java/org/codelutin/util/OptionParser.java Mon Nov 19 20:50:12 2007 @@ -0,0 +1,535 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* OptionParser.java +* +* Created: 22 août 2003 +* +* @author Benjamin Poussin +* @version $Revision: 1.1 $ +* +* Mise a jour: $Date: 2007-11-19 20:50:12 $ +* par : $Author: tchemit $ +*/ + +package org.codelutin.util; + +import org.apache.commons.beanutils.ConvertUtils; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * Parser d'options de la ligne de commande. + * + * @author poussin + * @author chemit + */ +public class OptionParser { + + public static OptionParser doParse(String name, + String fullyQualifiedFactoryName, + String... args) + throws OptionParserException { + + OptionParser parser; + + parser = new OptionParser(name); + + Map indexAlias = parser.init(fullyQualifiedFactoryName); + List contexts = null; + + if (args.length > 0) { + + // detection des contexts d'options + contexts = parser.detectOptionContexts(indexAlias, args); + } + + // verification de la coherence des options détectée par rapport aux + // definitions des options + parser.checkPostParsing(contexts); + + if (contexts != null && !contexts.isEmpty()) { + for (OptionContext context : contexts) { + parser.instanciateOption(context); + } + // on vide les contextes + contexts.clear(); + } + + return parser; + } + + + /** l'usine de définitions d'options */ + protected OptionDefinitionFactory definitionFactory; + + /** La liste des arguments qui ne sont pas des options */ + protected List arguments; + + /** le nom à afficher pour l'usage */ + protected String name; + + /** + * la liste des options, la cle est le nom de l'option, et la valeur + * est la liste des options qui ont été lues grâce à celle-ci. + */ + protected Map> options; + + /** liste a plat de toutes les options lus. */ + protected List