rusty-cmd
A crate for creating custom line-oriented command interpreters in Rust.
I wrote this as a Rust learning project and was inspired by Python's cmd and the dev.to article: A small library for writing line oriented-command interpreters in rust.
Features
- Create custom command interpreters.
- Easily define and execute commands.
- Implement optional command arguments.
- Redirect output to types that implement io::Write.
- Create teardown function by returing 0 from a command handler.
Overview
rusty-cmd provides two crates:
cmd
: Used for creating theCmd
struct that contains theCommandHandler
implementations in aHashMap
.command_handler
: Contains theCommandHandler
trait.
Example
use io;
use Write;
use ;
use Cmd;
use Quit;
/// CommandHandler that prints out help message
;
/// CommandHandler that emulates the basic bash touch command to create a new file
;
Usage
To use rusty-cmd in your project, add the following to your Cargo.toml
file:
[]
= "1.0.0"
Then import the crate in your Rust code:
use ;
use Cmd;
License
This project is licensed under the MIT License - see the LICENSE file for details.