Cli framework supports TAB key auto-complete

i’m looking for any cli framework supports tab key auto-completion feature. I looked at spf13/cobra and docker/docker-machine cli sample but they didn’t have the option for this feature.

for example, if I have 4 commands for App(show/set/start/status), when I type

“App s”

and then press TAB key, the cli can come back with 4 options

show
set
start
status

and if I continue type

“App stat”

and then press TAB key, the cli can auto fill in “status” word. Another nice feature is that I can use “App stat” directly with the next sub-command without fully typing/finishing “Status” word.

this kind of behavior is popular for network device cli like Cisco IOS/NX-OS.

any pointers?

Thanks
Hongjun

If you mean tab completion from a shell like bash, cobra can generate the completion files: https://github.com/spf13/cobra/blob/master/bash_completions.md

If you mean tab completion inside your program (e.g., a custom application shell) then try https://github.com/abiosoft/ishell or its underlying library https://github.com/chzyer/readline

1 Like

thanks for the info!

Try alecthomas/kingpin

will do. it does look very simple.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.