Package edu.uiuc.ncsa.security.util.cli
Class CommonCommands
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.CommonCommands
-
- All Implemented Interfaces:
Logable,Commands,Serializable
- Direct Known Subclasses:
StoreCommands
public abstract class CommonCommands extends Object implements Commands
Utilities that are used by any reasonable implementation of the Commands interface. You need to extend this for your command processor.Created by Jeff Gaynor
on 10/30/13 at 4:14 PM- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected StringCL_INPUT_FILE_FLAGprotected StringCL_OUTPUT_FILE_FLAGprotected static StringDEFAULT_NULL_VALUE_PLACEHOLDERprotected StringdefaultIndentprotected CLIDriverdriverstatic StringINDENTprotected MyLoggingFacadeloggerStringplaceHolderThis is used wherever a missing value is.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommonCommands(MyLoggingFacade logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputLinebootstrap(InputLine inputLine)voidclear_env(InputLine inputLine)protected voidclearEnvHelp()voiddebug(String x)Write a debug message to the log.voidecho(InputLine inputLine)protected voidechoHelp()voiderror(String x)Write an error message to the log.voidget_env(InputLine inputline)BufferedReadergetBufferedReader()CLIDrivergetDriver()Back reference to the driver that manages this instance.HelpUtilgetHelpUtil()protected StringgetInput(String prompt, String defaultValue)Creates the input prompt and shows the supplied default value.IOInterfacegetIOInterface()StringgetPlaceHolder()Gets the placeholder for missing values.protected StringgetPropertyHelp(String propertyName, String prompt, String defaultValue)Use this to get a property and also allow for getting help.protected StringgetValue(String x)Returns the value if it is not empty of a placeholder if it is.protected booleangracefulExit(boolean exitNow, String msg)Exit gracefully.intindentWidth()voidinfo(String x)Write an informational message to the logprotected voidinitHelp()booleanisDebugOn()Query if debugging is enabled for this logger.protected booleanisEmpty(String x)protected booleanisOk(String x)booleanisPrintOuput()If this is set true, then no output is generated.booleanisVerbose()protected voidlogit(String x)voidprint_env(InputLine inputLine)protected voidprintEnvHelp()protected voidprintGetEnvHelp()protected voidprintReadEnvHelp()protected voidprintSaveEnvHelp()protected voidprintSetEnvHelp()voidread_env(InputLine inputline)protected StringreadFile(String filename)read a text file and return a single string of the content.protected net.sf.json.JSONObjectreadJSON(String filename)protected Stringreadline()protected Stringreadline(String prompt)voidsave_env(InputLine inputLine)protected voidsay()Linefeed.protected voidsay(String x)Prints with the default indent and a linefeed.protected voidsay2(String x)Output the string without any linefeed.protected voidsayi(String x)prints with the current indent and a linefeed.protected voidsayii(String x)Double indent -- useful for lists.protected voidsayv(String x)Use this for verbose mode.voidset_env(InputLine inputline)voidset_output_on(InputLine inputLine)voidset_verbose_on(InputLine inputLine)So batch files can change whether or not they are verbosevoidsetBufferedReader(BufferedReader bufferedReader)voidsetDebugOn(boolean setOn)Enable/disable debugging for this loggervoidsetDriver(CLIDriver driver)voidsetHelpUtil(HelpUtil helpUtil)protected voidsetOutputOnHelp()voidsetPlaceHolder(String placeHolder)voidsetPrintOuput(boolean printOuput)voidsetVerbose(boolean verbose)protected voidsetVerboseHelp()protected booleanshowHelp(InputLine inputLine)returns "true if the command has the flag --help in it.voidversion(InputLine inputLine)protected voidversionHelp()voidwarn(String x)Write a warning to the log.
-
-
-
Field Detail
-
logger
protected transient MyLoggingFacade logger
-
defaultIndent
protected String defaultIndent
-
INDENT
public static final String INDENT
- See Also:
- Constant Field Values
-
DEFAULT_NULL_VALUE_PLACEHOLDER
protected static String DEFAULT_NULL_VALUE_PLACEHOLDER
-
placeHolder
public String placeHolder
This is used wherever a missing value is.
-
driver
protected transient CLIDriver driver
-
CL_OUTPUT_FILE_FLAG
protected String CL_OUTPUT_FILE_FLAG
-
CL_INPUT_FILE_FLAG
protected String CL_INPUT_FILE_FLAG
-
-
Constructor Detail
-
CommonCommands
protected CommonCommands(MyLoggingFacade logger) throws Throwable
- Throws:
Throwable
-
-
Method Detail
-
debug
public void debug(String x)
Description copied from interface:LogableWrite a debug message to the log.
-
error
public void error(String x)
Description copied from interface:LogableWrite an error message to the log. Typically this is invoked as the last command before throwing an exception.
-
info
public void info(String x)
Description copied from interface:LogableWrite an informational message to the log
-
isDebugOn
public boolean isDebugOn()
Description copied from interface:LogableQuery if debugging is enabled for this logger.
-
setDebugOn
public void setDebugOn(boolean setOn)
Description copied from interface:LogableEnable/disable debugging for this logger- Specified by:
setDebugOnin interfaceLogable
-
warn
public void warn(String x)
Description copied from interface:LogableWrite a warning to the log. This indicates a severe, but non-fatal condition exists.
-
indentWidth
public int indentWidth()
-
getBufferedReader
public BufferedReader getBufferedReader()
-
setBufferedReader
public void setBufferedReader(BufferedReader bufferedReader)
-
getIOInterface
public IOInterface getIOInterface()
- Specified by:
getIOInterfacein interfaceCommands
-
readline
protected String readline(String prompt) throws IOException
- Throws:
IOException
-
readline
protected String readline()
-
say
protected void say(String x)
Prints with the default indent and a linefeed.- Parameters:
x-
-
say
protected void say()
Linefeed.
-
sayi
protected void sayi(String x)
prints with the current indent and a linefeed.- Parameters:
x-
-
sayii
protected void sayii(String x)
Double indent -- useful for lists.- Parameters:
x-
-
say2
protected void say2(String x)
Output the string without any linefeed. This is used for prompts.- Parameters:
x-
-
showHelp
protected boolean showHelp(InputLine inputLine)
returns "true if the command has the flag --help in it. This is a cue from the user to show the help for a given function. So it the function is called "X" and its help is in the function "showXHelp" then a value of true from this should simply invoke "showXHelp" and return.- Parameters:
inputLine-- Returns:
-
isOk
protected boolean isOk(String x)
-
getInput
protected String getInput(String prompt, String defaultValue) throws IOException
Creates the input prompt and shows the supplied default value. This returns the default if the default value is chosen and the input value otherwise. If supplied the default value is a null, then this is shown too.- Parameters:
prompt-defaultValue-- Returns:
- Throws:
IOException
-
getPropertyHelp
protected String getPropertyHelp(String propertyName, String prompt, String defaultValue) throws IOException
Use this to get a property and also allow for getting help. This is justgetInput(String, String)but with the optional lookup of help for the propertyName if the user enters --help or /help. It will then re-prompt for the input.- Parameters:
propertyName-prompt-defaultValue-- Returns:
- Throws:
IOException
-
isEmpty
protected boolean isEmpty(String x)
-
getPlaceHolder
public String getPlaceHolder()
Gets the placeholder for missing values. E.g. if a value (like a last name) is missing this will be displayed.- Returns:
-
setPlaceHolder
public void setPlaceHolder(String placeHolder)
-
getValue
protected String getValue(String x)
Returns the value if it is not empty of a placeholder if it is.- Parameters:
x-- Returns:
-
getDriver
public CLIDriver getDriver()
Description copied from interface:CommandsBack reference to the driver that manages this instance.
-
printReadEnvHelp
protected void printReadEnvHelp()
-
printSetEnvHelp
protected void printSetEnvHelp()
-
printGetEnvHelp
protected void printGetEnvHelp()
-
printSaveEnvHelp
protected void printSaveEnvHelp()
-
printEnvHelp
protected void printEnvHelp()
-
clearEnvHelp
protected void clearEnvHelp()
-
gracefulExit
protected boolean gracefulExit(boolean exitNow, String msg)Exit gracefully. That is to say, if the exitNow flag is true, do a system shutdown in batch mode and otherwise, do nothing. If the flag is true and the mode is interactive, then print the message and return true, prompting the system to return;- Parameters:
exitNow-msg-- Returns:
-
sayv
protected void sayv(String x)
Use this for verbose mode.- Parameters:
x-
-
logit
protected void logit(String x)
-
isVerbose
public boolean isVerbose()
-
setVerboseHelp
protected void setVerboseHelp()
-
set_verbose_on
public void set_verbose_on(InputLine inputLine) throws Exception
So batch files can change whether or not they are verbose- Parameters:
inputLine-- Throws:
Exception
-
setVerbose
public void setVerbose(boolean verbose)
-
isPrintOuput
public boolean isPrintOuput()
If this is set true, then no output is generated. This is usedul in batch mode or with a batch file.- Returns:
-
setPrintOuput
public void setPrintOuput(boolean printOuput)
-
setOutputOnHelp
protected void setOutputOnHelp()
-
versionHelp
protected void versionHelp()
-
version
public void version(InputLine inputLine)
-
echoHelp
protected void echoHelp()
-
echo
public void echo(InputLine inputLine)
-
readFile
protected String readFile(String filename) throws Exception
read a text file and return a single string of the content. This is intended for small files which will be processed into something else (e.g. turned into a JSON object, key set etc.)- Parameters:
filename-- Returns:
- Throws:
Exception
-
readJSON
protected net.sf.json.JSONObject readJSON(String filename) throws Exception
- Throws:
Exception
-
getHelpUtil
public HelpUtil getHelpUtil()
-
setHelpUtil
public void setHelpUtil(HelpUtil helpUtil)
-
-