readline 帮助功能和自动完成

发布于 2024-12-11 18:35:56 字数 499 浏览 0 评论 0原文

我愿意创建一个与 JUNOS cli 或 cisco cli 相同的项目,

我通过 gnu readline 来的,但我很困惑,因为有太多的功能和方法需要实现。无论如何,我想要一个带有自动完成功能的 cli,使用制表符和空格键以及问号来显示带有帮助文本的命令。

我有两个问题:

  1. 我在 python 和 perl 中找到了代码,但我不使用 python,该代码是完整的,我只是想知道我是否应该继续使用 python。我对 Perl 更有经验,但到目前为止我发现的 Perl 代码并不完整。
  2. 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 :

  1. 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.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陈年往事 2024-12-18 18:35:56

我必须说,我很难理解您在问题中要解决的具体问题。但无论如何,这里有一个建议:

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.

旧人哭 2024-12-18 18:35:56

我们必须创建一个像 JunOS/Cisco/VyOS 这样的 cli,并且我们将其构建在 ishell 之上,ishell 使用 readline 来完成这项工作。

从项目页面:

ishell 可帮助您轻松地为您的应用程序创建交互式 shell。它支持命令完成、动态参数、命令历史记录和命令链接。

您可以在 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:

ishell helps you to easily create an interactive shell for your application. It supports command completion, dynamic arguments, a command history, and chaining of commands.

You can check the project at github: https://github.com/italorossi/ishell

Cisco example:
enter image description here

PS: I'm the author :).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文