I'm currently trying to improve a Spring Shell application, and one of thing that would make it considerably better would be if it would support tab-completion for values as well as the options.
As an example, if my CLI had a command getInfo --name <name>, where <name> is a name from a finite set of names in the DB, it would be handy to be able to do
> getInfo --name Lu<tab>
Lucy Luke Lulu
> getInfo --name Luk<tab>
> getInfo --name Luke
Is there any way to do this using the existing Spring Shell tooling? I've had a poke around in the documentation and can't find anything about autocompleting values..
Cheers!
You can register a Converter to get this functionality to the String type. There are already a few already created converters and the org.springframework.shell.converters.EnumConverter has the functionality you are looking for.
To register a Converter you need to implement the org.springframework.shell.core.Converter interface:
In the previous example I've registered a converter for the String Object that it enables when the optionContext of the @CliOption Annotation has
enable-prop-converter.You also have to disable the default StringConverter. In the next line I disabled the default String converter in the @CliOption Annotation with
disable-string-converterand enabled the new PropertyConverter withenable-prop-converter.