Package io.permazen.cli.config
Class CliConfig
java.lang.Object
io.permazen.cli.config.CliConfig
- Direct Known Subclasses:
KeyValueCliConfig
Configuration for a CLI application.
To use this class (or a subclass), first invoke startup()
to configure and start the database
using the command-line flags that were given. Then, access the database to create CLI sessions as needed.
When done, invoke shutdownDatabase()
to stop.
-
Field Summary
Modifier and TypeFieldDescriptionprotected joptsimple.OptionSpec<Void>
protected final ApplicationClassLoader
protected final Logger
protected joptsimple.OptionSpec<Void>
protected boolean
protected boolean
protected joptsimple.OptionSpec<Void>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addGenericOptions
(joptsimple.OptionParser parser) Add generic command line flags to the given option parser.void
addOptions
(joptsimple.OptionParser parser) Configure anOptionParser
with the comand line flags supported by this instance.protected void
configureSession
(Session session) Configure a newSession
.protected joptsimple.OptionParser
createOptionParser
(int numColumns) Create theOptionParser
to be used to parse command line options.abstract String
protected <T> T
instantiateClass
(Class<T> type, String className) Load and instantiate a class.protected <T> Class<? extends T>
Load a class.Create a newPermazenExec
.Create a newPermazenShell
.protected void
processOptions
(joptsimple.OptionSet options) Review parsed options and do any preprocessing before starting database.void
showHelp
(PrintStream out, joptsimple.OptionParser parser) Print the help message.abstract void
Shutdown the database.boolean
startup
(PrintStream out, PrintStream err, int numColumns, String[] params) Configure and startup aSession
.abstract void
startupDatabase
(joptsimple.OptionSet options) Configure and start up the database based on the parsed command line options.
-
Field Details
-
log
-
readOnlyOption
-
verboseOption
-
helpOption
-
loader
-
setReadOnly
protected boolean setReadOnly -
setVerbose
protected boolean setVerbose
-
-
Constructor Details
-
CliConfig
public CliConfig()
-
-
Method Details
-
startup
Configure and startup aSession
.If an error occurs, or
--help
is requested, null will be returned and an appropriate message printed to the console.- Parameters:
out
- standard outputerr
- standard errornumColumns
- number of columns in terminal display, or -1 if unknownparams
- command line parameters- Returns:
- true if successful, or false if the
--help
flag was given - Throws:
IllegalArgumentException
- if startup failed due to misconfigurationIllegalArgumentException
- if any parameter is null
-
createOptionParser
protected joptsimple.OptionParser createOptionParser(int numColumns) Create theOptionParser
to be used to parse command line options.- Parameters:
numColumns
- number of columns in terminal display, or -1 if unknown- Returns:
- option parser
-
addOptions
public void addOptions(joptsimple.OptionParser parser) Configure anOptionParser
with the comand line flags supported by this instance.- Parameters:
parser
- command line flag parser- Throws:
IllegalArgumentException
- ifparser
is null
-
addGenericOptions
protected void addGenericOptions(joptsimple.OptionParser parser) Add generic command line flags to the given option parser.- Parameters:
parser
- command line flag parser- Throws:
IllegalArgumentException
- ifparser
is nullIllegalStateException
- if an option being added has already been added
-
processOptions
protected void processOptions(joptsimple.OptionSet options) Review parsed options and do any preprocessing before starting database.- Parameters:
options
- parsed command line options- Throws:
joptsimple.OptionException
- if some option(s) are invalidIllegalArgumentException
- if some option(s) are invalidIllegalArgumentException
- ifoptions
is null
-
showHelp
Print the help message.- Parameters:
out
- output for help messageparser
- command line flag parser- Throws:
IllegalArgumentException
- if either parameter is null
-
startupDatabase
public abstract void startupDatabase(joptsimple.OptionSet options) Configure and start up the database based on the parsed command line options.- Parameters:
options
- parsed command line options- Throws:
joptsimple.OptionException
- if some option(s) are invalidIllegalArgumentException
- if some option(s) are invalidIllegalArgumentException
- ifoptions
is nullIllegalStateException
- if already started
-
shutdownDatabase
public abstract void shutdownDatabase()Shutdown the database. -
getDatabaseDescription
-
getKVDatabase
-
getDatabase
-
getPermazen
-
configureSession
Configure a newSession
.- Parameters:
session
- new session to configure- Throws:
IllegalArgumentException
- ifsession
is null
-
newPermazenExec
Create a newPermazenExec
.- Throws:
IllegalStateException
- if not started yet
-
newPermazenShell
Create a newPermazenShell
.- Throws:
IllegalStateException
- if not started yet
-
loadClass
Load a class.- Parameters:
type
- expected typeclassName
- class name- Returns:
- class with name
className
- Throws:
IllegalArgumentException
- if class can't be loaded or has the wrong typeIllegalArgumentException
- if either parameter is null
-
instantiateClass
Load and instantiate a class.- Parameters:
type
- expected typeclassName
- class name- Returns:
- new instance of class
- Throws:
IllegalArgumentException
- if class can't be loaded, instantiated, or has the wrong typeIllegalArgumentException
- if either parameter is null
-