Class Cli


  • public final class Cli
    extends java.lang.Object
    This class provides a very basic CLI abstraction.

    Why are we not using a library for this? Because parsing command line options isn't difficult, we don't need to take a dependency, this code uses no reflection to improve startup time. We can control exactly what CLI features are supported in case we want to migrate to a library or event a different language.

    • Constructor Summary

      Constructors 
      Constructor Description
      Cli​(Command command, java.lang.ClassLoader classLoader)
      Creates a new CLI with the given name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int run​(java.lang.String[] args)
      Execute the command line using the given arguments.
      void stderr​(CliPrinter printer)  
      void stdout​(CliPrinter printer)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Cli

        public Cli​(Command command,
                   java.lang.ClassLoader classLoader)
        Creates a new CLI with the given name.
        Parameters:
        command - CLI command to run.
        classLoader - ClassLoader to use when invoking commands.
    • Method Detail

      • run

        public int run​(java.lang.String[] args)
        Execute the command line using the given arguments.
        Parameters:
        args - Arguments to parse.
        Returns:
        Returns the exit code.
        Throws:
        CliError - on error.
      • stdout

        public void stdout​(CliPrinter printer)
      • stderr

        public void stderr​(CliPrinter printer)