package net.sourceforge.javautil.ui.command;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.javautil.common.reflection.cache.ClassDescriptor;
import net.sourceforge.javautil.common.reflection.cache.ClassMethod;
import net.sourceforge.javautil.ui.cli.CommandLineCommand;
import net.sourceforge.javautil.ui.command.UICommand.CommandArgument;
import net.sourceforge.javautil.ui.command.UICommand.CommandFlag;
import net.sourceforge.javautil.ui.command.UICommand.CommandOption;
/**
* The base for most ui command implementations.
*
* @author elponderador
* @author $Author: ponderator $
* @version $Id: UICommandAbstract.java 912 2009-09-09 20:43:46Z ponderator $
*/
public abstract class UICommandAbstract<CTX extends UICommandContext, ARG extends UICommandArguments> implements UICommand<CTX, ARG> {
protected final String name;
protected final String description;
protected final Map<String, CommandArgument> arguments = new LinkedHashMap<String, CommandArgument>();
protected final Map<String, CommandOption> options = new LinkedHashMap<String, CommandOption>();
protected final Map<String, CommandFlag> flags = new LinkedHashMap<String, CommandFlag>();
public UICommandAbstract(String name, String description) {
this.name = name;
this.description = description;
}
/**
* @param smallDesc The small description of the argument
* @param longDesc The long description of the argument
* @return This for chaining.
*/
public UICommandAbstract<CTX, ARG> addArgument (String name, Class type, String desc) {
this.arguments.put(name, new CommandArgument(name, type, desc)); return this;
}
/**
* @param name The name of the option
* @param description The description of the option
* @param defaultDesc The description of the default value for the option
* @return This for chaining.
*/
public UICommandAbstract<CTX, ARG> addOption (String name, Class type, String description, String defaultDesc) {
this.options.put(name, new CommandOption(name, type, description, defaultDesc)); return this;
}
/**
* @param desc The description of the flag
* @param defaultValue The default value for the flag
* @return This for chaining.
*/
public UICommandAbstract<CTX, ARG> addFlag (String name, String desc, boolean defaultValue) {
this.flags.put(name, new CommandFlag(name, desc, defaultValue)); return this;
}
/**
* @return The arguments currently defined
*/
public Map<String, CommandArgument> getArguments() { return new LinkedHashMap<String, CommandArgument>(arguments); }
/**
* @return The options currently defined
*/
public Map<String, CommandOption> getOptions() { return new LinkedHashMap<String, CommandOption>(options); }
/**
* @return The flags currently defined
*/
public Map<String, CommandFlag> getFlags() { return new LinkedHashMap<String, CommandFlag>(flags); }
public String getName() { return this.name; }
public String getDescription() { return this.description; }
public String toString () { return getClass().getSimpleName() + "[ " + name + ", " + description + " ]"; }
}