readline 帮助功能和自动完成
我愿意创建一个与 JUNOS cli 或 cisco cli 相同的项目,
我通过 gnu readline 来的,但我很困惑,因为有太多的功能和方法需要实现。无论如何,我想要一个带有自动完成功能的 cli,使用制表符和空格键以及问号来显示带有帮助文本的命令。
我有两个问题:
- 我在 python 和 perl 中找到了代码,但我不使用 python,该代码是完整的,我只是想知道我是否应该继续使用 python。我对 Perl 更有经验,但到目前为止我发现的 Perl 代码并不完整。
- readline.parse_and_bind('tab:complete')
我应该对帮助和自动完成功能使用相同的完整函数吗?因为我已经完成了另一个功能,
readline.set_completion_display_matches_hook(print_suggestions)
所以你建议:P 我对它完全陌生!
im willing to create a project same as JUNOS cli or cisco cli,
I came through gnu readline, but im confused as there are too many functions and methods to implement. any how i want a cli with auto complete using tab and space bar with question mark to display commands with help text.
I have two questions :
- I have found code in python and perl but the im not use to python that code is complete and i just want to know if i should continue with python. im more experienced in perl but the code i found so far isn't complete for perl.
readline.parse_and_bind('tab: complete')
should i use the same complete function for both help and autocomplete feature. where as i have gone through another function
readline.set_completion_display_matches_hook(print_suggestions)
what you suggest :P im completely new to it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须说,我很难理解您在问题中要解决的具体问题。但无论如何,这里有一个建议:
从 cmd 模块开始。它为您提供了一个很好的小框架来构建命令行解释器。它支持开箱即用的制表符完成(前提是 readline 可用)。开始实施您的命令行界面。一旦稳定下来,您就可以考虑添加更多舒适性,例如命令参数的制表符补全、帮助键等。这样,您就有了一个可以运行的应用程序来处理,并且可以在您真正需要时更具体地处理 readline 详细信息。如果我处于你的立场,我不会预先费力地浏览整个 readline API。
I must say that I struggle to understand which specific point you are addressing in your question. But here is a suggestion anyway:
Start out with the cmd module. It gives you a nice little framework to build a command-line interpreter. It supports tab completion out of the box (provided readline is available). Start implementing your command-line interface. Once this stabilizes you can think about adding more comfort, e.g. tab completion for command arguments, help keys, and the like. This way, you have a working app to deal with, and can address readline details more specifically when you really need them. I wouldn't wade through the whole readline API upfront, if I were in your shoes.
我们必须创建一个像 JunOS/Cisco/VyOS 这样的 cli,并且我们将其构建在 ishell 之上,ishell 使用 readline 来完成这项工作。
从项目页面:
您可以在 github 上查看该项目: https://github.com/italorossi/ishell
Cisco 示例:
PS:我是作者:)。
We had to create a cli like JunOS/Cisco/VyOS and we built it on top of ishell, which uses readline for this job.
From the project page:
You can check the project at github: https://github.com/italorossi/ishell
Cisco example:
PS: I'm the author :).