#cli #text #command-line #cmdr

cmdr

Cmdr is a library for building line-oriented text-based user interfaces

10 releases

✓ Uses Rust 2018 edition

new 0.3.3 Mar 24, 2019
0.3.2 Mar 22, 2019
0.2.1 Mar 2, 2019
0.1.3 Jan 26, 2019

#21 in #command-line

Download history 26/week @ 2018-12-30 13/week @ 2019-01-06 11/week @ 2019-01-13 5/week @ 2019-01-20 7/week @ 2019-01-27 5/week @ 2019-02-03 3/week @ 2019-02-10 7/week @ 2019-02-17 16/week @ 2019-02-24 17/week @ 2019-03-03 28/week @ 2019-03-10 37/week @ 2019-03-17

60 downloads per month

MIT/Apache

14KB
285 lines


lib.rs:

Cmdr is a library for building line-oriented text-based user interfaces.

This can be done by implementing one or more objects that implement the Cmdr::Scope trait. A command loop can then be started on a scope by calling the cmd_loop function. The command loop uses a line reader to get user input and executes them by running the appropriate functions on the supplied scope object.

Implementing a scope is as easy as creating an object with a few methods that take a vector of &str as their input and return a CommandResult. By annotating the impl block of that object the cmdr macro all functions starting annotated with #[cmd] in that block can be used as commands.

For additional functionality like setting custom prompts or setting hooks to catch unknown or empty commands additional methods can be added to the impl block. These correspond to overridable functions in the Scope trait.

Dependencies

~2.5MB
~45K SLoC