Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableEditConfig.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableEditConfig.java:1.3 lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableEditConfig.java:1.4 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableEditConfig.java:1.3 Sun Mar 16 21:15:58 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableEditConfig.java Mon Mar 17 22:39:33 2008 @@ -1,3 +1,16 @@ +/** + * ##% 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; @@ -15,12 +28,14 @@ static public final String UI_FQN = "org.codelutin.option.ui.ConfigUI"; - public void run(OptionAction action, AbstractContext context) throws Exception { - int nbConfigs = context.getParser().getConfigKeys().size(); - Config[] configs = new Config[nbConfigs]; - for (int i = 0; i < nbConfigs; i++) { - ConfigKey configKey = context.getParser().getConfigKeys().get(i); - configs[i] = context.getParser().getConfig(configKey); + public void run(OptionAction action) throws Exception { + + AbstractContext context = action.getContext(); + + Config[] configs = new Config[context.getConfigKeys().size()]; + int i = 0; + for (ConfigKey o : context.getConfigKeys()) { + configs[i++] = context.getConfig(o); } javax.swing.JDialog ui = (javax.swing.JDialog) Class.forName(UI_FQN).newInstance(); ui.getClass().getMethod("init", AbstractContext.class, Config[].class).invoke(context, ui, new Object[]{configs}); Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableShowConfig.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableShowConfig.java:1.1 lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableShowConfig.java:1.2 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableShowConfig.java:1.1 Sun Mar 16 11:08:27 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableShowConfig.java Mon Mar 17 22:39:33 2008 @@ -1,11 +1,24 @@ +/** + * ##% 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 org.codelutin.option.OptionActionRunnable; -import org.codelutin.option.OptionAction; import org.codelutin.option.AbstractContext; import org.codelutin.option.ConfigKey; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; import org.codelutin.option.ParserUtil; import java.io.StringWriter; @@ -15,22 +28,28 @@ protected final Log log = LogFactory.getLog(getClass()); - public void run(OptionAction action, AbstractContext context) throws Exception { + public void run(OptionAction action) throws Exception { + AbstractContext context = action.getContext(); String category = action.getOption().getConstantArgumentValue(0); - if (context.getConfig() == null) { - throw new IllegalArgumentException("could not found a configuration with category " + category); - } + log.info("required showConfig pour category [" + category + "]"); StringWriter writer = new StringWriter(); + if (category.equals("all")) { - for (ConfigKey configKey : context.getParser().getConfigKeys()) { - ParserUtil.printConfig(writer, context.getParser().getConfig(configKey)); + for (ConfigKey configKey : context.getConfigKeys()) { + ParserUtil.printConfig(writer, context.getConfig(configKey)); log.info(writer); } - } else { - ParserUtil.printConfig(writer, context.getParser().getConfig(category)); + } else { + if (context.getConfig(category) == null) { + throw new IllegalArgumentException("could not found a configuration with category " + category); + } + ParserUtil.printConfig(writer, context.getConfig(category)); log.info(writer); } + context.setQuit(true); } + + } Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeConfig.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeConfig.java:1.2 lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeConfig.java:1.3 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeConfig.java:1.2 Sun Mar 16 21:15:58 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeConfig.java Mon Mar 17 22:39:33 2008 @@ -1,3 +1,16 @@ +/** + * ##% 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; @@ -11,24 +24,29 @@ import org.codelutin.option.OptionAction; import org.codelutin.option.OptionActionRunnable; -/** @author chemit */ +/** + * OptionAction to change a property in a config. + * + * @author chemit + */ public class OptionActionRunnableChangeConfig implements OptionActionRunnable { protected final Log log = LogFactory.getLog(getClass()); - public void run(OptionAction action, AbstractContext context) throws Exception { - // Do nothing, this action is treated while init of config file - //TODO transfert logic from config to here (to make change of behevior possible more easier) - // surcharge config + public void run(OptionAction action) throws Exception { Option option = action.getOption(); - String category = getCategory(context, option); - ConfigKey configKey = context.getParser().getConfigKey(category); + AbstractContext context = action.getContext(); - Config config = context.getParser().getConfig(configKey); + String category = getCategory(context, action.getOption()); + + ConfigKey configKey = context.getConfigKey(category); + + Config config = context.getConfig(configKey); if (config == null) { + //TODO log warning return; } @@ -51,6 +69,7 @@ } + /** * @param context current context * @param option the option to test @@ -59,9 +78,11 @@ protected String getCategory(AbstractContext context, Option option) { String value = option.getConstantArgumentValue(-1); if (value == null) { + // used by default main category value = "main"; } - ConfigKey configKey = context.getParser().getConfigKey(value); + ConfigKey configKey = context.getConfigKey(value); return configKey == null ? null : configKey.getCategory(); } + } Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableHelp.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableHelp.java:1.1 lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableHelp.java:1.2 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableHelp.java:1.1 Sun Mar 16 11:08:27 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableHelp.java Mon Mar 17 22:39:33 2008 @@ -1,19 +1,38 @@ +/** + * ##% 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 org.codelutin.option.OptionActionRunnable; -import org.codelutin.option.OptionAction; import org.codelutin.option.AbstractContext; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; + +import java.io.StringWriter; /** @author chemit */ public class OptionActionRunnableHelp implements OptionActionRunnable { protected final Log log = LogFactory.getLog(getClass()); - public void run(OptionAction action, AbstractContext context) throws Exception { - java.io.StringWriter writer = new java.io.StringWriter(); - context.getParser().printUsage(writer, "SimExplorer SI v " + context.getConfig().getPropertyKey("version").getCurrentValue()); + public void run(OptionAction action) throws Exception { + + AbstractContext context = action.getContext(); + + StringWriter writer = new StringWriter(); + String title = "TODO Add project name v " + context.getMainConfig().getPropertyKey("version").getCurrentValue(); + context.getParser().printUsage(writer, title); //TODO should be able to register writer System.out.println(writer); context.setQuit(true); Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableResetConfig.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableResetConfig.java:1.1 lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableResetConfig.java:1.2 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableResetConfig.java:1.1 Sun Mar 16 11:08:27 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableResetConfig.java Mon Mar 17 22:39:33 2008 @@ -1,3 +1,16 @@ +/** + * ##% 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; @@ -14,8 +27,10 @@ protected final Log log = LogFactory.getLog(getClass()); - public void run(OptionAction action, AbstractContext context) throws Exception { - File property = (File) context.getConfig().getProperty("configFileName"); + public void run(OptionAction action) throws Exception { + AbstractContext context = action.getContext(); + + File property = (File) context.getMainConfig().getProperty("configFileName"); property.delete(); log.info(_("lutinutil.message.reset.user.configuration")); context.setFirstLaunch(true); Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeFileConfig.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeFileConfig.java:1.2 lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeFileConfig.java:1.3 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeFileConfig.java:1.2 Sun Mar 16 21:15:58 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableChangeFileConfig.java Mon Mar 17 22:39:33 2008 @@ -1,23 +1,32 @@ +/** + * ##% 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.codelutin.option.OptionActionRunnable; import org.codelutin.option.OptionAction; -import org.codelutin.option.AbstractContext; -import org.codelutin.option.Option; +import org.codelutin.option.OptionActionRunnable; import java.io.File; /** @author chemit */ public class OptionActionRunnableChangeFileConfig implements OptionActionRunnable { - public void run(OptionAction action, AbstractContext context) throws Exception { - - Option option = action.getOption(); + public void run(OptionAction action) throws Exception { - File source = option.getValuedArgumentValue(0, File.class,null,false); + File source = action.getOption().getValuedArgumentValue(0, File.class, null, false); if (source.exists()) { - context.setSource(source); + action.getContext().setSource(source); } } Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableUi.java diff -u lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableUi.java:1.1 lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableUi.java:1.2 --- lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableUi.java:1.1 Sun Mar 16 11:08:27 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionRunnableUi.java Mon Mar 17 22:39:33 2008 @@ -1,10 +1,23 @@ +/** + * ##% 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 org.codelutin.option.OptionActionRunnable; -import org.codelutin.option.OptionAction; import org.codelutin.option.AbstractContext; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; /** @author chemit */ public class OptionActionRunnableUi implements OptionActionRunnable { @@ -13,13 +26,15 @@ protected boolean init = false; - public void run(OptionAction action, AbstractContext context) throws Exception { - // Do nothing, this action is treated while init of config file + public void run(OptionAction action) throws Exception { + AbstractContext context = action.getContext(); Boolean bool = action.getOption().getValuedArgumentValue(0, Boolean.class, "flag", false); boolean launchUI = bool != null && bool; log.info(action.getOption().getUsedAlias() + ", value:" + bool); context.setLaunchUI(launchUI); - if (init) context.setQuit(true); + if (init) { + context.setQuit(true); + } init = true; } } \ No newline at end of file