- java.lang.Object
-
- com.github.rvesse.airline.Cli<C>
-
- Type Parameters:
C
- Command type
public class Cli<C> extends java.lang.Object
Class for encapsulating and parsing CLIs
-
-
Field Summary
Fields Modifier and Type Field Description private GlobalMetadata<C>
metadata
-
Constructor Summary
Constructors Constructor Description Cli(GlobalMetadata<C> metadata)
Creates a new CLICli(java.lang.Class<?> cliClass)
Creates a new CLI from a class annotated with theCli
annotationCli(java.lang.Class<?> cliClass, ParserMetadata<C> parserConfig)
Creates a new CLI from a class annotated with theCli
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 styleGlobalMetadata<C>
getMetadata()
Gets the global meta-dataprivate C
parse(java.lang.Iterable<java.lang.String> args)
Parses the arguments to produce a command instance, this may benull
if the arguments don't identify a command and there was no appropriate default command configuredC
parse(java.lang.String... args)
Parses the arguments to produce a command instance, this may benull
if the arguments don't identify a command and there was no appropriate default command configuredParseResult<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.
-
-
-
Field Detail
-
metadata
private final GlobalMetadata<C> metadata
-
-
Constructor Detail
-
Cli
public Cli(java.lang.Class<?> cliClass)
Creates a new CLI from a class annotated with theCli
annotation- Parameters:
cliClass
- CLI class
-
Cli
public Cli(java.lang.Class<?> cliClass, ParserMetadata<C> parserConfig)
Creates a new CLI from a class annotated with theCli
annotation- Parameters:
cliClass
- CLI classparserConfig
- Parser configuration, this will override any configuration specified by theCli.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 benull
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 benull
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 benull
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 benull
if the arguments don't identify a command and there was no appropriate default command configured- Parameters:
args
- Arguments- Returns:
- Parse result
-
-