java.lang.Object
com.github.rvesse.airline.Cli<C>
Type Parameters:
C - Command type

public class Cli<C> extends Object
Class for encapsulating and parsing CLIs
  • Field Details

  • Constructor Details

    • Cli

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

      public Cli(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 Details

    • builder

      public static <T> CliBuilder<T> builder(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(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(Iterable<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(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(Iterable<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