Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionChangeFileConfigRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionChangeFileConfigRunnable.java:1.1 --- /dev/null Tue Mar 18 23:40:52 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionChangeFileConfigRunnable.java Tue Mar 18 23:40:46 2008 @@ -0,0 +1,33 @@ +/** + * ##% 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.OptionAction; +import org.codelutin.option.OptionActionRunnable; + +import java.io.File; + +/** @author chemit */ +public class OptionActionChangeFileConfigRunnable implements OptionActionRunnable { + + public void run(OptionAction action) throws Exception { + + File source = action.getOption().getValuedArgumentValue(0, File.class, null, false); + + if (source.exists()) { + action.getContext().setSource(source); + } + + } +} \ No newline at end of file Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionUiRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionUiRunnable.java:1.1 --- /dev/null Tue Mar 18 23:40:52 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionUiRunnable.java Tue Mar 18 23:40:47 2008 @@ -0,0 +1,40 @@ +/** + * ##% 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.AbstractContext; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; + +/** @author chemit */ +public class OptionActionUiRunnable implements OptionActionRunnable { + + protected final Log log = LogFactory.getLog(getClass()); + + protected boolean init = false; + + 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); + } + init = true; + } +} \ No newline at end of file Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionChangeConfigRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionChangeConfigRunnable.java:1.1 --- /dev/null Tue Mar 18 23:40:52 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionChangeConfigRunnable.java Tue Mar 18 23:40:47 2008 @@ -0,0 +1,88 @@ +/** + * ##% 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.Config; +import org.codelutin.option.ConfigKey; +import org.codelutin.option.ConfigPropertyKey; +import org.codelutin.option.Option; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; + +/** + * OptionAction to change a property in a config. + * + * @author chemit + */ +public class OptionActionChangeConfigRunnable implements OptionActionRunnable { + + protected final Log log = LogFactory.getLog(getClass()); + + public void run(OptionAction action) throws Exception { + + Option option = action.getOption(); + + AbstractContext context = action.getContext(); + + String category = getCategory(context, action.getOption()); + + ConfigKey configKey = context.getConfigKey(category); + + Config config = context.getConfig(configKey); + + if (config == null) { + //TODO log warning + return; + } + + String key = option.getValuedArgumentValue(0, String.class, null, false); + + String value = option.getValuedArgumentValue(1, String.class, null, false); + + ConfigPropertyKey propKey = config.getPropertyKey(key); + + if (propKey == null) { + // fatal error , could not found a matching configuration property + throw new IllegalArgumentException(_("lutinutil.error.unfound.config.property", category, key)); + } + Object oldVal = propKey.getCurrentValue(); + config.setProperty(propKey, value); + Object newVal = propKey.getCurrentValue(); + + log.info(_("lutinutil.change.config.property", category, propKey, oldVal, newVal)); + + + } + + + /** + * @param context current context + * @param option the option to test + * @return the category of an IsisOptionConfig + */ + 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.getConfigKey(value); + return configKey == null ? null : configKey.getCategory(); + } + +} Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java:1.1 --- /dev/null Tue Mar 18 23:40:52 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionShowConfigRunnable.java Tue Mar 18 23:40:47 2008 @@ -0,0 +1,55 @@ +/** + * ##% 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.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; + +/** @author chemit */ +public class OptionActionShowConfigRunnable 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()) { + 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); + } + ParserUtil.printConfig(writer, context.getConfig(category)); + log.info(writer); + } + + context.setQuit(true); + } + + +} Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionHelpRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionHelpRunnable.java:1.1 --- /dev/null Tue Mar 18 23:40:52 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionHelpRunnable.java Tue Mar 18 23:40:47 2008 @@ -0,0 +1,40 @@ +/** + * ##% 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.AbstractContext; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; + +import java.io.StringWriter; + +/** @author chemit */ +public class OptionActionHelpRunnable implements OptionActionRunnable { + + protected final Log log = LogFactory.getLog(getClass()); + + 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); + } +} \ No newline at end of file Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionEditConfigRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionEditConfigRunnable.java:1.1 --- /dev/null Tue Mar 18 23:40:52 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionEditConfigRunnable.java Tue Mar 18 23:40:47 2008 @@ -0,0 +1,44 @@ +/** + * ##% 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.AbstractContext; +import org.codelutin.option.Config; +import org.codelutin.option.ConfigKey; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; + +/** @author chemit */ +public class OptionActionEditConfigRunnable implements OptionActionRunnable { + + protected final Log log = LogFactory.getLog(getClass()); + + static public final String UI_FQN = "org.codelutin.option.ui.ConfigUI"; + + 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}); + ui.setVisible(true); + } +} \ No newline at end of file Index: lutincommandline/src/java/org/codelutin/option/actions/OptionActionResetConfigRunnable.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/actions/OptionActionResetConfigRunnable.java:1.1 --- /dev/null Tue Mar 18 23:40:52 2008 +++ lutincommandline/src/java/org/codelutin/option/actions/OptionActionResetConfigRunnable.java Tue Mar 18 23:40:47 2008 @@ -0,0 +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 static org.codelutin.i18n.I18n._; +import org.codelutin.option.AbstractContext; +import org.codelutin.option.OptionAction; +import org.codelutin.option.OptionActionRunnable; + +import java.io.File; + +/** @author chemit */ +public class OptionActionResetConfigRunnable implements OptionActionRunnable { + + protected final Log log = LogFactory.getLog(getClass()); + + 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); + } +} \ No newline at end of file