-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Constant for theAirlineModule
annotation classstatic final String
Constant for thecom.google.inject.Inject
annotation classprivate static Map
<String, Class<? extends Annotation>> static final String
Constant for thejakarta.inject.Inject
annotation classstatic final String
Constant for thejavax.inject.Inject
annotation class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
buildGroupsHierarchy
(List<CommandGroupMetadata> commandGroups, Map<String, CommandGroupMetadata> subGroups) private static void
checkForInjectionAnnotation
(MetadataLoader.InjectionMetadata injectionMetadata, Field field, List<Field> path, String annotationClass, ParserMetadata<?> parserConfig) private static void
collectPartial
(Map<Class<? extends Annotation>, Set<Integer>> partials, Partial partial) private static void
createGroupsFromAnnotations
(List<CommandMetadata> allCommands, List<CommandMetadata> newCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) static CommandMetadata
loadCommand
(Class<?> commandType, ParserMetadata<?> parserConfig) Loads command meta-datastatic CommandMetadata
loadCommand
(Class<?> commandType, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-datastatic CommandGroupMetadata
loadCommandGroup
(String name, String description, boolean hidden, Iterable<CommandGroupMetadata> subGroups, CommandMetadata defaultCommand, Iterable<CommandMetadata> commands) Loads command group meta-datastatic <T> List
<CommandMetadata> loadCommands
(Iterable<Class<? extends T>> defaultCommands, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-datastatic void
loadCommandsIntoGroupsByAnnotation
(List<CommandMetadata> allCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) static <C> GlobalMetadata
<C> loadGlobal
(Class<?> cliClass) static <C> GlobalMetadata
<C> loadGlobal
(Class<?> cliClass, ParserMetadata<C> parserConfigOverride) Loads the metadata for a CLIstatic <C> GlobalMetadata
<C> loadGlobal
(String name, String description, CommandMetadata defaultCommand, Iterable<CommandMetadata> defaultGroupCommands, Iterable<CommandGroupMetadata> groups, Iterable<GlobalRestriction> restrictions, Iterable<HelpSection> baseHelpSections, ParserMetadata<C> parserConfig) Loads global meta-dataprotected static Map
<String, HelpSection> loadHelpSections
(Class<?> sourceClass, Map<String, HelpSection> baseHelpSections) static void
loadInjectionMetadata
(Class<?> type, MetadataLoader.InjectionMetadata injectionMetadata, List<Field> fields, ParserMetadata<?> parserConfig) Loads injection meta-dataloadInjectionMetadata
(Class<?> type, ParserMetadata<?> parserConfig) Loads injection meta-dataprivate static <C> ParserMetadata
<C> loadParser
(Parser parserConfig) static <C> ParserMetadata
<C> loadParser
(Class<?> cliClass) private static Map
<Class<? extends Annotation>, Set<Integer>> loadPartials
(Field field) static SuggesterMetadata
loadSuggester
(Class<? extends Suggester> suggesterClass, ParserMetadata<?> parserConfig) Loads suggester meta-dataprivate static List
<OptionMetadata> mergeOptionSet
(List<OptionMetadata> options) private static List
<OptionMetadata> overrideOptionSet
(List<OptionMetadata> options) private static void
tryOverrideOptions
(Map<Set<String>, OptionMetadata> optionIndex, Set<String> names, OptionMetadata parent)
-
Field Details
-
AIRLINE_MODULE
Constant for theAirlineModule
annotation class- See Also:
-
JAVAX_INJECT_INJECT
Constant for thejavax.inject.Inject
annotation class- See Also:
-
JAKARTA_INJECT_INJECT
Constant for thejakarta.inject.Inject
annotation class- See Also:
-
COM_GOOGLE_INJECT_INJECT
Constant for thecom.google.inject.Inject
annotation class- See Also:
-
dynamicAnnotationCache
-
-
Constructor Details
-
MetadataLoader
public MetadataLoader()
-
-
Method Details
-
loadParser
-
loadParser
-
loadGlobal
-
loadGlobal
public static <C> GlobalMetadata<C> loadGlobal(Class<?> cliClass, ParserMetadata<C> parserConfigOverride) Loads the metadata for a CLI- Parameters:
cliClass
- Class that has theCli
annotationparserConfigOverride
- Optional parser configuration, note that theCli.parserConfiguration()
field is normally used to provide a parser configuration via annotation but in some situations this may not be possible, e.g. constructing user alias search paths programmatically, in which case providing a parser configuration here overrides anything specified directly on the annotation- Returns:
- Global metadata
-
loadGlobal
public static <C> GlobalMetadata<C> loadGlobal(String name, String description, CommandMetadata defaultCommand, Iterable<CommandMetadata> defaultGroupCommands, Iterable<CommandGroupMetadata> groups, Iterable<GlobalRestriction> restrictions, Iterable<HelpSection> baseHelpSections, ParserMetadata<C> parserConfig) Loads global meta-data- Parameters:
name
- CLI namedescription
- CLI descriptiondefaultCommand
- Default CommanddefaultGroupCommands
- Default Group Commandsgroups
- Command Groupsrestrictions
- RestrictionsbaseHelpSections
- Base help sectionsparserConfig
- Parser Configuration- Returns:
- Global meta-data
-
loadCommandGroup
public static CommandGroupMetadata loadCommandGroup(String name, String description, boolean hidden, Iterable<CommandGroupMetadata> subGroups, CommandMetadata defaultCommand, Iterable<CommandMetadata> commands) Loads command group meta-data- Parameters:
name
- Group namedescription
- Group descriptionhidden
- Whether the group is hiddendefaultCommand
- Default command for the groupcommands
- Commands for the group- Returns:
- Command group meta-data
-
loadCommands
public static <T> List<CommandMetadata> loadCommands(Iterable<Class<? extends T>> defaultCommands, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-data- Parameters:
defaultCommands
- Default command classes- Returns:
- Command meta-data
-
loadCommand
Loads command meta-data- Parameters:
commandType
- Command class- Returns:
- Command meta-data
-
loadCommand
public static CommandMetadata loadCommand(Class<?> commandType, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) Loads command meta-data- Parameters:
commandType
- Command TypebaseHelpSections
- Base set of help sections- Returns:
- Command meta-data
-
loadHelpSections
protected static Map<String,HelpSection> loadHelpSections(Class<?> sourceClass, Map<String, HelpSection> baseHelpSections) -
loadSuggester
public static SuggesterMetadata loadSuggester(Class<? extends Suggester> suggesterClass, ParserMetadata<?> parserConfig) Loads suggester meta-data- Parameters:
suggesterClass
- Suggester class- Returns:
- Suggester meta-data
-
loadInjectionMetadata
public static MetadataLoader.InjectionMetadata loadInjectionMetadata(Class<?> type, ParserMetadata<?> parserConfig) Loads injection meta-dataGiven a class that represents a command, searches its fields to find those that are annotated with Airline annotations e.g.
Option
,Arguments
in order to discover all the options and arguments for a command. This also includes walking back up the superclass hierarchy so options and arguments may be defined in shared base classes and still discovered.Additionally options and arguments may be modularised out into separate classes that can be composed into your command classes by defining a field of the appropriate type and annotating it with an injection annotation to tell Airline it also needs to discover options inside that class.
Historically Airline supported only the
javax.inject.Inject
annotation, but with the move of mostjavax
packages (Java EE) to the stewardship of the Eclipse Foundation those packages are gradually being migrated into thejakarta
namespace. As of 2.9.0 Airline makes the choice of annotation fully configurable via the parser configuration. To avoid potential class loading issues these are specified as string class names with the metadata loader dynamically loading the relevant annotation classes if they are present on the runtime classpath. As of 3.10.0 we only look for our ownAirlineModule
annotation and any other composition annotation e.g.jakarta.inject.Inject
MUST be explicitly configured.- Parameters:
type
- ClassparserConfig
- Parser Configuration- Returns:
- Injection meta-data
-
loadInjectionMetadata
public static void loadInjectionMetadata(Class<?> type, MetadataLoader.InjectionMetadata injectionMetadata, List<Field> fields, ParserMetadata<?> parserConfig) Loads injection meta-data- Parameters:
type
- ClassinjectionMetadata
- Injection meta-datafields
- Fields
-
checkForInjectionAnnotation
private static void checkForInjectionAnnotation(MetadataLoader.InjectionMetadata injectionMetadata, Field field, List<Field> path, String annotationClass, ParserMetadata<?> parserConfig) -
loadPartials
-
collectPartial
-
mergeOptionSet
-
overrideOptionSet
-
tryOverrideOptions
private static void tryOverrideOptions(Map<Set<String>, OptionMetadata> optionIndex, Set<String> names, OptionMetadata parent) -
loadCommandsIntoGroupsByAnnotation
public static void loadCommandsIntoGroupsByAnnotation(List<CommandMetadata> allCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) -
createGroupsFromAnnotations
private static void createGroupsFromAnnotations(List<CommandMetadata> allCommands, List<CommandMetadata> newCommands, List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup, Map<String, HelpSection> baseHelpSections, ParserMetadata<?> parserConfig) -
buildGroupsHierarchy
protected static void buildGroupsHierarchy(List<CommandGroupMetadata> commandGroups, Map<String, CommandGroupMetadata> subGroups)
-