开发者

Inspiration on how to build a great command line interface

I am in the process of building interactive front-ends to a distributed applicat开发者_运维知识库ion which to date has been used to run workloads that had a batch-job like structures and needed no UI at all. The application is mostly written in Perl and C and runs on a mix of Unix and Windows machines, but I think this isn't relevant to the UI.

The first such frontend is going have a command-line user interface -- currently, I envision something similar to the CLIs of the Procurve switches and Cisco routers that I have worked with.

Like modern network gear CLIs, commands are going to resemble simple sentences, (i.e. show vlans ports 1-4) and the CLI will have some implicit state, much in the way that Unix shells and cmd.exe in Windows have environment variables and current working directories. Moreover, I'd like to implement great tab completion that is aware of the application's state as much as possible and I want to be able to do that with as little application-specific code as possible.

The low-level functionality (terminal I/O) seems easy to implement on top of GNU Readline or similar libraries, but that's only where the real fun starts. So far I have looked at the Perl modules Term::Shell and Term::ShellUI, but I'm not convinced that I want to use either of them. I am still considering rolling my own solution and at the moment I am primarily looking for inspiration.

Can you recommend any application or library, regardless of implementation language, that implements a good CLI from which I can borrow ideas?


I suggest you take a look at the philosophy underlying Microsoft PowerShell. From the idea of piping typed objects between commands to the consistency of its commands and argument syntax, I think it can be a source of inspiration.


You could try having a look at libcli :

"Libcli provides a shared library for including a Cisco-like command-line interface into other software."

http://code.google.com/p/libcli/

BTW - I forgot to mention that it is GNU Lesser GPL and actually used by Cisco in some products.


As for your last sentence/question, I'm particularly fond of zsh completion and line editing (zle).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