Class CliHelper

  • All Implemented Interfaces:
    org.refcodes.mixin.VerboseAccessor

    public class CliHelper
    extends Object
    implements org.refcodes.mixin.VerboseAccessor
    The CliHelper provides means to support CLI command line argument parsing.E.g. using the CliHelper you easily can create configuration files ("--init" or "--init path/to/your/config") from a template (found in "src/main/resources"), print a help text ("--help"), show system information ("--sysinfo") for support issues, regard being more verbose ("--verbose") or more quiet ("--quiet"), load a configuration from a specific location ("--config path/to/your/config"), all given that your command line syntax given uses the according predefined ArgsSyntax elements such as HelpFlag, VerboseFlag, QuietFlag, InitFlag, SysInfoFlag, DebugFlag or ConfigOption (and the like). The CliHelper can either be invoked via its constructor or by using the CliHelper.Builder retrieved by invoking the builder() method (allowing you to configure the CliHelper in a more verbose way).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CliHelper.Builder
      Builder to build CliHelper.
      • Nested classes/interfaces inherited from interface org.refcodes.mixin.VerboseAccessor

        org.refcodes.mixin.VerboseAccessor.VerboseMutator, org.refcodes.mixin.VerboseAccessor.VerboseProperty
    • Constructor Summary

      Constructors 
      Constructor Description
      CliHelper​(String[] aArgs, org.refcodes.cli.ArgsSyntax aArgsSyntax, Collection<org.refcodes.cli.ExampleUsage> aExampleUsages, String aDefaultConfig, String aName, String aTitle, String aDescription, String aCopyright, String aLicenseNote, org.refcodes.textual.Font aBannerFont, char[] aBannerPalette, boolean aVerboseFallback, org.refcodes.logger.RuntimeLogger aLogger)
      Creates a new CliHelper using the provided application's RuntimeLogger so that logs produced by the CliHelper are logged according to the application's RuntimeLogger configuration (depending on the RuntimeLogger.ini file).
    • Constructor Detail

      • CliHelper

        public CliHelper​(String[] aArgs,
                         org.refcodes.cli.ArgsSyntax aArgsSyntax,
                         Collection<org.refcodes.cli.ExampleUsage> aExampleUsages,
                         String aDefaultConfig,
                         String aName,
                         String aTitle,
                         String aDescription,
                         String aCopyright,
                         String aLicenseNote,
                         org.refcodes.textual.Font aBannerFont,
                         char[] aBannerPalette,
                         boolean aVerboseFallback,
                         org.refcodes.logger.RuntimeLogger aLogger)
        Creates a new CliHelper using the provided application's RuntimeLogger so that logs produced by the CliHelper are logged according to the application's RuntimeLogger configuration (depending on the RuntimeLogger.ini file).
        Parameters:
        aArgs - The command line arguments.
        aArgsSyntax - The root elelemt of your command line syntax.
        aExampleUsages - The ExampleUsage examples to use when printing out the help.
        aDefaultConfig - The name to your default config file.
        aName - The name of your application.
        aTitle - The title of the application.
        aDescription - The description to use when printing out the help.
        aCopyright - The copyright being applied.
        aLicenseNote - The license for the application.
        aBannerFont - The font for the banner to use.
        aBannerPalette - The ASCII color palette for the banner to use.
        aVerboseFallback - The fallback verbose mode if the verbose mode cannot be determined otherwise.
        aLogger - The application's logger.
    • Method Detail

      • getRuntimeProperties

        public org.refcodes.properties.ext.runtime.RuntimeProperties getRuntimeProperties()
        Returns the RuntimeProperties as of the provided CLI configuration.
        Returns:
        The according RuntimeProperties instance.
      • isVerbose

        public boolean isVerbose()
        Determines the verbose mode by evaluating the VerboseFlag.ALIAS and the QuietFlag.ALIAS properties after having constructed the RuntimeProperties from the command line arguments and the configuration file (e.g. the "quiet" property is false or the "verbose" property is true). Also takes into account a potentially existing QuietFlag or VerboseFlag given being provided by your command line syntax.
        Specified by:
        isVerbose in interface org.refcodes.mixin.VerboseAccessor
        Returns:
        True in case to be more verbose.
      • printSysInfo

        public void printSysInfo()
        Prints system information helpful for debugging cases.