user1012397
user1012397

Reputation: 19

readline help feature & autocomplete

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!

Upvotes: 0

Views: 1237

Answers (2)

Italo Rossi
Italo Rossi

Reputation: 68

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 :).

Upvotes: 1

ThomasH
ThomasH

Reputation: 23536

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.

Upvotes: 1

Related Questions