- java.lang.Object
-
- org.refcodes.archetype.CliHelper
-
- All Implemented Interfaces:
org.refcodes.mixin.VerboseAccessor
public class CliHelper extends Object implements org.refcodes.mixin.VerboseAccessor
TheCliHelper
provides means to support CLI command line argument parsing.E.g. using theCliHelper
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 predefinedArgsSyntax
elements such asHelpFlag
,VerboseFlag
,QuietFlag
,InitFlag
,SysInfoFlag
,DebugFlag
orConfigOption
(and the like). TheCliHelper
can either be invoked via its constructor or by using theCliHelper.Builder
retrieved by invoking thebuilder()
method (allowing you to configure theCliHelper
in a more verbose way).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CliHelper.Builder
Builder to buildCliHelper
.
-
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)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CliHelper.Builder
builder()
Creates builder to buildCliHelper
.org.refcodes.properties.ext.runtime.RuntimeProperties
getRuntimeProperties()
Returns theRuntimeProperties
as of the provided CLI configuration.boolean
isVerbose()
Determines the verbose mode by evaluating theVerboseFlag.ALIAS
and theQuietFlag.ALIAS
properties after having constructed theRuntimeProperties
from the command line arguments and the configuration file (e.g. the "quiet" property is false or the "verbose" property is true).void
printSysInfo()
Prints system information helpful for debugging cases.
-
-
-
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 newCliHelper
using the provided application'sRuntimeLogger
so that logs produced by theCliHelper
are logged according to the application'sRuntimeLogger
configuration (depending on the RuntimeLogger.ini file).- Parameters:
aArgs
- The command line arguments.aArgsSyntax
- The root elelemt of your command line syntax.aExampleUsages
- TheExampleUsage
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 theRuntimeProperties
as of the provided CLI configuration.- Returns:
- The according
RuntimeProperties
instance.
-
isVerbose
public boolean isVerbose()
Determines the verbose mode by evaluating theVerboseFlag.ALIAS
and theQuietFlag.ALIAS
properties after having constructed theRuntimeProperties
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 existingQuietFlag
orVerboseFlag
given being provided by your command line syntax.- Specified by:
isVerbose
in interfaceorg.refcodes.mixin.VerboseAccessor
- Returns:
- True in case to be more verbose.
-
printSysInfo
public void printSysInfo()
Prints system information helpful for debugging cases.
-
builder
public static CliHelper.Builder builder()
Creates builder to buildCliHelper
.- Returns:
- created builder
-
-