Package edu.uiuc.ncsa.security.util.cli
Class CLIDriver
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.CLIDriver
-
- Direct Known Subclasses:
SASCLIDriver
,SASServerSideCLiDriver
public class CLIDriver extends Object
A driver program that does introspection on a set of CLICommandsCreated by Jeff Gaynor
on 5/17/13 at 3:01 PM
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description CLIDriver()
CLIDriver(Commands... cci)
CLIDriver(IOInterface ioInterface)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCommands(Commands... cci)
protected void
batchFileHelp()
InputLine
bootstrap(InputLine argLine)
InputLine
bootstrap(String[] args)
This method is charged with interpreting the command line arguments and setting up the state for this CLI driver.protected void
doBufferRead(String cmdLine)
protected void
doBufferWrite(String cmdLine)
protected void
doHelp(InputLine inputLine)
protected String
doHistory(String cmdLine)
protected String
doRepeatCommand(String cmdLine)
int
execute(InputLine cliAV)
Returns a logical true if one of the command lines executes the line successfully.int
execute(String cmdLine)
Commands[]
getCLICommands()
static CLIDriver
getCLIDriver()
List<String>
getCommandHistory()
ComponentManager
getComponentManager()
String
getCurrentEnvFile()
Map
getEnv()
HelpUtil
getHelpUtil()
IOInterface
getIOInterface()
String
getLineCommentStart()
MyLoggingFacade
getLogger()
String
getOutputFile()
String
getRunLine()
static boolean
hasCLIDriver()
boolean
hasComments()
If a comment delimiter has been set for this component.boolean
hasEnv()
boolean
hasInputFile()
boolean
hasOutputFile()
boolean
isOutputOn()
boolean
isRunLineMode()
boolean
isTraceOn()
Boolean
isTrue(String raw)
This checks that the string is one of the allowed trues or false.boolean
isVerbose()
protected void
listCLIMethods(InputLine inputLine)
static void
main(String[] args)
protected void
NEWstart()
protected boolean
noPrompt()
protected void
printHelp()
protected void
printHelpTopics(InputLine inputLine)
protected void
processLine(String cmdLine)
protected void
processRunLine()
Process a line to run.void
quit(InputLine inputLine)
protected void
readEnv(String path, boolean verbose)
protected String
readline(String prompt)
protected void
say(String x)
For use with informational messages.protected void
sayv(String x)
Conditional output if in verbose mode only.protected void
setCLICommands(Commands[] commands)
static void
setCLIDriver(CLIDriver driver)
void
setCommandHistory(List<String> commandHistory)
void
setComponentManager(ComponentManager componentManager)
void
setCurrentEnvFile(String currentEnvFile)
void
setEnv(Map env)
void
setHasInputFile(boolean hasInputFile)
void
setHelpUtil(HelpUtil helpUtil)
void
setIOInterface(IOInterface ioInterface)
This also sets any components you added.void
setLineCommentStart(String lineCommentStart)
void
setLogger(MyLoggingFacade logger)
void
setOutputFile(String outputFile)
void
setOutputOn(boolean outputOn)
void
setRunLine(String runLine)
void
setRunLineMode(boolean runLineMode)
void
setTraceOn(boolean traceOn)
void
setVerbose(boolean verbose)
protected void
shutdown()
void
start()
Actual method that starts up this driver and sets out prompts etc.
-
-
-
Field Detail
-
EXIT_COMMAND
public static final String EXIT_COMMAND
If a user enters this string at any point, the current operation should end. An ExitException is thrown.- See Also:
- Constant Field Values
-
ECHO_COMMAND
public static final String ECHO_COMMAND
- See Also:
- Constant Field Values
-
lineCommentStart
protected String lineCommentStart
-
OK_RC
public static final int OK_RC
- See Also:
- Constant Field Values
-
ABNORMAL_RC
public static final int ABNORMAL_RC
- See Also:
- Constant Field Values
-
USER_EXIT_RC
public static final int USER_EXIT_RC
- See Also:
- Constant Field Values
-
SHUTDOWN_RC
public static final int SHUTDOWN_RC
- See Also:
- Constant Field Values
-
HELP_RC
public static final int HELP_RC
- See Also:
- Constant Field Values
-
HELP_SWITCH
public static final String HELP_SWITCH
- See Also:
- Constant Field Values
-
PRINT_HELP_COMMAND
public static final String PRINT_HELP_COMMAND
- See Also:
- Constant Field Values
-
CLEAR_BUFFER_COMMAND
public static final String CLEAR_BUFFER_COMMAND
- See Also:
- Constant Field Values
-
LOAD_BUFFER_COMMAND
public static final String LOAD_BUFFER_COMMAND
- See Also:
- Constant Field Values
-
HISTORY_LIST_COMMAND
public static final String HISTORY_LIST_COMMAND
- See Also:
- Constant Field Values
-
SHORT_EXIT_COMMAND
public static final String SHORT_EXIT_COMMAND
- See Also:
- Constant Field Values
-
REPEAT_LAST_COMMAND
public static final String REPEAT_LAST_COMMAND
- See Also:
- Constant Field Values
-
WRITE_BUFFER_COMMAND
public static final String WRITE_BUFFER_COMMAND
- See Also:
- Constant Field Values
-
COMPONENT_COMMAND
public static final String COMPONENT_COMMAND
- See Also:
- Constant Field Values
-
LIST_ALL_METHODS_COMMAND
public static final String LIST_ALL_METHODS_COMMAND
- See Also:
- Constant Field Values
-
TRACE_COMMAND
public static final String TRACE_COMMAND
- See Also:
- Constant Field Values
-
ONLINE_HELP_COMMAND
public static final String ONLINE_HELP_COMMAND
- See Also:
- Constant Field Values
-
DUMMY_FUNCTION
protected static String DUMMY_FUNCTION
-
INPUT_FILE_FLAG
protected static final String INPUT_FILE_FLAG
- See Also:
- Constant Field Values
-
OUTPUT_FILE_FLAG
protected static final String OUTPUT_FILE_FLAG
- See Also:
- Constant Field Values
-
RUN_COMMAND_FLAG
protected static final String RUN_COMMAND_FLAG
- See Also:
- Constant Field Values
-
TERMINAL_TYPE_FLAG
protected static final String TERMINAL_TYPE_FLAG
- See Also:
- Constant Field Values
-
TERMINAL_TYPE_ANSI
protected static final String TERMINAL_TYPE_ANSI
- See Also:
- Constant Field Values
-
TERMINAL_TYPE_TEXT
protected static final String TERMINAL_TYPE_TEXT
- See Also:
- Constant Field Values
-
TERMINAL_TYPE_ASCII
protected static final String TERMINAL_TYPE_ASCII
- See Also:
- Constant Field Values
-
SHORT_VERBOSE_FLAG
protected static final String SHORT_VERBOSE_FLAG
- See Also:
- Constant Field Values
-
LONG_VERBOSE_FLAG
protected static final String LONG_VERBOSE_FLAG
- See Also:
- Constant Field Values
-
SHORT_SET_OUTPUT_FLAG
protected static final String SHORT_SET_OUTPUT_FLAG
- See Also:
- Constant Field Values
-
LONG_SET_OUTPUT_FLAG
protected static final String LONG_SET_OUTPUT_FLAG
- See Also:
- Constant Field Values
-
SILENT_FLAG
protected static final String SILENT_FLAG
- See Also:
- Constant Field Values
-
ENVIRONMENT_FLAG
protected static final String ENVIRONMENT_FLAG
- See Also:
- Constant Field Values
-
LOG_FLAG
protected static final String LOG_FLAG
- See Also:
- Constant Field Values
-
LOGICAL_TRUES
public static String[] LOGICAL_TRUES
Strings that this will treat as equivalent to logical true.
-
LOGICAL_FALSES
public static String[] LOGICAL_FALSES
Strings this will treat as equivalent to logical false.
-
-
Constructor Detail
-
CLIDriver
public CLIDriver()
-
CLIDriver
public CLIDriver(Commands... cci)
-
CLIDriver
public CLIDriver(IOInterface ioInterface)
-
-
Method Detail
-
getLineCommentStart
public String getLineCommentStart()
-
setLineCommentStart
public void setLineCommentStart(String lineCommentStart)
-
hasComments
public boolean hasComments()
If a comment delimiter has been set for this component. If so, then lines that start with this are ignored.- Returns:
-
getEnv
public Map getEnv()
-
setEnv
public void setEnv(Map env)
-
hasEnv
public boolean hasEnv()
-
addCommands
public void addCommands(Commands... cci)
-
getCLICommands
public Commands[] getCLICommands()
-
setCLICommands
protected void setCLICommands(Commands[] commands)
-
noPrompt
protected boolean noPrompt()
-
readline
protected String readline(String prompt) throws IOException
- Throws:
IOException
-
printHelp
protected void printHelp()
-
getComponentManager
public ComponentManager getComponentManager()
-
setComponentManager
public void setComponentManager(ComponentManager componentManager)
-
start
public void start()
Actual method that starts up this driver and sets out prompts etc. for the user to use interactively.- Throws:
Exception
-
NEWstart
protected void NEWstart()
-
isTraceOn
public boolean isTraceOn()
-
setTraceOn
public void setTraceOn(boolean traceOn)
-
execute
public int execute(String cmdLine)
-
execute
public int execute(InputLine cliAV)
Returns a logical true if one of the command lines executes the line successfully. This will also throw a shutdown exception if the user asks it to... Otherwise, it returns false;- Parameters:
cliAV
-- Returns:
-
getHelpUtil
public HelpUtil getHelpUtil()
-
setHelpUtil
public void setHelpUtil(HelpUtil helpUtil)
-
doHelp
protected void doHelp(InputLine inputLine)
-
printHelpTopics
protected void printHelpTopics(InputLine inputLine)
-
listCLIMethods
protected void listCLIMethods(InputLine inputLine)
-
quit
public void quit(InputLine inputLine)
-
shutdown
protected void shutdown()
-
say
protected void say(String x)
For use with informational messages.- Parameters:
x
-
-
sayv
protected void sayv(String x)
Conditional output if in verbose mode only.- Parameters:
x
-
-
getIOInterface
public IOInterface getIOInterface()
-
setIOInterface
public void setIOInterface(IOInterface ioInterface)
This also sets any components you added.- Parameters:
ioInterface
-
-
processRunLine
protected void processRunLine()
Process a line to run. At invocation you may use something likecli
and what happens is that everything after the flag is fed tot he processor and executed as a single command, as if you'd type inRUN_COMMAND_FLAG
A B CA B C
This lets you do things likecli -run use clients
to start a component right away.
-
batchFileHelp
protected void batchFileHelp()
-
main
public static void main(String[] args)
-
hasOutputFile
public boolean hasOutputFile()
-
getOutputFile
public String getOutputFile()
-
setOutputFile
public void setOutputFile(String outputFile)
-
getLogger
public MyLoggingFacade getLogger()
-
setLogger
public void setLogger(MyLoggingFacade logger)
-
isVerbose
public boolean isVerbose()
-
setVerbose
public void setVerbose(boolean verbose)
-
isOutputOn
public boolean isOutputOn()
-
setOutputOn
public void setOutputOn(boolean outputOn)
-
isRunLineMode
public boolean isRunLineMode()
-
setRunLineMode
public void setRunLineMode(boolean runLineMode)
-
getRunLine
public String getRunLine()
-
setRunLine
public void setRunLine(String runLine)
-
bootstrap
public InputLine bootstrap(String[] args)
This method is charged with interpreting the command line arguments and setting up the state for this CLI driver. State includesgetLogger()
- the logger, if specifiedisRunLineMode()
- if theRUN_COMMAND_FLAG
was usedisOutputOn()
- suppress all output if trueisVerbose()
- how chatty this should beIOInterface
Commands
are not altered after that. So either create aCLIDriver
, set your components and call this to inject the state, or create this, call this method and then add your components. You callstart()
to being interactive processingprocessRunLine()
to run the single command.
- Parameters:
args
-- Returns:
- The
InputLine
after all recognized flags have been processed. This means they are stripped.
-
hasInputFile
public boolean hasInputFile()
-
setHasInputFile
public void setHasInputFile(boolean hasInputFile)
-
hasCLIDriver
public static boolean hasCLIDriver()
-
setCLIDriver
public static void setCLIDriver(CLIDriver driver)
-
getCLIDriver
public static CLIDriver getCLIDriver()
-
readEnv
protected void readEnv(String path, boolean verbose)
-
getCurrentEnvFile
public String getCurrentEnvFile()
-
setCurrentEnvFile
public void setCurrentEnvFile(String currentEnvFile)
-
-