jline多参数解析
我试图让 JLine 进行制表符补全,以便我可以输入类似以下内容:
commandname --arg1 value1 --arg2 value2
我正在使用以下代码:
final List<Completor> completors = Arrays.asList(
new SimpleCompletor("commandname "),
new SimpleCompletor("--arg1"),
new SimpleCompletor("--arg2"),
new NullCompletor());
consoleReader.addCompletor(new ArgumentCompletor(completors));
但在我键入 value2 后,制表符补全停止。
(补充问题,我可以使用 jline 将 value1 验证为日期吗?)
I am trying to get JLine to do tab completion so I can enter something like the following:
commandname --arg1 value1 --arg2 value2
I am using the following code:
final List<Completor> completors = Arrays.asList(
new SimpleCompletor("commandname "),
new SimpleCompletor("--arg1"),
new SimpleCompletor("--arg2"),
new NullCompletor());
consoleReader.addCompletor(new ArgumentCompletor(completors));
But after I type the value2 tab completion stops.
(Suplementary question, can I validate value1 as a date using jline?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,我通过创建自己的类来使用 jLine 完成命令来解决它。我只需要实现我自己的 Completor。
我正在开发一个应用程序,它不仅可以帮助 DBA 键入命令名称,还可以键入参数。我仅使用 jLine 进行终端交互,并创建了另一个 Completor。
我必须向 Completor 提供完整的语法,这就是我的应用程序的目标。它称为 Zemucan,托管在 SourceForge 中;该应用程序最初主要针对 DB2,但可以合并任何语法。我正在使用的 Completor 的示例是:
这是应用程序的摘录。您可以做一个简单的 Completor,并且必须提供一系列选项。最终,您将需要实现自己的 CompletionHandler 来改进向用户呈现选项的方式。
完整的代码可以此处。
I had the same problem, and I solved it by creating my own classes to complete the commands with jLine. I just needed to implement my own Completor.
I am developing an application that could assist DBAs to type not only the command names, but also the parameters. I am using jLine for just for the Terminal interactions, and I created another Completor.
I have to provide the complete grammar to the Completor, and that is the objective of my application. It is called Zemucan and it is hosted in SourceForge; this application is initially focused to DB2, but any grammar could be incorporated. The example of the Completor I am using is:
This is an extract of the application. You could do a simple Completor, and you have to provide an array of options. Eventually, you will want to implement your own CompletionHandler to improve the way that the options are presented to the user.
The complete code is available here.
创建 2 个完成器,然后使用它们来完成任意参数。请注意,并非所有参数都需要完成。
Create 2 completors, then use them to complete arbituary arguments. Note that not all the arguments need to be completed.
删除 NullCompletor,您将得到您想要的。 NullCompletor 确保您的整个命令只有 3 个单词长。
Remove the NullCompletor and you will have what you want. NullCompletor makes sure your entire command is only 3 words long.