Package picocli
Class AutoComplete
java.lang.Object
picocli.AutoComplete
Stand-alone tool that generates bash auto-complete scripts for picocli-based command line applications.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
CLI command class for generating completion script.private static class
Drops all characters that are not valid for bash function and identifier names.private static class
private static class
private static interface
static class
Command that generates a Bash/ZSH completion script for its top-level command.private static class
private static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Exit code of this application when the specified command script exists (2).static final int
Exit code of this application when the specified completion script exists (3).static final int
Exit code of this application when an exception was encountered during operation (4).static final int
Exit code of this application when the specified command line arguments are invalid (1).static final int
Normal exit code of this application (0).private static final String
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addCandidatesForArgsFollowing
(Object obj, List<CharSequence> candidates) private static void
addCandidatesForArgsFollowing
(CommandLine.Model.CommandSpec commandSpec, List<CharSequence> candidates) private static void
addCandidatesForArgsFollowing
(CommandLine.Model.OptionSpec optionSpec, List<CharSequence> candidates) private static void
addCandidatesForArgsFollowing
(CommandLine.Model.PositionalParamSpec positionalSpec, List<CharSequence> candidates) private static void
addCompletionCandidates
(Iterable<String> completionCandidates, List<CharSequence> candidates) static void
bash
(String scriptName, File out, File command, CommandLine commandLine) Generates source code for an autocompletion bash script for the specified picocli-based application, and writes this script to the specifiedout
file, and optionally writes an invocation script to the specifiedcommand
file.static String
bash
(String scriptName, CommandLine commandLine) Generates and returns the source code for an autocompletion bash script for the specified picocli-based application.private static String
bashify
(CharSequence value) static int
complete
(CommandLine.Model.CommandSpec spec, String[] args, int argIndex, int positionInArg, int cursor, List<CharSequence> candidates) private static String
private static String
private static <V,
T extends V>
Stringconcat
(String infix, List<T> values, T lastValue, AutoComplete.Function<V, String> normalize) private static List
<AutoComplete.CommandDescriptor> createHierarchy
(String scriptName, CommandLine commandLine) private static void
createSubHierarchy
(String scriptName, String parentWithoutTopLevelCommand, CommandLine commandLine, List<AutoComplete.CommandDescriptor> out) private static boolean
private static boolean
private static <K,
T extends K>
List<T> filter
(List<T> list, AutoComplete.Predicate<K> filter) private static void
filterAndTrimMatchingPrefix
(String prefix, List<CharSequence> candidates) private static CommandLine.Model.CommandSpec
private static CommandLine.Model.CommandSpec
findCommandFor
(CommandLine.Model.OptionSpec option, CommandLine.Model.CommandSpec commandSpec) private static CommandLine.Model.CommandSpec
findCommandFor
(CommandLine.Model.PositionalParamSpec positional, CommandLine.Model.CommandSpec commandSpec) private static Object
findCompletionStartPoint
(CommandLine.ParseResult parseResult) private static void
private static void
generatedEdgeCaseFunctionCalls
(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy) private static String
generateEntryPointFunction
(String scriptName, CommandLine commandLine, List<AutoComplete.CommandDescriptor> hierarchy) private static void
generateFunctionCallsToArrContains
(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy) private static String
generateFunctionForCommand
(String functionName, String commandName, CommandLine commandLine) private static String
generateOptionsCases
(List<CommandLine.Model.OptionSpec> argOptionFields, String indent, String currWord) private static String
generateOptionsSwitch
(List<CommandLine.Model.OptionSpec> argOptions) private static String
generatePositionalParamsCases
(List<CommandLine.Model.PositionalParamSpec> posParams, String indent, String currWord) private static void
generatePositionParamCompletionCandidates
(StringBuilder buff, CommandLine.Model.PositionalParamSpec f) private static boolean
static void
Generates a bash completion script for the specified command class.private static <T> AutoComplete.Predicate
<T> negate
(AutoComplete.Predicate<T> original) private static String
optionNames
(List<CommandLine.Model.OptionSpec> options) private static String
sanitizeScriptName
(String scriptName) private static boolean
-
Field Details
-
EXIT_CODE_SUCCESS
public static final int EXIT_CODE_SUCCESSNormal exit code of this application (0).- See Also:
-
EXIT_CODE_INVALID_INPUT
public static final int EXIT_CODE_INVALID_INPUTExit code of this application when the specified command line arguments are invalid (1).- See Also:
-
EXIT_CODE_COMMAND_SCRIPT_EXISTS
public static final int EXIT_CODE_COMMAND_SCRIPT_EXISTSExit code of this application when the specified command script exists (2).- See Also:
-
EXIT_CODE_COMPLETION_SCRIPT_EXISTS
public static final int EXIT_CODE_COMPLETION_SCRIPT_EXISTSExit code of this application when the specified completion script exists (3).- See Also:
-
EXIT_CODE_EXECUTION_ERROR
public static final int EXIT_CODE_EXECUTION_ERRORExit code of this application when an exception was encountered during operation (4).- See Also:
-
SCRIPT_HEADER
- See Also:
-
SCRIPT_FOOTER
- See Also:
-
-
Constructor Details
-
AutoComplete
private AutoComplete()
-
-
Method Details
-
main
Generates a bash completion script for the specified command class.- Parameters:
args
- command line options. Specify at least thecommandLineFQCN
mandatory parameter, which is the fully qualified class name of the annotated@Command
class to generate a completion script for. Other parameters are optional. Specify-h
to see details on the available options.
-
exitOnSuccess
private static boolean exitOnSuccess() -
exitOnError
private static boolean exitOnError() -
syspropDefinedAndNotFalse
-
bashify
-
negate
-
filter
-
sanitizeScriptName
-
bash
public static void bash(String scriptName, File out, File command, CommandLine commandLine) throws IOException Generates source code for an autocompletion bash script for the specified picocli-based application, and writes this script to the specifiedout
file, and optionally writes an invocation script to the specifiedcommand
file.- Parameters:
scriptName
- the name of the command to generate a bash autocompletion script forout
- the file to write the autocompletion bash script source code tocommand
- the file to write a helper script to that invokes the command, ornull
if no helper script file should be writtencommandLine
- theCommandLine
instance for the command line application- Throws:
IOException
- if a problem occurred writing to the specified files
-
bash
Generates and returns the source code for an autocompletion bash script for the specified picocli-based application.- Parameters:
scriptName
- the name of the command to generate a bash autocompletion script forcommandLine
- theCommandLine
instance for the command line application- Returns:
- source code for an autocompletion bash script
-
createHierarchy
private static List<AutoComplete.CommandDescriptor> createHierarchy(String scriptName, CommandLine commandLine) -
createSubHierarchy
private static void createSubHierarchy(String scriptName, String parentWithoutTopLevelCommand, CommandLine commandLine, List<AutoComplete.CommandDescriptor> out) -
generateEntryPointFunction
private static String generateEntryPointFunction(String scriptName, CommandLine commandLine, List<AutoComplete.CommandDescriptor> hierarchy) -
generatedEdgeCaseFunctionCalls
private static void generatedEdgeCaseFunctionCalls(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy) -
generateFunctionCallsToArrContains
private static void generateFunctionCallsToArrContains(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy) -
concat
-
concat
-
concat
private static <V,T extends V> String concat(String infix, List<T> values, T lastValue, AutoComplete.Function<V, String> normalize) -
generateFunctionForCommand
private static String generateFunctionForCommand(String functionName, String commandName, CommandLine commandLine) -
generatePositionParamCompletionCandidates
private static void generatePositionParamCompletionCandidates(StringBuilder buff, CommandLine.Model.PositionalParamSpec f) -
generateCompletionCandidates
private static void generateCompletionCandidates(StringBuilder buff, CommandLine.Model.OptionSpec f) -
extract
-
generatePositionalParamsCases
private static String generatePositionalParamsCases(List<CommandLine.Model.PositionalParamSpec> posParams, String indent, String currWord) -
generateOptionsSwitch
-
generateOptionsCases
private static String generateOptionsCases(List<CommandLine.Model.OptionSpec> argOptionFields, String indent, String currWord) -
optionNames
-
complete
public static int complete(CommandLine.Model.CommandSpec spec, String[] args, int argIndex, int positionInArg, int cursor, List<CharSequence> candidates) -
findCompletionStartPoint
-
findCommandFor
private static CommandLine.Model.CommandSpec findCommandFor(CommandLine.Model.ArgSpec arg, CommandLine.Model.CommandSpec cmd) -
findCommandFor
private static CommandLine.Model.CommandSpec findCommandFor(CommandLine.Model.OptionSpec option, CommandLine.Model.CommandSpec commandSpec) -
findCommandFor
private static CommandLine.Model.CommandSpec findCommandFor(CommandLine.Model.PositionalParamSpec positional, CommandLine.Model.CommandSpec commandSpec) -
isPicocliModelObject
-
filterAndTrimMatchingPrefix
-
addCandidatesForArgsFollowing
-
addCandidatesForArgsFollowing
private static void addCandidatesForArgsFollowing(CommandLine.Model.CommandSpec commandSpec, List<CharSequence> candidates) -
addCandidatesForArgsFollowing
private static void addCandidatesForArgsFollowing(CommandLine.Model.OptionSpec optionSpec, List<CharSequence> candidates) -
addCandidatesForArgsFollowing
private static void addCandidatesForArgsFollowing(CommandLine.Model.PositionalParamSpec positionalSpec, List<CharSequence> candidates) -
addCompletionCandidates
private static void addCompletionCandidates(Iterable<String> completionCandidates, List<CharSequence> candidates)
-