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 classCLI command class for generating completion script.private static classDrops all characters that are not valid for bash function and identifier names.private static classprivate static classprivate static interfacestatic classCommand that generates a Bash/ZSH completion script for its top-level command.private static classprivate static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intExit code of this application when the specified command script exists (2).static final intExit code of this application when the specified completion script exists (3).static final intExit code of this application when an exception was encountered during operation (4).static final intExit code of this application when the specified command line arguments are invalid (1).static final intNormal exit code of this application (0).private static final Stringprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddCandidatesForArgsFollowing(Object obj, List<CharSequence> candidates) private static voidaddCandidatesForArgsFollowing(CommandLine.Model.CommandSpec commandSpec, List<CharSequence> candidates) private static voidaddCandidatesForArgsFollowing(CommandLine.Model.OptionSpec optionSpec, List<CharSequence> candidates) private static voidaddCandidatesForArgsFollowing(CommandLine.Model.PositionalParamSpec positionalSpec, List<CharSequence> candidates) private static voidaddCompletionCandidates(Iterable<String> completionCandidates, List<CharSequence> candidates) static voidbash(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 specifiedoutfile, and optionally writes an invocation script to the specifiedcommandfile.static Stringbash(String scriptName, CommandLine commandLine) Generates and returns the source code for an autocompletion bash script for the specified picocli-based application.private static Stringbashify(CharSequence value) static intcomplete(CommandLine.Model.CommandSpec spec, String[] args, int argIndex, int positionInArg, int cursor, List<CharSequence> candidates) private static Stringprivate static Stringprivate 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 voidcreateSubHierarchy(String scriptName, String parentWithoutTopLevelCommand, CommandLine commandLine, List<AutoComplete.CommandDescriptor> out) private static booleanprivate static booleanprivate static <K,T extends K>
List<T> filter(List<T> list, AutoComplete.Predicate<K> filter) private static voidfilterAndTrimMatchingPrefix(String prefix, List<CharSequence> candidates) private static CommandLine.Model.CommandSpecprivate static CommandLine.Model.CommandSpecfindCommandFor(CommandLine.Model.OptionSpec option, CommandLine.Model.CommandSpec commandSpec) private static CommandLine.Model.CommandSpecfindCommandFor(CommandLine.Model.PositionalParamSpec positional, CommandLine.Model.CommandSpec commandSpec) private static ObjectfindCompletionStartPoint(CommandLine.ParseResult parseResult) private static voidprivate static voidgeneratedEdgeCaseFunctionCalls(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy) private static StringgenerateEntryPointFunction(String scriptName, CommandLine commandLine, List<AutoComplete.CommandDescriptor> hierarchy) private static voidgenerateFunctionCallsToArrContains(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy) private static StringgenerateFunctionForCommand(String functionName, String commandName, CommandLine commandLine) private static StringgenerateOptionsCases(List<CommandLine.Model.OptionSpec> argOptionFields, String indent, String currWord) private static StringgenerateOptionsSwitch(List<CommandLine.Model.OptionSpec> argOptions) private static StringgeneratePositionalParamsCases(List<CommandLine.Model.PositionalParamSpec> posParams, String indent, String currWord) private static voidgeneratePositionParamCompletionCandidates(StringBuilder buff, CommandLine.Model.PositionalParamSpec f) private static booleanstatic voidGenerates a bash completion script for the specified command class.private static <T> AutoComplete.Predicate<T> negate(AutoComplete.Predicate<T> original) private static StringoptionNames(List<CommandLine.Model.OptionSpec> options) private static StringsanitizeScriptName(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 thecommandLineFQCNmandatory parameter, which is the fully qualified class name of the annotated@Commandclass to generate a completion script for. Other parameters are optional. Specify-hto 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 specifiedoutfile, and optionally writes an invocation script to the specifiedcommandfile.- 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, ornullif no helper script file should be writtencommandLine- theCommandLineinstance 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- theCommandLineinstance 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)
-