public class PicocliRunner extends Object
Constructor and Description |
---|
PicocliRunner() |
Modifier and Type | Method and Description |
---|---|
static <C extends Callable<T>,T> |
call(Class<C> cls,
ApplicationContext ctx,
String... args)
Obtains an instance of the specified
Callable command class from the specified context,
injecting any beans from the specified context as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option and @Parameters
annotations, and finally calls the command and returns the result. |
static <C extends Callable<T>,T> |
call(Class<C> cls,
String... args)
Instantiates a new
ApplicationContext for the Environment.CLI environment,
obtains an instance of the specified Callable command class from the context,
injecting any beans as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option and @Parameters
annotations, and finally calls the command and returns the result. |
static <R extends Runnable> |
run(Class<R> cls,
ApplicationContext ctx,
String... args)
Obtains an instance of the specified
Runnable command class from the specified context,
injecting any beans from the specified context as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option and @Parameters
annotations, and finally runs the command. |
static <R extends Runnable> |
run(Class<R> cls,
String... args)
Instantiates a new
ApplicationContext for the Environment.CLI environment,
obtains an instance of the specified Runnable command class from the context,
injecting any beans as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option and @Parameters
annotations, and finally runs the command. |
public static <C extends Callable<T>,T> T call(Class<C> cls, String... args) throws Exception
ApplicationContext
for the Environment.CLI
environment,
obtains an instance of the specified Callable
command class from the context,
injecting any beans as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option
and @Parameters
annotations, and finally calls the command and returns the result.
The ApplicationContext
is closed before this method returns.
C
- The callable typeT
- The callable return typecls
- the Callable command classargs
- the command line argumentsnull
if an error occurred while parsing the command line options,
or if help was requested and printed. Otherwise returns the result of calling the Callablepicocli.CommandLine.InitializationException
- if the specified command object does not have
a CommandLine.Command
, CommandLine.Option
or CommandLine.Parameters
annotationpicocli.CommandLine.ExecutionException
- if the Callable throws an exceptionException
- if the ApplicationContext could not be closedpublic static <C extends Callable<T>,T> T call(Class<C> cls, ApplicationContext ctx, String... args)
Callable
command class from the specified context,
injecting any beans from the specified context as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option
and @Parameters
annotations, and finally calls the command and returns the result.
The caller is responsible for closing the context.
C
- The callable typeT
- The callable return typecls
- the Callable command classctx
- the ApplicationContext that injects dependencies into the commandargs
- the command line argumentsnull
if an error occurred while parsing the command line options,
or if help was requested and printed. Otherwise returns the result of calling the Callablepicocli.CommandLine.InitializationException
- if the specified command object does not have
a CommandLine.Command
, CommandLine.Option
or CommandLine.Parameters
annotationpicocli.CommandLine.ExecutionException
- if the Callable throws an exceptionpublic static <R extends Runnable> void run(Class<R> cls, String... args) throws Exception
ApplicationContext
for the Environment.CLI
environment,
obtains an instance of the specified Runnable
command class from the context,
injecting any beans as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option
and @Parameters
annotations, and finally runs the command.
The ApplicationContext
is closed before this method returns.
R
- The runnable typecls
- the Runnable command classargs
- the command line argumentspicocli.CommandLine.InitializationException
- if the specified command object does not have
a CommandLine.Command
, CommandLine.Option
or CommandLine.Parameters
annotationpicocli.CommandLine.ExecutionException
- if the Runnable throws an exceptionException
- if the ApplicationContext could not be closedpublic static <R extends Runnable> void run(Class<R> cls, ApplicationContext ctx, String... args)
Runnable
command class from the specified context,
injecting any beans from the specified context as required,
then parses the specified command line arguments, populating fields and methods annotated
with picocli @Option
and @Parameters
annotations, and finally runs the command.
The caller is responsible for closing the context.
R
- The runnable typecls
- the Runnable command classctx
- the ApplicationContext that injects dependencies into the commandargs
- the command line argumentspicocli.CommandLine.InitializationException
- if the specified command object does not have
a CommandLine.Command
, CommandLine.Option
or CommandLine.Parameters
annotationpicocli.CommandLine.ExecutionException
- if the Runnable throws an exception