Class CliMain

  • Direct Known Subclasses:
    NlsMain

    public abstract class CliMain
    extends Object
    This is the abstract base class for a main-program.
    You simply need to extend this class and implement run(CliArgs). For advanced CLIs please extend io.github.mmm.nls.cli.NlsMain from mmm-nls-cli.
    Since:
    1.0.0
    • Constructor Detail

      • CliMain

        public CliMain()
        The constructor.
      • CliMain

        public CliMain​(CliConsole console)
        The constructor.
        Parameters:
        console - the CliConsole to use.
    • Method Detail

      • error

        protected void error​(CliArgument argument)
        Parameters:
        argument - the CliArgument that was unexpected at this place.
      • error

        protected int error​(Throwable error)
        Parameters:
        error - the Throwable that occurred.
        Returns:
        the exit code corresponding to the given error.
      • getVersion

        protected String getVersion()
        Returns:
        the version of this program.
      • run

        public abstract int run​(CliArgs args)
        Has to be implemented to handle that given CliArgs and do the program logic.
        Parameters:
        args - the CliArgs.
        Returns:
        the exit code.
      • run

        public int run​(String... args)
        This method parses the given args as CliArgs and delegates to run(CliArgs). Additionally it will catch and handle any kind of errors.
        Parameters:
        args - are the command-line arguments.
        Returns:
        the exit code.
      • runAndExit

        protected void runAndExit​(String... args)
        This method delegates to run(String...) and then calls System.exit(int) with the returned exit code. Typically you only need to call this method from your actual main method.
        Parameters:
        args - are the command-line arguments.