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 String
CL_INPUT_FILE_FLAG
protected String
CL_OUTPUT_FILE_FLAG
protected static String
DEFAULT_NULL_VALUE_PLACEHOLDER
protected String
defaultIndent
protected CLIDriver
driver
static String
INDENT
protected MyLoggingFacade
logger
String
placeHolder
This is used wherever a missing value is.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CommonCommands(MyLoggingFacade logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputLine
bootstrap(InputLine inputLine)
void
clear_env(InputLine inputLine)
protected void
clearEnvHelp()
void
debug(String x)
Write a debug message to the log.void
echo(InputLine inputLine)
protected void
echoHelp()
void
error(String x)
Write an error message to the log.void
get_env(InputLine inputline)
BufferedReader
getBufferedReader()
CLIDriver
getDriver()
Back reference to the driver that manages this instance.HelpUtil
getHelpUtil()
protected String
getInput(String prompt, String defaultValue)
Creates the input prompt and shows the supplied default value.IOInterface
getIOInterface()
String
getPlaceHolder()
Gets the placeholder for missing values.protected String
getPropertyHelp(String propertyName, String prompt, String defaultValue)
Use this to get a property and also allow for getting help.protected String
getValue(String x)
Returns the value if it is not empty of a placeholder if it is.protected boolean
gracefulExit(boolean exitNow, String msg)
Exit gracefully.int
indentWidth()
void
info(String x)
Write an informational message to the logprotected void
initHelp()
boolean
isDebugOn()
Query if debugging is enabled for this logger.protected boolean
isEmpty(String x)
protected boolean
isOk(String x)
boolean
isPrintOuput()
If this is set true, then no output is generated.boolean
isVerbose()
protected void
logit(String x)
void
print_env(InputLine inputLine)
protected void
printEnvHelp()
protected void
printGetEnvHelp()
protected void
printReadEnvHelp()
protected void
printSaveEnvHelp()
protected void
printSetEnvHelp()
void
read_env(InputLine inputline)
protected String
readFile(String filename)
read a text file and return a single string of the content.protected net.sf.json.JSONObject
readJSON(String filename)
protected String
readline()
protected String
readline(String prompt)
void
save_env(InputLine inputLine)
protected void
say()
Linefeed.protected void
say(String x)
Prints with the default indent and a linefeed.protected void
say2(String x)
Output the string without any linefeed.protected void
sayi(String x)
prints with the current indent and a linefeed.protected void
sayii(String x)
Double indent -- useful for lists.protected void
sayv(String x)
Use this for verbose mode.void
set_env(InputLine inputline)
void
set_output_on(InputLine inputLine)
void
set_verbose_on(InputLine inputLine)
So batch files can change whether or not they are verbosevoid
setBufferedReader(BufferedReader bufferedReader)
void
setDebugOn(boolean setOn)
Enable/disable debugging for this loggervoid
setDriver(CLIDriver driver)
void
setHelpUtil(HelpUtil helpUtil)
protected void
setOutputOnHelp()
void
setPlaceHolder(String placeHolder)
void
setPrintOuput(boolean printOuput)
void
setVerbose(boolean verbose)
protected void
setVerboseHelp()
protected boolean
showHelp(InputLine inputLine)
returns "true if the command has the flag --help in it.void
version(InputLine inputLine)
protected void
versionHelp()
void
warn(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:Logable
Write a debug message to the log.
-
error
public void error(String x)
Description copied from interface:Logable
Write 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:Logable
Write an informational message to the log
-
isDebugOn
public boolean isDebugOn()
Description copied from interface:Logable
Query if debugging is enabled for this logger.
-
setDebugOn
public void setDebugOn(boolean setOn)
Description copied from interface:Logable
Enable/disable debugging for this logger- Specified by:
setDebugOn
in interfaceLogable
-
warn
public void warn(String x)
Description copied from interface:Logable
Write 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:
getIOInterface
in 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:Commands
Back 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)
-
-