Class CliConfig

java.lang.Object
io.permazen.cli.config.CliConfig
Direct Known Subclasses:
KeyValueCliConfig

public abstract class CliConfig extends Object
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 Details

    • log

      protected final Logger log
    • readOnlyOption

      protected joptsimple.OptionSpec<Void> readOnlyOption
    • verboseOption

      protected joptsimple.OptionSpec<Void> verboseOption
    • helpOption

      protected joptsimple.OptionSpec<Void> helpOption
    • loader

      protected final ApplicationClassLoader loader
    • setReadOnly

      protected boolean setReadOnly
    • setVerbose

      protected boolean setVerbose
  • Constructor Details

    • CliConfig

      public CliConfig()
  • Method Details

    • startup

      public boolean startup(PrintStream out, PrintStream err, int numColumns, String[] params)
      Configure and startup a Session.

      If an error occurs, or --help is requested, null will be returned and an appropriate message printed to the console.

      Parameters:
      out - standard output
      err - standard error
      numColumns - number of columns in terminal display, or -1 if unknown
      params - command line parameters
      Returns:
      true if successful, or false if the --help flag was given
      Throws:
      IllegalArgumentException - if startup failed due to misconfiguration
      IllegalArgumentException - if any parameter is null
    • createOptionParser

      protected joptsimple.OptionParser createOptionParser(int numColumns)
      Create the OptionParser 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 an OptionParser with the comand line flags supported by this instance.
      Parameters:
      parser - command line flag parser
      Throws:
      IllegalArgumentException - if parser 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 - if parser is null
      IllegalStateException - 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 invalid
      IllegalArgumentException - if some option(s) are invalid
      IllegalArgumentException - if options is null
    • showHelp

      public void showHelp(PrintStream out, joptsimple.OptionParser parser)
      Print the help message.
      Parameters:
      out - output for help message
      parser - 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 invalid
      IllegalArgumentException - if some option(s) are invalid
      IllegalArgumentException - if options is null
      IllegalStateException - if already started
    • shutdownDatabase

      public abstract void shutdownDatabase()
      Shutdown the database.
    • getDatabaseDescription

      public abstract String getDatabaseDescription()
    • getKVDatabase

      public KVDatabase getKVDatabase()
    • getDatabase

      public Database getDatabase()
    • getPermazen

      public Permazen getPermazen()
    • configureSession

      protected void configureSession(Session session)
      Configure a new Session.
      Parameters:
      session - new session to configure
      Throws:
      IllegalArgumentException - if session is null
    • newPermazenExec

      public PermazenExec newPermazenExec()
      Create a new PermazenExec.
      Throws:
      IllegalStateException - if not started yet
    • newPermazenShell

      public PermazenShell newPermazenShell()
      Create a new PermazenShell.
      Throws:
      IllegalStateException - if not started yet
    • loadClass

      protected <T> Class<? extends T> loadClass(Class<T> type, String className)
      Load a class.
      Parameters:
      type - expected type
      className - class name
      Returns:
      class with name className
      Throws:
      IllegalArgumentException - if class can't be loaded or has the wrong type
      IllegalArgumentException - if either parameter is null
    • instantiateClass

      protected <T> T instantiateClass(Class<T> type, String className)
      Load and instantiate a class.
      Parameters:
      type - expected type
      className - class name
      Returns:
      new instance of class
      Throws:
      IllegalArgumentException - if class can't be loaded, instantiated, or has the wrong type
      IllegalArgumentException - if either parameter is null