Package picocli
Class AutoComplete
- java.lang.Object
-
- picocli.AutoComplete
-
public class AutoComplete extends java.lang.Object
Stand-alone tool that generates bash auto-complete scripts for picocli-based command line applications.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AutoComplete.App
CLI command class for generating completion script.private static class
AutoComplete.Bashify
Drops all characters that are not valid for bash function and identifier names.private static class
AutoComplete.BooleanArgFilter
private static class
AutoComplete.CommandDescriptor
private static interface
AutoComplete.Function<T,V>
static class
AutoComplete.GenerateCompletion
Command that generates a Bash/ZSH completion script for its top-level command.private static class
AutoComplete.NullFunction
private static interface
AutoComplete.Predicate<T>
-
Field Summary
Fields Modifier and Type Field Description static int
EXIT_CODE_COMMAND_SCRIPT_EXISTS
Exit code of this application when the specified command script exists (2).static int
EXIT_CODE_COMPLETION_SCRIPT_EXISTS
Exit code of this application when the specified completion script exists (3).static int
EXIT_CODE_EXECUTION_ERROR
Exit code of this application when an exception was encountered during operation (4).static int
EXIT_CODE_INVALID_INPUT
Exit code of this application when the specified command line arguments are invalid (1).static int
EXIT_CODE_SUCCESS
Normal exit code of this application (0).private static java.lang.String
SCRIPT_FOOTER
private static java.lang.String
SCRIPT_HEADER
-
Constructor Summary
Constructors Modifier Constructor Description private
AutoComplete()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
addCandidatesForArgsFollowing(java.lang.Object obj, java.util.List<java.lang.CharSequence> candidates)
private static void
addCandidatesForArgsFollowing(CommandLine.Model.CommandSpec commandSpec, java.util.List<java.lang.CharSequence> candidates)
private static void
addCandidatesForArgsFollowing(CommandLine.Model.OptionSpec optionSpec, java.util.List<java.lang.CharSequence> candidates)
private static void
addCandidatesForArgsFollowing(CommandLine.Model.PositionalParamSpec positionalSpec, java.util.List<java.lang.CharSequence> candidates)
private static void
addCompletionCandidates(java.lang.Iterable<java.lang.String> completionCandidates, java.util.List<java.lang.CharSequence> candidates)
static void
bash(java.lang.String scriptName, java.io.File out, java.io.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 java.lang.String
bash(java.lang.String scriptName, CommandLine commandLine)
Generates and returns the source code for an autocompletion bash script for the specified picocli-based application.private static java.lang.String
bashify(java.lang.CharSequence value)
static int
complete(CommandLine.Model.CommandSpec spec, java.lang.String[] args, int argIndex, int positionInArg, int cursor, java.util.List<java.lang.CharSequence> candidates)
private static java.lang.String
concat(java.lang.String infix, java.lang.String... values)
private static java.lang.String
concat(java.lang.String infix, java.util.List<java.lang.String> values)
private static <V,T extends V>
java.lang.Stringconcat(java.lang.String infix, java.util.List<T> values, T lastValue, AutoComplete.Function<V,java.lang.String> normalize)
private static java.util.List<AutoComplete.CommandDescriptor>
createHierarchy(java.lang.String scriptName, CommandLine commandLine)
private static void
createSubHierarchy(java.lang.String scriptName, CommandLine commandLine, java.util.List<AutoComplete.CommandDescriptor> out)
private static boolean
exitOnError()
private static boolean
exitOnSuccess()
private static java.util.List<java.lang.String>
extract(java.lang.Iterable<java.lang.String> generator)
private static <K,T extends K>
java.util.List<T>filter(java.util.List<T> list, AutoComplete.Predicate<K> filter)
private static void
filterAndTrimMatchingPrefix(java.lang.String prefix, java.util.List<java.lang.CharSequence> candidates)
private static CommandLine.Model.CommandSpec
findCommandFor(CommandLine.Model.ArgSpec arg, CommandLine.Model.CommandSpec cmd)
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 java.lang.Object
findCompletionStartPoint(CommandLine.ParseResult parseResult)
private static void
generateCompletionCandidates(java.lang.StringBuilder buff, CommandLine.Model.OptionSpec f)
private static java.lang.String
generateEntryPointFunction(java.lang.String scriptName, CommandLine commandLine, java.util.List<AutoComplete.CommandDescriptor> hierarchy)
private static void
generateFunctionCallsToArrContains(java.lang.StringBuilder buff, java.util.List<java.lang.String> functionCalls, java.util.List<AutoComplete.CommandDescriptor> hierarchy)
private static java.lang.String
generateFunctionForCommand(java.lang.String functionName, java.lang.String commandName, CommandLine commandLine)
private static java.lang.String
generateOptionsCases(java.util.List<CommandLine.Model.OptionSpec> argOptionFields, java.lang.String indent, java.lang.String currWord)
private static java.lang.String
generateOptionsSwitch(java.util.List<CommandLine.Model.OptionSpec> argOptions)
private static java.lang.String
generatePositionalParamsCases(java.util.List<CommandLine.Model.PositionalParamSpec> posParams, java.lang.String indent, java.lang.String currWord)
private static void
generatePositionParamCompletionCandidates(java.lang.StringBuilder buff, CommandLine.Model.PositionalParamSpec f)
private static boolean
isPicocliModelObject(java.lang.Object obj)
static void
main(java.lang.String... args)
Generates a bash completion script for the specified command class.private static <T> AutoComplete.Predicate<T>
negate(AutoComplete.Predicate<T> original)
private static java.lang.String
optionNames(java.util.List<CommandLine.Model.OptionSpec> options)
private static boolean
syspropDefinedAndNotFalse(java.lang.String key)
-
-
-
Field Detail
-
EXIT_CODE_SUCCESS
public static final int EXIT_CODE_SUCCESS
Normal exit code of this application (0).- See Also:
- Constant Field Values
-
EXIT_CODE_INVALID_INPUT
public static final int EXIT_CODE_INVALID_INPUT
Exit code of this application when the specified command line arguments are invalid (1).- See Also:
- Constant Field Values
-
EXIT_CODE_COMMAND_SCRIPT_EXISTS
public static final int EXIT_CODE_COMMAND_SCRIPT_EXISTS
Exit code of this application when the specified command script exists (2).- See Also:
- Constant Field Values
-
EXIT_CODE_COMPLETION_SCRIPT_EXISTS
public static final int EXIT_CODE_COMPLETION_SCRIPT_EXISTS
Exit code of this application when the specified completion script exists (3).- See Also:
- Constant Field Values
-
EXIT_CODE_EXECUTION_ERROR
public static final int EXIT_CODE_EXECUTION_ERROR
Exit code of this application when an exception was encountered during operation (4).- See Also:
- Constant Field Values
-
SCRIPT_HEADER
private static final java.lang.String SCRIPT_HEADER
- See Also:
- Constant Field Values
-
SCRIPT_FOOTER
private static final java.lang.String SCRIPT_FOOTER
- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(java.lang.String... args)
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
private static boolean syspropDefinedAndNotFalse(java.lang.String key)
-
bashify
private static java.lang.String bashify(java.lang.CharSequence value)
-
negate
private static <T> AutoComplete.Predicate<T> negate(AutoComplete.Predicate<T> original)
-
filter
private static <K,T extends K> java.util.List<T> filter(java.util.List<T> list, AutoComplete.Predicate<K> filter)
-
bash
public static void bash(java.lang.String scriptName, java.io.File out, java.io.File command, CommandLine commandLine) throws java.io.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 forcommandLine
- theCommandLine
instance for the command line applicationout
- 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 written- Throws:
java.io.IOException
- if a problem occurred writing to the specified files
-
bash
public static java.lang.String bash(java.lang.String scriptName, CommandLine commandLine)
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 java.util.List<AutoComplete.CommandDescriptor> createHierarchy(java.lang.String scriptName, CommandLine commandLine)
-
createSubHierarchy
private static void createSubHierarchy(java.lang.String scriptName, CommandLine commandLine, java.util.List<AutoComplete.CommandDescriptor> out)
-
generateEntryPointFunction
private static java.lang.String generateEntryPointFunction(java.lang.String scriptName, CommandLine commandLine, java.util.List<AutoComplete.CommandDescriptor> hierarchy)
-
generateFunctionCallsToArrContains
private static void generateFunctionCallsToArrContains(java.lang.StringBuilder buff, java.util.List<java.lang.String> functionCalls, java.util.List<AutoComplete.CommandDescriptor> hierarchy)
-
concat
private static java.lang.String concat(java.lang.String infix, java.lang.String... values)
-
concat
private static java.lang.String concat(java.lang.String infix, java.util.List<java.lang.String> values)
-
concat
private static <V,T extends V> java.lang.String concat(java.lang.String infix, java.util.List<T> values, T lastValue, AutoComplete.Function<V,java.lang.String> normalize)
-
generateFunctionForCommand
private static java.lang.String generateFunctionForCommand(java.lang.String functionName, java.lang.String commandName, CommandLine commandLine)
-
generatePositionParamCompletionCandidates
private static void generatePositionParamCompletionCandidates(java.lang.StringBuilder buff, CommandLine.Model.PositionalParamSpec f)
-
generateCompletionCandidates
private static void generateCompletionCandidates(java.lang.StringBuilder buff, CommandLine.Model.OptionSpec f)
-
extract
private static java.util.List<java.lang.String> extract(java.lang.Iterable<java.lang.String> generator)
-
generatePositionalParamsCases
private static java.lang.String generatePositionalParamsCases(java.util.List<CommandLine.Model.PositionalParamSpec> posParams, java.lang.String indent, java.lang.String currWord)
-
generateOptionsSwitch
private static java.lang.String generateOptionsSwitch(java.util.List<CommandLine.Model.OptionSpec> argOptions)
-
generateOptionsCases
private static java.lang.String generateOptionsCases(java.util.List<CommandLine.Model.OptionSpec> argOptionFields, java.lang.String indent, java.lang.String currWord)
-
optionNames
private static java.lang.String optionNames(java.util.List<CommandLine.Model.OptionSpec> options)
-
complete
public static int complete(CommandLine.Model.CommandSpec spec, java.lang.String[] args, int argIndex, int positionInArg, int cursor, java.util.List<java.lang.CharSequence> candidates)
-
findCompletionStartPoint
private static java.lang.Object findCompletionStartPoint(CommandLine.ParseResult parseResult)
-
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
private static boolean isPicocliModelObject(java.lang.Object obj)
-
filterAndTrimMatchingPrefix
private static void filterAndTrimMatchingPrefix(java.lang.String prefix, java.util.List<java.lang.CharSequence> candidates)
-
addCandidatesForArgsFollowing
private static void addCandidatesForArgsFollowing(java.lang.Object obj, java.util.List<java.lang.CharSequence> candidates)
-
addCandidatesForArgsFollowing
private static void addCandidatesForArgsFollowing(CommandLine.Model.CommandSpec commandSpec, java.util.List<java.lang.CharSequence> candidates)
-
addCandidatesForArgsFollowing
private static void addCandidatesForArgsFollowing(CommandLine.Model.OptionSpec optionSpec, java.util.List<java.lang.CharSequence> candidates)
-
addCandidatesForArgsFollowing
private static void addCandidatesForArgsFollowing(CommandLine.Model.PositionalParamSpec positionalSpec, java.util.List<java.lang.CharSequence> candidates)
-
addCompletionCandidates
private static void addCompletionCandidates(java.lang.Iterable<java.lang.String> completionCandidates, java.util.List<java.lang.CharSequence> candidates)
-
-