#shell #interactive #terminal #cli

nightly macro mysh_derive

Scaffolding to build interactive shells

2 releases

0.1.6 Jan 30, 2024
0.1.0 Jan 25, 2024

#201 in #interactive

32 downloads per month
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::macros::{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) -> Result<(), mysh::error::Error> {
  println!("Hello {}", args.name);
  Ok(())
}
use mysh::shell::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

~0.9–1.7MB
~37K SLoC