Top Description Inners Fields Constructors Methods
picocli

public Class AutoComplete

extends Object
Class Inheritance
Static Imports
java.lang.String.format

Stand-alone tool that generates bash auto-complete scripts for picocli-based command line applications.

Nested and Inner Type Summary

Modifier and TypeClass and 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
private static class
private static interface
public static class
AutoComplete.GenerateCompletion

Command that generates a Bash/ZSH completion script for its top-level command.

private static class
private static interface

Field Summary

Modifier and TypeField and Description
public static final int
EXIT_CODE_COMMAND_SCRIPT_EXISTS

Exit code of this application when the specified command script exists (2).

public static final int
EXIT_CODE_COMPLETION_SCRIPT_EXISTS

Exit code of this application when the specified completion script exists (3).

public static final int
EXIT_CODE_EXECUTION_ERROR

Exit code of this application when an exception was encountered during operation (4).

public static final int
EXIT_CODE_INVALID_INPUT

Exit code of this application when the specified command line arguments are invalid (1).

public static final int
EXIT_CODE_SUCCESS

Normal exit code of this application (0).

private static final String
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
private static void
private static void
private static void
private static void
addCompletionCandidates(Iterable<String> completionCandidates, List<CharSequence> candidates)

public static void
bash(String
the name of the command to generate a bash autocompletion script for
scriptName
,
File
the file to write the autocompletion bash script source code to
out
,
File
the file to write a helper script to that invokes the command, or null if no helper script file should be written
command
,
CommandLine
the CommandLine instance for the command line application
commandLine
)

Generates source code for an autocompletion bash script for the specified picocli-based application, and writes this script to the specified out file, and optionally writes an invocation script to the specified command file.

public static String

Returns:

source code for an autocompletion bash script
bash
(String
the name of the command to generate a bash autocompletion script for
scriptName
,
CommandLine
the CommandLine instance for the command line application
commandLine
)

Generates and returns the source code for an autocompletion bash script for the specified picocli-based application.

private static String
public static int
complete(CommandLine.Model.CommandSpec spec, String[] args, int argIndex, int positionInArg, int cursor, List<CharSequence> candidates)

private static String
concat(String infix, String... values)

private static String
concat(String infix, List<String> values)

