Package net.shibboleth.shared.cli

# Class AbstractCommandLine<T extends CommandLineArguments>

java.lang.Object
net.shibboleth.shared.cli.AbstractCommandLine<T>

Type Parameters:
  `T` - argument object type

public abstract class AbstractCommandLine<T extends CommandLineArguments> extends Object
A simple driver for a Spring-based CLI. This class handles a single parameters, the primary Spring configuration resource. Additional parameters may be handled by subclasses. All logging is done in accordance with the logback.xml file included in the library. If you wish to use a different logging configuration you may do so using the `-Dlogback.configurationFile=/path/to/logback.xml` JVM configuration option.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`AbstractCommandLine.TerminalCodes`
Terminal codes.

## Field Summary

Fields
Modifier and Type
Field
Description
`private GenericApplicationContext`
`applicationContext`
Spring context.
`static final String`
`ARGS_PROPERTY`
Name of system property for command line argument class.
`private boolean`
`caseSensitiveOptions`
Whether options are case-sensitive.
`private ApplicationContextInitializer<? super FilesystemGenericApplicationContext>`
`contextInitializer`
Optional Context initialized.
`static final int`
`RC_INIT`
Return code indicating an initialization error, 1.
`static final int`
`RC_IO`
Return code indicating an error reading files, 2.
`static final int`
`RC_MODULE`
Return code indicating an module mismatch, for instance during plugin installation 3.
`static final int`
`RC_OK`
Return code indicating command completed successfully, 0.
`static final int`
`RC_UNKNOWN`
Return code indicating an unknown error occurred, -1 .

## Constructor Summary

Constructors
Constructor
Description
`AbstractCommandLine()`

## Method Summary

Modifier and Type
Method
Description
`protected int`
`doRun(T args)`
The execution method to override.
`private static void`
`error(String error)`
Prints the error message to STDERR.
`protected List<Resource>`
`getAdditionalSpringResources()`
Return any additional resources that should be prepended to that supplied by the caller.
`protected GenericApplicationContext`
`getApplicationContext()`
Get the Spring context.
`protected abstract Class<T>`
`getArgumentClass()`
Get the class of the argument object to instantiate.
`protected abstract org.slf4j.Logger`
`getLogger()`
Get logger.
`protected abstract String`
`getVersion()`
Return an appropriate version value.
`protected void`
`initLogging(T args)`
Initialize the logging subsystem.
`protected int`
`run(String[] args)`
Run method.
`protected void`
`setCaseSensitiveOptions(boolean flag)`
Sets whether JCommander parses options case-sensitively or not.
`protected void`
`setContextInitializer(ApplicationContextInitializer<? super FilesystemGenericApplicationContext> initializer)`
Set a context initializer.
`private void`
`setLoggingProperty(String value)`
Set the logback configuration to a specific location.
`private void`
`setLoggingToLocalResource(String value)`
Set the logback configuration to a specific package-local resource.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### ARGS_PROPERTY

@Nonnull @NotEmpty public static final String ARGS_PROPERTY
Name of system property for command line argument class.

See Also:
  - Constant Field Values

### RC_OK

public static final int RC_OK
Return code indicating command completed successfully, 0.

See Also:
  - Constant Field Values

### RC_INIT

public static final int RC_INIT
Return code indicating an initialization error, 1.

See Also:
  - Constant Field Values

### RC_IO

public static final int RC_IO
Return code indicating an error reading files, 2.

See Also:
  - Constant Field Values

### RC_MODULE

public static final int RC_MODULE
Return code indicating an module mismatch, for instance during plugin installation 3.

See Also:
  - Constant Field Values

### RC_UNKNOWN

public static final int RC_UNKNOWN
Return code indicating an unknown error occurred, -1 .

See Also:
  - Constant Field Values

### caseSensitiveOptions

private boolean caseSensitiveOptions
Whether options are case-sensitive.

### applicationContext

@Nullable private GenericApplicationContext applicationContext
Spring context.

### contextInitializer

@Nullable private ApplicationContextInitializer<? super FilesystemGenericApplicationContext> contextInitializer
Optional Context initialized.

## Constructor Details

### AbstractCommandLine

public AbstractCommandLine()

## Method Details

### setCaseSensitiveOptions

protected void setCaseSensitiveOptions(boolean flag)
Sets whether JCommander parses options case-sensitively or not.

Default is true.

Parameters:
  `flag` - flag to set
Since:
  9.0.0

### setContextInitializer

protected void setContextInitializer(@Nonnull ApplicationContextInitializer<? super FilesystemGenericApplicationContext> initializer)
Set a context initializer.

Parameters:
  `initializer` - what to set

### getApplicationContext

@Nonnull protected GenericApplicationContext getApplicationContext()
Get the Spring context.

Returns:
  Spring context

### getAdditionalSpringResources

@Nonnull @Unmodifiable @NotLive protected List<Resource> getAdditionalSpringResources()
Return any additional resources that should be prepended to that supplied by the caller.

Returns:
  the resources

### run

protected int run(@Nonnull String[] args)
Run method.

Parameters:
  `args` - command line arguments
Returns:
  exit code

### setLoggingProperty

private void setLoggingProperty(@Nonnull String value)
Set the logback configuration to a specific location.

Note that this must be done before the first logger is retrieved.

Parameters:
  `value` - logback configuration location to set

### setLoggingToLocalResource

private void setLoggingToLocalResource(@Nonnull String value)
Set the logback configuration to a specific package-local resource.

Parameters:
  `value` - name of resource to use as the logback configuration file

### initLogging

protected void initLogging(@Nonnull T args)
Initialize the logging subsystem.

Parameters:
  `args` - command line arguments

### doRun

protected int doRun(@Nonnull T args)
The execution method to override. The default implementation handles Spring context creation.

Parameters:
  `args` - input arguments
Returns:
  exit code

### getArgumentClass

@Nonnull protected abstract Class<T> getArgumentClass()
Get the class of the argument object to instantiate.

Returns:
  argument class

### getVersion

@Nonnull @NotEmpty protected abstract String getVersion()
Return an appropriate version value.

Returns:
  a version string

### getLogger

@Nonnull protected abstract org.slf4j.Logger getLogger()
Get logger.

Returns:
  logger

### error

private static void error(@Nonnull @NotEmpty String error)
Prints the error message to STDERR.

Parameters:
  `error` - the error message