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
FieldsModifier and TypeFieldDescriptionprotected joptsimple.OptionSpec<Void>protected final ApplicationClassLoaderprotected final Loggerprotected joptsimple.OptionSpec<Void>protected booleanprotected booleanprotected joptsimple.OptionSpec<Void> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddGenericOptions(joptsimple.OptionParser parser) Add generic command line flags to the given option parser.voidaddOptions(joptsimple.OptionParser parser) Configure anOptionParserwith the comand line flags supported by this instance.protected voidconfigureSession(Session session) Configure a newSession.protected joptsimple.OptionParsercreateOptionParser(int numColumns) Create theOptionParserto be used to parse command line options.abstract Stringprotected <T> TinstantiateClass(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 voidprocessOptions(joptsimple.OptionSet options) Review parsed options and do any preprocessing before starting database.voidshowHelp(PrintStream out, joptsimple.OptionParser parser) Print the help message.abstract voidShutdown the database.booleanstartup(PrintStream out, PrintStream err, int numColumns, String[] params) Configure and startup aSession.abstract voidstartupDatabase(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
--helpis 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
--helpflag was given - Throws:
IllegalArgumentException- if startup failed due to misconfigurationIllegalArgumentException- if any parameter is null
-
createOptionParser
protected joptsimple.OptionParser createOptionParser(int numColumns) Create theOptionParserto 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 anOptionParserwith the comand line flags supported by this instance.- Parameters:
parser- command line flag parser- Throws:
IllegalArgumentException- ifparseris 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- ifparseris 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- ifoptionsis 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- ifoptionsis 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- ifsessionis 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
-