Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java:1.1 lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java:1.2 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java:1.1 Tue Mar 18 23:40:47 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java Sat Mar 22 06:09:34 2008 @@ -37,9 +37,9 @@ if (category.equals("all")) { for (ConfigKey configKey : context.getConfigKeys()) { - ParserUtil.printConfig(writer, context.getConfig(configKey)); - log.info(writer); + ParserUtil.printConfig(writer, context.getConfig(configKey)); } + log.info(writer); } else { if (context.getConfig(category) == null) { throw new IllegalArgumentException("could not found a configuration with category " + category); Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionHelpConfigRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionHelpConfigRunnable.java:1.1 --- /dev/null Sat Mar 22 06:09:39 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionHelpConfigRunnable.java Sat Mar 22 06:09:34 2008 @@ -0,0 +1,76 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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. ##%* + */ +package org.codelutin.option.actions; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import static org.codelutin.i18n.I18n._; +import org.codelutin.option.AbstractContext; +import org.codelutin.option.ConfigKey; +import org.codelutin.option.ConfigPropertyKey; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; +import static org.codelutin.option.ParserUtil.addTitle; +import org.codelutin.util.ReflectUtil; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +/** @author chemit */ +public class OptionActionHelpConfigRunnable implements OptionActionRunnable { + + protected final Log log = LogFactory.getLog(getClass()); + + public void run(OptionAction action) throws Exception { + AbstractContext context = action.getContext(); + String category = action.getOption().getConstantArgumentValue(0); + + log.info("required showConfig pour category [" + category + "]"); + StringWriter writer = new StringWriter(); + + if (category.equals("all")) { + for (ConfigKey configKey : context.getConfigKeys()) { + toString(writer, configKey); + } + log.info(writer); + } else { + if (context.getConfig(category) == null) { + throw new IllegalArgumentException("could not found a configuration with category " + category); + } + toString(writer, context.getConfigKey(category)); + log.info(writer); + } + + context.setQuit(true); + } + + public void toString(Writer w, ConfigKey key) throws IOException { + + String prefixConfig = _("lutinutil.parserdef.printUsage.configs.head", key.getCategory()); + String prefix = "\n"; + w.append(addTitle(prefixConfig, '-', false)).append("\n"); + w.append("\n").append(addTitle(key.getDescription() + " (" + key.getCategory() + ")", '~', false)).append("\n"); + for (ConfigPropertyKey propertyKey : ReflectUtil.getConstants(key.getAbstractConfigClass(), ConfigPropertyKey.class)) { + w.append(prefix).append(propertyKey.getKey()).append(" (").append(propertyKey.getType().getSimpleName()).append(")"); + if (propertyKey.getDefaultValue() != null) { + w.append(" "); + + } + w.append("\n ").append(propertyKey.getDescription()).append("\n\n"); + } + } + + +} \ No newline at end of file