Class CliApp

  • All Implemented Interfaces:
    TypedReader
    Direct Known Subclasses:
    CliAppKafujo

    public class CliApp
    extends Object
    implements TypedReader
    Makes it easier to create Apache Commons CLI apps. Offers three useful standard options.
    • Field Detail

      • commandLine

        protected org.apache.commons.cli.CommandLine commandLine
    • Constructor Detail

      • CliApp

        public CliApp()
        Default ctor with default values:
        • '?' help (showing help when there are no args)
        • 'S' stats
        • 'W' wait (waiting forever)
      • CliApp

        public CliApp​(String standardHelpOpt,
                      boolean showHelpOnNoArgs,
                      String standardStatsOpt,
                      String standardWaitOpt,
                      Duration standardWaitDuration)
    • Method Detail

      • addStandardOptions

        protected final void addStandardOptions()
        Adds all default options.
      • addStandardHelpOption

        protected void addStandardHelpOption()
        Adds an option wi
      • addStandardStatsOption

        protected void addStandardStatsOption()
      • addStandardWaitOption

        protected void addStandardWaitOption()
      • help

        protected boolean help()
        The default help. You can overwrite this in the actual class to show a specialized help screen.
        Returns:
        always false to signal the end of the program
      • add

        protected void add​(org.apache.commons.cli.Option option)
      • addOptionalArgOption

        protected void addOptionalArgOption​(RunnableResult<Boolean> code,
                                            String opt,
                                            String description)
        Adds an Option with ONE optional argument.
        Parameters:
        code - runnable for this option.
        opt - short name
        description - describes what it does
      • run

        protected void run​(String[] args)
      • confirmNextStep

        protected boolean confirmNextStep​(String message)
        Prints message and ask for confirmation. User has to enter y or n.
        Parameters:
        message - question to be confirmed or not.
        Returns:
        true, if user confirms
      • confirmOverwrite

        protected boolean confirmOverwrite​(Path file)
        Checks if file exists and asks, if it can be overwritten.
        Parameters:
        file - file to be checked
        Returns:
        false if file exists and user doen't confirm overwrite. Else true.
        Throws:
        RequirementException - if file exists but is directory