org.overlord.sramp.shell.api
Class AbstractShellCommand

java.lang.Object
  extended by org.overlord.sramp.shell.api.AbstractShellCommand
All Implemented Interfaces:
ShellCommand

public abstract class AbstractShellCommand
extends Object
implements ShellCommand

Base class for shell commands.

Author:
eric.wittmann@redhat.com

Constructor Summary
AbstractShellCommand()
          Constructor.
 
Method Summary
protected  Arguments getArguments()
          Gets the command's arguments.
protected  ShellContext getContext()
           
protected  String optionalArgument(int argIndex)
          Returns the optional argument at the given index.
protected  String optionalArgument(int argIndex, String defaultValue)
          Returns the optional argument at the given index.
 void print(String formattedMessage, Object... params)
          Prints the given message to the output stream.
protected  String requiredArgument(int argIndex, String message)
          Returns the argument at the given index.
 void setArguments(Arguments arguments)
          Sets the arguments that can be used by this command.
 void setContext(ShellContext context)
          The shell context.
 void setOutput(Writer output)
          Configure the command's output.
 int tabCompletion(String lastArgument, List<CharSequence> candidates)
          Handle tab completion for the command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.overlord.sramp.shell.api.ShellCommand
execute, printHelp, printUsage
 

Constructor Detail

AbstractShellCommand

public AbstractShellCommand()
Constructor.

Method Detail

setContext

public void setContext(ShellContext context)
Description copied from interface: ShellCommand
The shell context.

Specified by:
setContext in interface ShellCommand
See Also:
org.overlord.sramp.common.shell.ShellCommand#setContext(org.overlord.sramp.common.shell.ShellContext)

getContext

protected ShellContext getContext()
Returns:
the shell context

setArguments

public void setArguments(Arguments arguments)
Description copied from interface: ShellCommand
Sets the arguments that can be used by this command.

Specified by:
setArguments in interface ShellCommand
See Also:
org.overlord.sramp.common.shell.ShellCommand#setArguments(java.lang.String[])

getArguments

protected Arguments getArguments()
Gets the command's arguments.


requiredArgument

protected String requiredArgument(int argIndex,
                                  String message)
                           throws InvalidCommandArgumentException
Returns the argument at the given index. Throws an exception if the argument does not exist.

Parameters:
argIndex -
message -
Throws:
InvalidCommandArgumentException

optionalArgument

protected String optionalArgument(int argIndex)
Returns the optional argument at the given index. Returns null if the argument does not exist.

Parameters:
argIndex -

optionalArgument

protected String optionalArgument(int argIndex,
                                  String defaultValue)
Returns the optional argument at the given index. Returns the given default value if the argument does not exist.

Parameters:
argIndex -
defaultValue -

print

public void print(String formattedMessage,
                  Object... params)
Description copied from interface: ShellCommand
Prints the given message to the output stream.

Specified by:
print in interface ShellCommand
See Also:
org.overlord.sramp.common.shell.ShellCommand#print(java.lang.String, java.lang.Object[])

setOutput

public void setOutput(Writer output)
Description copied from interface: ShellCommand
Configure the command's output.

Specified by:
setOutput in interface ShellCommand
Parameters:
output - the output to set

tabCompletion

public int tabCompletion(String lastArgument,
                         List<CharSequence> candidates)
Description copied from interface: ShellCommand
Handle tab completion for the command. This is optional, but provides a mechanism by which individual commands can enable command-specific tab completion functionality. The return value of this method represents the cursor position within lastArgument that represents the origin point for all of the candidates. Return 0 to indicate that the candidates are all full-replacements of lastArgument. Return -1 to indicate that no candidates were supplied. Return a positive, non-negative value if the returned candidates are partial completions. For example, if the user has typed "aar", then a command could return any of: candidates=[] rval=-1 candidates=["aardvark", "aardwolf"] rval=0 candidates=["dvark", "dwolf"] rval=3 In the latter two examples, the tab-completion will be the same, but the user will be shown the different candidate values (when more than 1 candidate is returned).

Specified by:
tabCompletion in interface ShellCommand
Returns:
the cursor position
See Also:
org.overlord.sramp.common.shell.ShellCommand#tabCompletion(java.lang.String, java.util.List)


Copyright © 2011-2013 JBoss, a division of Red Hat. All Rights Reserved.