FileDocCategorySizeDatePackage
OptionsConsoleCommand.javaAPI DocAzureus 3.0.3.43527Thu Dec 16 05:54:38 GMT 2004org.gudy.azureus2.ui.console.commands

OptionsConsoleCommand

public abstract class OptionsConsoleCommand extends IConsoleCommand
subclass of IConsoleCommand that allows the parameters to be defined using an Options object
see
org.apache.commons.cli.Options
author
pauld

Fields Summary
private org.apache.commons.cli.Options
options
private org.apache.commons.cli.CommandLineParser
parser
Constructors Summary
public OptionsConsoleCommand(String[] commandNames)

param
commandNames

	
	  	 
	   
		super(commandNames);
	
Methods Summary
public voidexecute(java.lang.String commandName, org.gudy.azureus2.ui.console.ConsoleInput console, java.util.List arguments)
take the args and try and create a command line object

		CommandLineParser parser = getParser();
		
		try 
		{
			String []args = new String[arguments.size()];
			int i = 0;
			for (Iterator iter = arguments.iterator(); iter.hasNext();) {
				String arg = (String) iter.next();
				args[i++] = arg;
			}
			CommandLine line = parser.parse(getOptions(), args);
			execute( commandName, console, line );
		} catch (ParseException e) 
		{
			console.out.println(">> Invalid arguments: " + e.getMessage());			
//			printHelp(commandName, console.out);
			printHelp(console.out, arguments);
		}
	
public abstract voidexecute(java.lang.String commandName, org.gudy.azureus2.ui.console.ConsoleInput console, org.apache.commons.cli.CommandLine commandLine)
execute using the specified command line.

param
commandName
param
console
param
commandLine

protected org.apache.commons.cli.OptionsgetOptions()

		return options;		
	
protected org.apache.commons.cli.CommandLineParsergetParser()

return

		if( parser == null )
			parser = new PosixParser();
		return parser;
	
public voidprintHelp(java.io.PrintStream out, java.util.List args)

		HelpFormatter formatter = new HelpFormatter();
		PrintWriter writer = new PrintWriter(out);
		writer.println("> -----");
		writer.println(getCommandDescriptions());
//		formatter.printHelp(writer, 80, getCommandDescriptions(), ">>>", getOptions(), 4, 4, ">>>", true);
		formatter.printOptions(writer, 80, getOptions(), 4, 4);
		writer.println("> -----");
		writer.flush();