#shell #interactive #terminal #cli

nightly macro mysh_derive

Scaffolding to build interactive shells

3 releases

new 0.1.7 Dec 6, 2024
0.1.6 Jan 30, 2024
0.1.0 Jan 25, 2024

#218 in #interactive

Download history 9/week @ 2024-09-20 2/week @ 2024-09-27

151 downloads per month
Used in mysh

MIT license

11KB
233 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

~1–1.9MB
~39K SLoC