8 releases

0.1.8 Dec 6, 2024
0.1.7 Dec 6, 2024
0.1.6 Jan 30, 2024

#852 in Command-line interface

Download history 10/week @ 2024-09-23 213/week @ 2024-12-02 40/week @ 2024-12-09

253 downloads per month

MIT license

23KB
667 lines

mysh-rs

mysh, short for "My Shell", is a rust library for quickly building small interactive shells.

Usage

[dependencies]
mysh = "0.1.1"
futures = "0.3"
use mysh::{command, CommandArg};
use serde::Deserialize;

#[derive(CommandArg, Deserialize, Clone)]
pub struct Args {
  name: String,
}

#[command(
  name = "hello",
  description = "Prints hello world",
  long_description = "Prints hello world" // optional
)]
pub async fn hello(_: UserInfo, args: Args) -> mysh::Result<()> {
  println!("Hello {}", args.name);
  Ok(())
}
use mysh::Shell;
use tokio;

#[derive(Clone)]
pub struct UserInfo {}

// #[tokio::main] // or
#[actix_rt::main]
async fn main() {
  Shell::new(UserInfo {})
    .add_command(hello)
    .run()
    .await;
}

Trigger read-eval-print-loop

cargo run

>> hello --name World
Hello World

Run single command

cargo run -- hello --name World
Hello World

Run Examples

cargo run -p simple

Dependencies

~9–19MB
~293K SLoC