private static <V, T extends V> String
concat(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 List<String>
extract(Iterable<String> generator)

private static <K, T extends K> List<T>
filter(List<T> list, AutoComplete.Predicate<K> filter)

private static void
private static CommandLine.Model.CommandSpec
private static CommandLine.Model.CommandSpec
private static CommandLine.Model.CommandSpec
private static Object
private static void
private static void
private static String
private static void
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
private static String
private static void
private static boolean
public static void
main(String...
command line options. Specify at least the commandLineFQCN 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.
args
)

Generates a bash completion script for the specified command class.

private static <T> AutoComplete.Predicate<T>
negate(final AutoComplete.Predicate<T> original)

private static String
private static String
private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EXIT_CODE_COMMAND_SCRIPT_EXISTSback to summary
public static final int EXIT_CODE_COMMAND_SCRIPT_EXISTS

Exit code of this application when the specified command script exists (2).

EXIT_CODE_COMPLETION_SCRIPT_EXISTSback to summary
public static final int EXIT_CODE_COMPLETION_SCRIPT_EXISTS

Exit code of this application when the specified completion script exists (3).

EXIT_CODE_EXECUTION_ERRORback to summary
public static final int EXIT_CODE_EXECUTION_ERROR

Exit code of this application when an exception was encountered during operation (4).

EXIT_CODE_INVALID_INPUTback to summary
public static final int EXIT_CODE_INVALID_INPUT

Exit code of this application when the specified command line arguments are invalid (1).

EXIT_CODE_SUCCESSback to summary
public static final int EXIT_CODE_SUCCESS

Normal exit code of this application (0).

SCRIPT_HEADERback to summary
private static final String SCRIPT_HEADER

Constructor Detail

AutoCompleteback to summary
private AutoComplete()

Method Detail

addCandidatesForArgsFollowingback to summary
private static void addCandidatesForArgsFollowing(Object obj, List<CharSequence> candidates)
addCandidatesForArgsFollowingback to summary
private static void addCandidatesForArgsFollowing(CommandLine.Model.CommandSpec commandSpec, List<CharSequence> candidates)
addCandidatesForArgsFollowingback to summary
private static void addCandidatesForArgsFollowing(CommandLine.Model.OptionSpec optionSpec, List<CharSequence> candidates)
addCandidatesForArgsFollowingback to summary
private static void addCandidatesForArgsFollowing(CommandLine.Model.PositionalParamSpec positionalSpec, List<CharSequence> candidates)
addCompletionCandidatesback to summary
private static void addCompletionCandidates(Iterable<String> completionCandidates, List<CharSequence> candidates)
bashback to summary
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 specified out file, and optionally writes an invocation script to the specified command file.

Parameters
scriptName:String

the name of the command to generate a bash autocompletion script for

out:File

the file to write the autocompletion bash script source code to

command:File

the file to write a helper script to that invokes the command, or null if no helper script file should be written

commandLine:CommandLine

the CommandLine instance for the command line application

Exceptions
IOException:
if a problem occurred writing to the specified files
bashback to summary
public static String bash(String scriptName, CommandLine commandLine)

Generates and returns the source code for an autocompletion bash script for the specified picocli-based application.

Parameters
scriptName:String

the name of the command to generate a bash autocompletion script for

commandLine:CommandLine

the CommandLine instance for the command line application

Returns:String

source code for an autocompletion bash script

bashifyback to summary
private static String bashify(CharSequence value)
completeback to summary
public static int complete(CommandLine.Model.CommandSpec spec, String[] args, int argIndex, int positionInArg, int cursor, List<CharSequence> candidates)
concatback to summary
private static String concat(String infix, String... values)
concatback to summary
private static String concat(String infix, List<String> values)
concatback to summary
private static <V, T extends V> String concat(String infix, List<T> values, T lastValue, AutoComplete.Function<V, String> normalize)
createHierarchyback to summary
private static List<AutoComplete.CommandDescriptor> createHierarchy(String scriptName, CommandLine commandLine)
createSubHierarchyback to summary
private static void createSubHierarchy(String scriptName, String parentWithoutTopLevelCommand, CommandLine commandLine, List<AutoComplete.CommandDescriptor> out)
exitOnErrorback to summary
private static boolean exitOnError()
exitOnSuccessback to summary
private static boolean exitOnSuccess()
extractback to summary
private static List<String> extract(Iterable<String> generator)
filterback to summary
private static <K, T extends K> List<T> filter(List<T> list, AutoComplete.Predicate<K> filter)
filterAndTrimMatchingPrefixback to summary
private static void filterAndTrimMatchingPrefix(String prefix, List<CharSequence> candidates)
findCommandForback to summary
private static CommandLine.Model.CommandSpec findCommandFor(CommandLine.Model.ArgSpec arg, CommandLine.Model.CommandSpec cmd)
findCommandForback to summary
private static CommandLine.Model.CommandSpec findCommandFor(CommandLine.Model.OptionSpec option, CommandLine.Model.CommandSpec commandSpec)
findCommandForback to summary
private static CommandLine.Model.CommandSpec findCommandFor(CommandLine.Model.PositionalParamSpec positional, CommandLine.Model.CommandSpec commandSpec)
findCompletionStartPointback to summary
private static Object findCompletionStartPoint(CommandLine.ParseResult parseResult)
generateCompletionCandidatesback to summary
private static void generateCompletionCandidates(StringBuilder buff, CommandLine.Model.OptionSpec f)
generatedEdgeCaseFunctionCallsback to summary
private static void generatedEdgeCaseFunctionCalls(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy)
generateEntryPointFunctionback to summary
private static String generateEntryPointFunction(String scriptName, CommandLine commandLine, List<AutoComplete.CommandDescriptor> hierarchy)
generateFunctionCallsToArrContainsback to summary
private static void generateFunctionCallsToArrContains(StringBuilder buff, List<AutoComplete.CommandDescriptor> hierarchy)
generateFunctionForCommandback to summary
private static String generateFunctionForCommand(String functionName, String commandName, CommandLine commandLine)
generateOptionsCasesback to summary
private static String generateOptionsCases(List<CommandLine.Model.OptionSpec> argOptionFields, String indent, String currWord)
generateOptionsSwitchback to summary
private static String generateOptionsSwitch(List<CommandLine.Model.OptionSpec> argOptions)
generatePositionalParamsCasesback to summary
private static String generatePositionalParamsCases(List<CommandLine.Model.PositionalParamSpec> posParams, String indent, String currWord)
generatePositionParamCompletionCandidatesback to summary
private static void generatePositionParamCompletionCandidates(StringBuilder buff, CommandLine.Model.PositionalParamSpec f)
isPicocliModelObjectback to summary
private static boolean isPicocliModelObject(Object obj)
mainback to summary
public static void main(String... args)

Generates a bash completion script for the specified command class.

Parameters
args:String[]

command line options. Specify at least the commandLineFQCN 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.

negateback to summary
private static <T> AutoComplete.Predicate<T> negate(final AutoComplete.Predicate<T> original)
optionNamesback to summary
private static String optionNames(List<CommandLine.Model.OptionSpec> options)
sanitizeScriptNameback to summary
private static String sanitizeScriptName(String scriptName)
syspropDefinedAndNotFalseback to summary
private static boolean syspropDefinedAndNotFalse(String key)
picocli back to summary

private Class AutoComplete.App

extends Object
implements Callable<Integer>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Annotations
@Command
name:AutoComplete
mixinStandardHelpOptions:true
showAtFileInUsageHelp:true
version:picocli.AutoComplete 4.7.5
sortOptions:false
description:Generates a bash completion script for the specified command class.
footerHeading:%n@|bold System Properties:|@%n
footer:Set the following system properties to control the exit code of this program:, , * `"@|yellow picocli.autocomplete.systemExitOnSuccess|@"`, call `System.exit(0)` when execution completes normally., * `"@|yellow picocli.autocomplete.systemExitOnError|@"`, call `System.exit(ERROR_CODE)` when an error occurs., , If these system properties are not defined or have value "false", this program completes without terminating the JVM., , Example, -------, java -cp "myapp.jar;picocli-4.7.5.jar" \\, picocli.AutoComplete my.pkg.MyClass
exitCodeListHeading:%nExit Codes:%n
exitCodeList:0:Successful program execution, 1:Usage error: user input for the command was incorrect, e.g., the wrong number of arguments, a bad flag, a bad syntax in a parameter, etc., 2:The specified command script exists (Specify `--force` to overwrite)., 3:The specified completion script exists (Specify `--force` to overwrite)., 4:An exception occurred while generating the completion script.
exitCodeOnInvalidInput:1
exitCodeOnExecutionException:4

CLI command class for generating completion script.

Field Summary

Modifier and TypeField and Description
pack-priv File
pack-priv String
pack-priv String
pack-priv String
pack-priv boolean
pack-priv CommandLine.Model.CommandSpec
pack-priv boolean

Constructor Summary

AccessConstructor and Description
private
App()

Method Summary

Modifier and TypeMethod and Description
public Integer
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.
private boolean
checkExists(final File file)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoCompleteScriptback to summary
pack-priv File autoCompleteScript
Annotations
@Option
names:-o, --completionScript
description:Optionally specify the path of the completion script file to generate. When omitted, a file named \'_completion\' is generated in the current directory.
commandLineFQCNback to summary
pack-priv String commandLineFQCN
Annotations
@Parameters
arity:1
description:Fully qualified class name of the annotated `@Command` class to generate a completion script for.
commandNameback to summary
pack-priv String commandName
Annotations
@Option
names:-n, --name
description:Optionally specify the name of the command to create a completion script for. When omitted, the annotated class `@Command(name = "...")` attribute is used. If no `@Command(name = ...)` attribute exists, \'\' (in lower-case) is used.
factoryClassback to summary
pack-priv String factoryClass
Annotations
@Option
names:-c, --factory
description:Optionally specify the fully qualified class name of the custom factory to use to instantiate the command class. When omitted, the default picocli factory is used.
overwriteIfExistsback to summary
pack-priv boolean overwriteIfExists
Annotations
@Option
names:-f, --force
description:Overwrite existing script files.
specback to summary
pack-priv CommandLine.Model.CommandSpec spec
Annotations
@Spec
writeCommandScriptback to summary
pack-priv boolean writeCommandScript
Annotations
@Option
names:-w, --writeCommandScript
description:Write a \'\' sample command script to the same directory as the completion script.

Constructor Detail

Appback to summary
private App()

Method Detail

callback to summary
public Integer call() throws Exception

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:Integer

computed result

Exceptions
Exception:
if unable to compute a result
checkExistsback to summary
private boolean checkExists(final File file)
picocli back to summary

private Class AutoComplete.Bashify

extends Object
implements AutoComplete.Function<CharSequence, String>
Class Inheritance
All Implemented Interfaces
picocli.AutoComplete.Function

Drops all characters that are not valid for bash function and identifier names.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Bashifyback to summary
private Bashify()

Method Detail

applyback to summary
public String apply(CharSequence value)

Implements picocli.AutoComplete.Function.apply.

picocli back to summary

private Class AutoComplete.BooleanArgFilter

extends Object
implements AutoComplete.Predicate<CommandLine.Model.ArgSpec>
Class Inheritance
All Implemented Interfaces
picocli.AutoComplete.Predicate

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BooleanArgFilterback to summary
private BooleanArgFilter()

Method Detail

testback to summary
public boolean test(CommandLine.Model.ArgSpec f)

Implements picocli.AutoComplete.Predicate.test.

picocli back to summary

private Class AutoComplete.CommandDescriptor

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final CommandLine
pack-priv final String
pack-priv final String
pack-priv final String
pack-priv final String

Constructor Summary

AccessConstructor and Description
pack-priv
CommandDescriptor(String functionName, String parentFunctionName, String parentWithoutTopLevelCommand, String commandName, CommandLine commandLine)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

commandLineback to summary
pack-priv final CommandLine commandLine
commandNameback to summary
pack-priv final String commandName
functionNameback to summary
pack-priv final String functionName
parentFunctionNameback to summary
pack-priv final String parentFunctionName
parentWithoutTopLevelCommandback to summary
pack-priv final String parentWithoutTopLevelCommand

Constructor Detail

CommandDescriptorback to summary
pack-priv CommandDescriptor(String functionName, String parentFunctionName, String parentWithoutTopLevelCommand, String commandName, CommandLine commandLine)
picocli back to summary

private Interface AutoComplete.Function<T, V>

Known Direct Implementers
picocli.AutoComplete.Bashify, picocli.AutoComplete.NullFunction

Method Summary

Modifier and TypeMethod and Description
public V
apply(T t)

Method Detail

applyback to summary
public V apply(T t)
picocli back to summary

public Class AutoComplete.GenerateCompletion

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Annotations
@Command
name:generate-completion
version:generate-completion 4.7.5
mixinStandardHelpOptions:true
description:Generate bash/zsh completion script for ${ROOT-COMMAND-NAME:-the root command of this command}., Run the following command to give `${ROOT-COMMAND-NAME:-$PARENTCOMMAND}` TAB completion in the current shell:, , source <(${PARENT-COMMAND-FULL-NAME:-$PARENTCOMMAND} ${COMMAND-NAME}),
optionListHeading:Options:%n
helpCommand:true

Command that generates a Bash/ZSH completion script for its top-level command.

This class can be used as a subcommand for the top-level command in your application. Users can then install completion for the top-level command by running the following command:

source <(top-level-command [sub-command] generate-completion)
Since
4.1

Field Summary

Modifier and TypeField and Description
pack-priv CommandLine.Model.CommandSpec

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

specback to summary
pack-priv CommandLine.Model.CommandSpec spec
Annotations
@Spec

Constructor Detail

GenerateCompletionback to summary
public GenerateCompletion()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

picocli back to summary

private Class AutoComplete.NullFunction

extends Object
implements AutoComplete.Function<CharSequence, String>
Class Inheritance
All Implemented Interfaces
picocli.AutoComplete.Function

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NullFunctionback to summary
private NullFunction()

Method Detail

applyback to summary
public String apply(CharSequence value)

Implements picocli.AutoComplete.Function.apply.

picocli back to summary

private Interface AutoComplete.Predicate<T>

Known Direct Implementers
picocli.AutoComplete.BooleanArgFilter

Method Summary

Modifier and TypeMethod and Description
public boolean
test(T t)

Method Detail

testback to summary
public boolean test(T t)