#interactive #shell #terminal

nightly macro mysh_derive

Scaffolding to build interactive shells

2 releases

0.1.6 Jan 30, 2024
0.1.0 Jan 25, 2024

#221 in #interactive


Used in mysh

MIT license

9KB
188 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–2MB
~40K SLoC