Search code examples
javaspring-rooadd-on

How to obtain roo shell access programmatically?


I'm trying to create a roo add-on and thus some custom commands. Is there a way to check if the user has filled in one of the options of the command he/she is typing? For instance, the user is typing the command:

say hello --name MyName --album SomeAlbum --song 

Now, just when he is supposed to enter a song and he presses the TAB key, I want to make a check that he has already introduced an album. Is there any way to read the buffer string he/she has entered so far?

I suppose that I would need to access the current shell instance somehow, but so far I couldn't find any way.


Solution

  • In the MethodTarget class there is a method called getRemainingBuffer(), which returns the content of the current line entered in the console. An object of this type is one of the arguments of the getAllPossibleValues method which needs to be implemented in a converter, which is needed for custom types of commands.

    That seems to be it.