Announcement Announcement Module
Collapse
No announcement yet.
Custom Converter for roo addon commands Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Converter for roo addon commands

    Hello everybody,

    I am trying to build a roo add-on, and one of the commands should accept a special parameter. It is special in the sense that I want to choose from a generated list of items (not enum, because enum is static). The command would look like:

    @CliCommand(value = "say hello", help = "Prints welcome message to the Roo shell")
    public void sayHello(
    @CliOption(key = "playlist") PlayList something)

    where PlayList is my custom class.
    I have created a PlayListConverter in my add-on, but roo simply ignores it.

    My question is how can I register this converter, or how can I make my command see my custom list?

    Hope that there is somebody that knows and could share this information, because I was not able to find any useful information on the internet.

    All the best,
    Radu

  • #2
    Not sure Roo can do this, since Roo add-ons aren't running in Spring, they are running in straight OSGi under Felix. Also, unless that list is super quick to generate, it has to be evaluated when you hit TAB so you may slow down your shell for every time you hit tab.

    Suggestions (assuming you have a command like this):

    play --playlist A|B|C|D|E

    1. Add a list playlists command which emits valid playlists:

    list playlists

    ONE, TWO, THREE

    2. Then the user can put in

    play --playlist ONE

    3. If the user enters an incorrect one (i.e. not one from the list) - prompt them to run 'list playlists' for a valid one.

    Originally posted by radu19 View Post
    Hello everybody,

    I am trying to build a roo add-on, and one of the commands should accept a special parameter. It is special in the sense that I want to choose from a generated list of items (not enum, because enum is static). The command would look like:

    @CliCommand(value = "say hello", help = "Prints welcome message to the Roo shell")
    public void sayHello(
    @CliOption(key = "playlist") PlayList something)

    where PlayList is my custom class.
    I have created a PlayListConverter in my add-on, but roo simply ignores it.

    My question is how can I register this converter, or how can I make my command see my custom list?

    Hope that there is somebody that knows and could share this information, because I was not able to find any useful information on the internet.

    All the best,
    Radu

    Comment


    • #3
      Hi krimple,

      Thank you for your answer, but I have to contradict you a bit. If you have a look at the CloudFoundry add-on, you will see that they are building a list dynamically. Also, the JavaType is also a dynamic list, as it enlarges and decreases when you add or remove jpa entities. They work kind of fast, I must say.

      However, in the meantime, I have found a solution. One must add the @Component and @Service annotations, thus the converter will get recognized.

      Nonetheless, now I have a different problem... Is there a way to check if the user has filled in one of the options of the command he 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, I want to make a check that he has already introduced and album. Is there any way to read the buffer string he has entered so far?

      Radu

      Comment


      • #4
        Contradictions welcome. I did say "think" - so I wasn't 100% sure.

        Glad you found an example like that. I'll dig into it as well. Shows what I know And if I thought about it any more, of course you can - any time you pass --class or --entity, it lets you fill that in from a list. So, ugh. My bad!

        Srini wrote that chapter. I've been over the code of the other add-ons but never dove into that one or I would have loved seeing it. Great examples in there, and I guess something to add to the add-ons presentation at SpringOne around command-line options etc...

        Just looking around but in JavaPackageConverter (in the classpath project of Roo) provides package completions and when you have multiple options places them below too. Each time you tab you'd send in a less or more complete field value. I don't know (but obviously my mileage may vary) about any System.in.read()-level calls. My quick search of the source didn't turn any up in an add-on.

        Ken
        Last edited by krimple; Sep 26th, 2012, 02:04 PM.

        Comment


        • #5
          Hi Ken!
          Thanks for getting involved. I have found a way, which I am describing below:

          In the MethodTarget class there is a method 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.

          That seems to be it.

          Comment


          • #6
            Even better. Sorry I wasn't of too much help, but at least this information is out there now.

            Comment

            Working...
            X