Package edu.uiuc.ncsa.security.util.cli
Class AbstractCommandsImpl
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.AbstractCommandsImpl
-
- All Implemented Interfaces:
Logable
,Commands
,Serializable
- Direct Known Subclasses:
CommonCommands2
,ConfigurableCommandsImpl2
public abstract class AbstractCommandsImpl extends Object implements Commands
Class that collects the startup logic forCommands
implementations- 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
static String
INDENT
static String
LOGO
protected String
logoName
static String
NO_HEADER
static String
NO_LOGO
protected boolean
showHeader
protected boolean
showLogo
static String
SILENT
-
Constructor Summary
Constructors Constructor Description AbstractCommandsImpl(CLIDriver driver)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
about(boolean showBanner, boolean showHeader)
This will show the boot up logos, header (additional info) etc.InputLine
bootstrap(InputLine inputLine)
Bootstrap this implementation.InputLine
bootstrap(String[] args)
void
clear_env(InputLine inputLine)
protected void
clearEnvHelp()
void
debug(String x)
Write a debug message to the log.void
error(String x)
Write an error message to the log.void
error(String x, Throwable t)
void
get_env(InputLine inputline)
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
getLogoName()
protected String
getPropertyHelp(String propertyName, String prompt, String defaultValue)
One of the most important help methods, but only used in subclasses.protected boolean
gracefulExit(boolean exitNow, String msg)
Exit gracefully.protected boolean
hasLogger()
int
indentWidth()
void
info(String x)
Write an informational message to the logprotected void
initHelp()
abstract void
initialize()
Finish initializing this implementation.boolean
isDebugOn()
Query if debugging is enabled for this logger.protected boolean
isOk(String x)
Used when reading lines to check is the user typed a "y" for yes.boolean
isShowHeader()
Show the header, if any, at startup?boolean
isShowLogo()
Show the logo, if any, at startup?abstract void
load(InputLine inputLine)
Load resources before showing logos etc.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 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
sayi(String x)
prints with the current indent and a linefeed.protected void
sayv(String x)
Use this for verbose mode.void
set_env(InputLine inputline)
void
setDebugOn(boolean setOn)
Enable/disable debugging for this loggervoid
setDriver(CLIDriver driver)
void
setLogoName(String logoName)
void
setShowHeader(boolean showHeader)
void
setShowLogo(boolean showLogo)
protected boolean
showHelp(InputLine inputLine)
returns "true if the command has the flag --help in it.void
warn(String x)
Write a warning to the log.
-
-
-
Field Detail
-
NO_LOGO
public static final String NO_LOGO
- See Also:
- Constant Field Values
-
NO_HEADER
public static final String NO_HEADER
- See Also:
- Constant Field Values
-
SILENT
public static final String SILENT
- See Also:
- Constant Field Values
-
LOGO
public static final String LOGO
- See Also:
- Constant Field Values
-
CL_OUTPUT_FILE_FLAG
protected String CL_OUTPUT_FILE_FLAG
-
CL_INPUT_FILE_FLAG
protected String CL_INPUT_FILE_FLAG
-
DEFAULT_NULL_VALUE_PLACEHOLDER
protected static String DEFAULT_NULL_VALUE_PLACEHOLDER
-
showHeader
protected boolean showHeader
-
showLogo
protected boolean showLogo
-
logoName
protected String logoName
-
defaultIndent
protected String defaultIndent
-
INDENT
public static final String INDENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractCommandsImpl
public AbstractCommandsImpl(CLIDriver driver)
-
-
Method Detail
-
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:
-
getPropertyHelp
protected String getPropertyHelp(String propertyName, String prompt, String defaultValue) throws IOException
One of the most important help methods, but only used in subclasses.
Use this to get a property and also allow for getting help. This is just
getInput(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
-
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
-
readline
protected String readline(String prompt) throws IOException
- Throws:
IOException
-
readline
protected String readline()
-
getDriver
public CLIDriver getDriver()
Description copied from interface:Commands
Back reference to the driver that manages this instance.
-
bootstrap
public InputLine bootstrap(InputLine inputLine) throws Throwable
Bootstrap this implementation. This callsCLIDriver.bootstrap(String[])
. The sequence this follows is- call
CLIDriver.bootstrap(InputLine)
- Turn off console ouput (loggin unaffected) if not verbose mode
- Call
load(InputLine)
- Turn back on output
- Show header with
about(boolean, boolean)
- Call
initialize()
- Call
initHelp()
- call
-
isShowHeader
public boolean isShowHeader()
Show the header, if any, at startup?- Returns:
-
setShowHeader
public void setShowHeader(boolean showHeader)
-
isShowLogo
public boolean isShowLogo()
Show the logo, if any, at startup?- Returns:
-
setShowLogo
public void setShowLogo(boolean showLogo)
-
getLogoName
public String getLogoName()
-
setLogoName
public void setLogoName(String logoName)
-
about
public abstract void about(boolean showBanner, boolean showHeader)
This will show the boot up logos, header (additional info) etc. if any
-
initialize
public abstract void initialize() throws Throwable
Finish initializing this implementation.- Throws:
Throwable
-
load
public abstract void load(InputLine inputLine) throws Throwable
Load resources before showing logos etc. This is typically called on your behalf inbootstrap(InputLine)
amd should load resources needed. Note that an exception in this does not stop booting. This allows you to start a system with a missing configuration file (for instnace) and prompt for it.
Seeinitialize()
which is called after this and is charged with actually starting- Parameters:
inputLine
-- Throws:
Throwable
-
hasLogger
protected boolean hasLogger()
-
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
-
debug
public void debug(String x)
Description copied from interface:Logable
Write a debug message to the log.
-
info
public void info(String x)
Description copied from interface:Logable
Write an informational message to the log
-
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.
-
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.
-
isOk
protected boolean isOk(String x)
Used when reading lines to check is the user typed a "y" for yes.- Parameters:
x
-- Returns:
-
getHelpUtil
public HelpUtil getHelpUtil()
-
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:
-
say
protected void say(String x)
Prints with the default indent and a linefeed.- Parameters:
x
-
-
say
protected void say()
Linefeed.
-
sayv
protected void sayv(String x)
Use this for verbose mode.- Parameters:
x
-
-
readJSON
protected net.sf.json.JSONObject readJSON(String filename) throws Throwable
- Throws:
Throwable
-
sayi
protected void sayi(String x)
prints with the current indent and a linefeed.- Parameters:
x
-
-
indentWidth
public int indentWidth()
-
getIOInterface
public IOInterface getIOInterface()
- Specified by:
getIOInterface
in interfaceCommands
-
-