Search code examples
javascalajlinejline3

Obtaining the collection of jline3 commands from a TreeCompleter


I have a TreeCompleter (Scala code) which works as expected:

val treeCompleter = new TreeCompleter(
    node("bindkey"),
    node("cls"),
    node(
      "custom",
      node("Option1", node("Param1", "Param2")),
      node("Option2"),
      node("Option3")
    ),
    node("help"),
    node("set"),
    node("testkey"),
    node("tput")
)

How can I obtain the collection of command names? For this example, those names are: bindkey, cls, custom, help, set, testkey and tput.

The github project that contains the above code is here: https://github.com/mslinn/jline-example/blob/master/src/main/scala/CliLoop.scala

I don't care if the answer is in Java or Scala, thanks!


Solution

  • I don't think it is possible this way given that TreeCompleter is just a wrapper around RegexCompleter that actually does the job. So if you want to gather this information, you should do it before you pass your nodes to the TreeCompleter constructor or probably before you create TreeCompleter.Node instances because they seem to provide no public accessors. One obvious solution would be to create your own wrapper around TreeCompleter with your own inner Node class that would store this information for later usage.