Class Cli<C>

  • Type Parameters:
    C - Command type

    public class Cli<C>
    extends java.lang.Object
    Class for encapsulating and parsing CLIs
    • Constructor Summary

      Constructors 
      Constructor Description
      Cli​(GlobalMetadata<C> metadata)
      Creates a new CLI
      Cli​(java.lang.Class<?> cliClass)
      Creates a new CLI from a class annotated with the Cli annotation
      Cli​(java.lang.Class<?> cliClass, ParserMetadata<C> parserConfig)
      Creates a new CLI from a class annotated with the Cli annotation
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> CliBuilder<T> builder​(java.lang.String name)
      Creates a builder for specifying a command line in fluent style
      GlobalMetadata<C> getMetadata()
      Gets the global meta-data
      private C parse​(java.lang.Iterable<java.lang.String> args)
      Parses the arguments to produce a command instance, this may be null if the arguments don't identify a command and there was no appropriate default command configured
      C parse​(java.lang.String... args)
      Parses the arguments to produce a command instance, this may be null if the arguments don't identify a command and there was no appropriate default command configured
      ParseResult<C> parseWithResult​(java.lang.Iterable<java.lang.String> args)
      Parses the arguments to produce a result.
      ParseResult<C> parseWithResult​(java.lang.String... args)
      Parses the arguments to produce a result.
      • Methods inherited from class java.lang.Object

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

      • Cli

        public Cli​(java.lang.Class<?> cliClass)
        Creates a new CLI from a class annotated with the Cli annotation
        Parameters:
        cliClass - CLI class
      • Cli

        public Cli​(java.lang.Class<?> cliClass,
                   ParserMetadata<C> parserConfig)
        Creates a new CLI from a class annotated with the Cli annotation
        Parameters:
        cliClass - CLI class
        parserConfig - Parser configuration, this will override any configuration specified by the Cli.parserConfiguration() field
      • Cli

        public Cli​(GlobalMetadata<C> metadata)
        Creates a new CLI
        Parameters:
        metadata - Metadata
    • Method Detail

      • builder

        public static <T> CliBuilder<T> builder​(java.lang.String name)
        Creates a builder for specifying a command line in fluent style
        Type Parameters:
        T - Command type to be built
        Parameters:
        name - Program name
        Returns:
        CLI Builder
      • getMetadata

        public GlobalMetadata<C> getMetadata()
        Gets the global meta-data
        Returns:
        Meta-data
      • parse

        public C parse​(java.lang.String... args)
        Parses the arguments to produce a command instance, this may be null if the arguments don't identify a command and there was no appropriate default command configured
        Parameters:
        args - Arguments
        Returns:
        Command instance
      • parse

        private C parse​(java.lang.Iterable<java.lang.String> args)
        Parses the arguments to produce a command instance, this may be null if the arguments don't identify a command and there was no appropriate default command configured
        Parameters:
        args - Arguments
        Returns:
        Command instance
      • parseWithResult

        public ParseResult<C> parseWithResult​(java.lang.String... args)
        Parses the arguments to produce a result. The result can be inspected to see errors (assuming a suitable error handler was used e.g. CollectAll) and to get a command instance. This may be null if the arguments don't identify a command and there was no appropriate default command configured
        Parameters:
        args - Arguments
        Returns:
        Parse result
      • parseWithResult

        public ParseResult<C> parseWithResult​(java.lang.Iterable<java.lang.String> args)
        Parses the arguments to produce a result. The result can be inspected to see errors (assuming a suitable error handler was used e.g. CollectAll) and to get a command instance. This may be null if the arguments don't identify a command and there was no appropriate default command configured
        Parameters:
        args - Arguments
        Returns:
        Parse result