Class CliSugar

java.lang.Object
org.refcodes.cli.CliSugar

public class CliSugar extends Object
Declarative syntactic sugar which may be statically imported in order to allow declarative definitions for the command line Flag, ArgsSyntax, Option and Operand elements.
  • Constructor Details

    • CliSugar

      public CliSugar()
  • Method Details

    • examples

      public static Example[] examples(Example... aExamples)
      Sugar for creating an Example array from a varargs argument.
      Parameters:
      aExamples - the Example varargs argument.
      Returns:
      The according array representation.
    • example

      public static Example example(String aDescription, Operand<?>... aOperands)
      Sugar for creating an Example from a description and the according Operand elements.
      Parameters:
      aDescription - The explanatory text of the example.
      aOperands - The operands required for the Example.
      Returns:
      The according Example instance.
    • operation

      public static Operation operation(String aOperation, String aDescription)
      Constructs a Operation with the given arguments.
      Parameters:
      aOperation - The operation to declare.
      aDescription - A description without any line breaks.
      Returns:
      The accordingly created Operation.
    • operation

      public static Operation operation(String aOperation, String aAlias, String aDescription)
      Constructs a Operation with the given arguments.
      Parameters:
      aOperation - The operation to declare.
      aAlias - The operation's name to be used when constructing the syntax.
      aDescription - A description without any line breaks.
      Returns:
      The accordingly created Operation.
    • and

      public static ArgsSyntax and(Syntaxable... aArgs)
      Instantiates a new AndCondition with the Syntaxable (ArgsSyntax) instances to be nested.
      Parameters:
      aArgs - The Syntaxable (ArgsSyntax) instances to be nested.
      Returns:
      The according AND condition.
      See Also:
    • all

      public static ArgsSyntax all(Syntaxable aArg)
      Instantiates a new AllCondition with the Syntaxable (ArgsSyntax) instance to be nested.
      Parameters:
      aArg - The Syntaxable (ArgsSyntax) instance to be nested.
      Returns:
      The according ALL condition.
      See Also:
    • or

      public static ArgsSyntax or(Syntaxable... aArgs)
      Instantiates a new OrCondition with the Syntaxable (ArgsSyntax) instances to be nested.
      Parameters:
      aArgs - The Syntaxable (ArgsSyntax) instances to be nested.
      Returns:
      The according OR condition.
      See Also:
    • xor

      public static ArgsSyntax xor(Syntaxable... aArgs)
      Instantiates a new XorCondition with the Syntaxable (ArgsSyntax) instances to be nested.
      Parameters:
      aArgs - The Syntaxable (ArgsSyntax) instances to be nested.
      Returns:
      The according XOR condition.
      See Also:
    • cases

      public static ArgsSyntax cases(Syntaxable... aArgs)
      Instantiates a new CasesCondition with the Syntaxable (ArgsSyntax) instances to be nested.
      Parameters:
      aArgs - The Syntaxable (ArgsSyntax) instances to be nested.
      Returns:
      The according CasesCondition (https://www.metacodes.pro XOR) condition.
      See Also:
    • any

      public static ArgsSyntax any(Syntaxable... aArgs)
      Instantiates a new AnyCondition with the Syntaxable (ArgsSyntax) instances to be nested. Any of the nested ArgsSyntax conditions may match for the AnyCondition to match, e.g. all of the nested conditions are optional.
      Parameters:
      aArgs - The Syntaxable (ArgsSyntax) instances to be nested
      Returns:
      The according AbstractCondition.
      See Also:
    • optional

      public static ArgsSyntax optional(Syntaxable... aArgs)
      Semantically identical synonym for the optional(Syntaxable...) declaration.
      Parameters:
      aArgs - The Syntaxable (ArgsSyntax) instances to be nested
      Returns:
      The according AbstractCondition.
      See Also:
    • none

      public static NoneOperand none(String aAlias, String aDescription)
      Instantiates a new NoneOperand.
      Parameters:
      aAlias - The identifier to be used when printing the syntax via the Syntaxable.toSyntax(SyntaxNotation, String, String, String) method.
      aDescription - A description without any line breaks.
      Returns:
      the none operand
      See Also:
    • none

      public static NoneOperand none(String aDescription)
      Instantiates a new NoneOperand.
      Parameters:
      aDescription - A description without any line breaks.
      Returns:
      the none operand
      See Also:
    • none

      public static NoneOperand none(org.refcodes.struct.Relation<String,Boolean> aProperty)
      Instantiates a new NoneOperand.
      Parameters:
      aProperty - The key (= alias) and the value for the operand.
      Returns:
      the none operand
      See Also:
    • enumOption

      public static <T extends Enum<T>> EnumOption<T> enumOption(String aShortOption, String aLongOption, Class<T> aType, String aAlias, String aDescription)
      Instantiates a new enum option.
      Type Parameters:
      T - the generic type
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aType - the type
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • enumOption

      public static <T extends Enum<T>> EnumOption<T> enumOption(String aLongOption, Class<T> aType, String aAlias, String aDescription)
      Instantiates a new enum option.
      Type Parameters:
      T - the generic type
      Parameters:
      aLongOption - the long option
      aType - the type
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • flag

      public static Flag flag(String aLongOption, String aAlias, String aDescription)
      As "switch" is a reserved word in Java, we use "flag" :-(.
      Parameters:
      aLongOption - the long option
      aAlias - The alias of the flag
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • flag

      public static Flag flag(String aShortOption, String aLongOption, String aAlias, String aDescription)
      As "switch" is a reserved word in Java, we use "flag" :-(.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - The alias of the flag
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • daemonFlag

      public static DaemonFlag daemonFlag(String aDescription)
      Constructs the predefined daemon Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • daemonFlag

      public static DaemonFlag daemonFlag()
      Constructs the predefined daemon Flag.
      Returns:
      The according Flag.
      See Also:
    • daemonFlag

      public static DaemonFlag daemonFlag(boolean hasShortOption)
      Constructs the predefined daemon Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • forceFlag

      public static ForceFlag forceFlag(String aDescription)
      Constructs the predefined force Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • forceFlag

      public static ForceFlag forceFlag()
      Constructs the predefined force Flag.
      Returns:
      The according Flag.
      See Also:
    • forceFlag

      public static ForceFlag forceFlag(boolean hasShortOption)
      Constructs the predefined force Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • helpFlag

      public static HelpFlag helpFlag(String aDescription)
      Constructs the predefined help Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • helpFlag

      public static HelpFlag helpFlag()
      Constructs the predefined help Flag.
      Returns:
      The according Flag.
      See Also:
    • helpFlag

      public static HelpFlag helpFlag(boolean hasShortOption)
      Constructs the predefined help Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • initFlag

      public static InitFlag initFlag(String aDescription)
      Constructs the predefined init Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • initFlag

      public static InitFlag initFlag()
      Constructs the predefined init Flag.
      Returns:
      The according Flag.
      See Also:
    • initFlag

      public static InitFlag initFlag(boolean hasShortOption)
      Constructs the predefined init Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • cleanFlag

      public static CleanFlag cleanFlag(String aDescription)
      Constructs the predefined clean Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • cleanFlag

      public static CleanFlag cleanFlag()
      Constructs the predefined clean Flag.
      Returns:
      The according Flag.
      See Also:
    • cleanFlag

      public static CleanFlag cleanFlag(boolean hasShortOption)
      Constructs the predefined clean Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • sysInfoFlag

      public static SysInfoFlag sysInfoFlag(String aDescription)
      Constructs the predefined system info Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • sysInfoFlag

      public static SysInfoFlag sysInfoFlag()
      Constructs the predefined system info Flag.
      Returns:
      The according Flag.
      See Also:
    • sysInfoFlag

      public static SysInfoFlag sysInfoFlag(boolean hasShortOption)
      Constructs the predefined system info Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • quietFlag

      public static QuietFlag quietFlag(String aDescription)
      Constructs the predefined quiet Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • quietFlag

      public static QuietFlag quietFlag()
      Constructs the predefined quiet Flag.
      Returns:
      The according Flag.
      See Also:
    • quietFlag

      public static QuietFlag quietFlag(boolean hasShortOption)
      Constructs the predefined quiet Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • verboseFlag

      public static VerboseFlag verboseFlag(String aDescription)
      Constructs the predefined verbose Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • verboseFlag

      public static VerboseFlag verboseFlag()
      Constructs the predefined verbose Flag.
      Returns:
      The according Flag.
      See Also:
    • verboseFlag

      public static VerboseFlag verboseFlag(boolean hasShortOption)
      Constructs the predefined verbose Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • debugFlag

      public static DebugFlag debugFlag(String aDescription)
      Constructs the predefined debug Flag.
      Parameters:
      aDescription - The description to use when printing out the help text.
      Returns:
      The according Flag.
      See Also:
    • debugFlag

      public static DebugFlag debugFlag()
      Constructs the predefined debug Flag.
      Returns:
      The according Flag.
      See Also:
    • debugFlag

      public static DebugFlag debugFlag(boolean hasShortOption)
      Constructs the predefined debug Flag.
      Parameters:
      hasShortOption - True in case to also enable the short option, else only the long option takes effect.
      Returns:
      The according Flag.
      See Also:
    • intOption

      public static IntOption intOption(String aLongOption, String aAlias, String aDescription)
      Int option.
      Parameters:
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • intOption

      public static IntOption intOption(String aShortOption, String aLongOption, String aAlias, String aDescription)
      Int option.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • longOption

      public static LongOption longOption(String aLongOption, String aAlias, String aDescription)
      Long option.
      Parameters:
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • longOption

      public static LongOption longOption(String aShortOption, String aLongOption, String aAlias, String aDescription)
      Long option.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • floatOption

      public static FloatOption floatOption(String aLongOption, String aAlias, String aDescription)
      Float option.
      Parameters:
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • floatOption

      public static FloatOption floatOption(String aShortOption, String aLongOption, String aAlias, String aDescription)
      Float option.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • doubleOption

      public static DoubleOption doubleOption(String aLongOption, String aAlias, String aDescription)
      Double option.
      Parameters:
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • doubleOption

      public static DoubleOption doubleOption(String aShortOption, String aLongOption, String aAlias, String aDescription)
      Double option.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • stringOption

      public static StringOption stringOption(String aLongOption, String aAlias, String aDescription)
      String option.
      Parameters:
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • stringOption

      public static StringOption stringOption(String aShortOption, String aLongOption, String aAlias, String aDescription)
      String option.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • charOption

      public static CharOption charOption(String aLongOption, String aAlias, String aDescription)
      Character option.
      Parameters:
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • charOption

      public static CharOption charOption(String aShortOption, String aLongOption, String aAlias, String aDescription)
      Character option.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • configOption

      public static ConfigOption configOption()
      Creates a ConfigOption representing value specifying a configuration resource (file).
      Returns:
      the according ConfigOption.
      See Also:
    • configOption

      public static ConfigOption configOption(String aDescription)
      Creates a ConfigOption representing a value specifying a configuration resource (file).
      Parameters:
      aDescription - The description to use when printing out the help text. to use when printing out the help text.
      Returns:
      the according ConfigOption.
      See Also:
    • fileOption

      public static FileOption fileOption(String aLongOption, String aAlias, String aDescription)
      Creates a FileOption for getting a File instance from a path.
      Parameters:
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • fileOption

      public static FileOption fileOption(String aShortOption, String aLongOption, String aAlias, String aDescription)
      Creates a FileOption for getting a File instance from a path.
      Parameters:
      aShortOption - the short option
      aLongOption - the long option
      aAlias - the option arg name
      aDescription - The description to use when printing out the help text.
      Returns:
      the option
      See Also:
    • stringOperand

      public static StringOperand stringOperand(String aIdentifier, String aDescription)
      String operand.
      Parameters:
      aIdentifier - the identifier
      aDescription - The description to use when printing out the help text.
      Returns:
      the operand
      See Also:
    • asArray

      public static <T> ArrayOption<T> asArray(Option<T> aOption)
      Creates an array representation facade for the encapsulated Option. This way any Option can also be used as an array Option, e.g. it can be provided multiple times in the command line arguments.
      Type Parameters:
      T - The type of the Option for which to create an ArrayOption.
      Parameters:
      aOption - The Option which's array counterpart is to be defined.
      Returns:
      The according ArrayOption.
    • asArray

      public static <T> ArrayOption<T> asArray(Option<T> aOption, int aLength)
      Creates an array representation facade for the encapsulated Option. This way any Option can also be used as an array Option, e.g. it can by provided multiple times in the command line arguments.
      Type Parameters:
      T - The type of the Option for which to create an ArrayOption.
      Parameters:
      aOption - The Option which's array counterpart is to be defined.
      aLength - The number of array elements, or -1 if there is no limit.
      Returns:
      The according ArrayOption.
    • asArray

      public static <T> ArrayOption<T> asArray(Option<T> aOption, int aMinLength, int aMaxLength)
      Creates an array representation facade for the encapsulated Option. This way any Option can also be used as an array Option, e.g. it can by provided multiple times in the command line arguments.
      Type Parameters:
      T - The type of the Option for which to create an ArrayOption.
      Parameters:
      aOption - The Option which's array counterpart is to be defined.
      aMinLength - The minimum number of array elements, or -1 if there is no limit.
      aMaxLength - The maximum number of array elements, or -1 if there is no limit.
      Returns:
      The according ArrayOption.
    • asArray

      public static <T> ArrayOperand<T> asArray(Operand<T> aOperand)
      Creates an array representation facade for the encapsulated Operand. This way any Operand can also be used as an array Operand, e.g. it can be provided multiple times in the command line arguments.
      Type Parameters:
      T - The type of the Operand for which to create an ArrayOperand.
      Parameters:
      aOperand - The Operand which's array counterpart is to be defined.
      Returns:
      The according ArrayOperand.
    • asArray

      public static <T> ArrayOperand<T> asArray(Operand<T> aOperand, int aLength)
      Creates an array representation facade for the encapsulated Operand. This way any Operand can also be used as an array Operand, e.g. it can by provided multiple times in the command line arguments.
      Type Parameters:
      T - The type of the Operand for which to create an ArrayOperand.
      Parameters:
      aOperand - The Operand which's array counterpart is to be defined.
      aLength - The number of array elements, or -1 if there is no limit.
      Returns:
      The according ArrayOperand.
    • asArray

      public static <T> ArrayOperand<T> asArray(Operand<T> aOperand, int aMinLength, int aMaxLength)
      Creates an array representation facade for the encapsulated Operand. This way any Operand can also be used as an array Operand, e.g. it can by provided multiple times in the command line arguments.
      Type Parameters:
      T - The type of the Operand for which to create an ArrayOperand.
      Parameters:
      aOperand - The Operand which's array counterpart is to be defined.
      aMinLength - The minimum number of array elements, or -1 if there is no limit.
      aMaxLength - The maximum number of array elements, or -1 if there is no limit.
      Returns:
      The according ArrayOperand.