my_cli

Crates.iomy_cli
lib.rsmy_cli
version0.1.5
created_at2025-01-30 17:11:31.249377+00
updated_at2025-01-31 19:09:56.781818+00
descriptionA simple cli library inspired by Clap builder.
homepage
repositoryhttps://github.com/MarcosAndradeV/my_cli
max_upload_size
id1536608
size12,929
MarcosA (MarcosAndradeV)

documentation

README

MyCLI

A simple rust cli library inspired by clap builder.

Usage

$ cargo add my_cli

or

$ git clone git@github.com:MarcosAndradeV/my_cli.git # Just copy an paste into your project. :)

Example

use my_cli::*;

fn main() {
    let cl = MyCLI::create_from_args()
        .add_cmd("say", Cmd::new().arg("msg", 1)
            .help("prints the message.")
        )
        .add_cmd("sayTo",
            Cmd::new()
            .arg("msg", 1)
            .flag("-t", "NAME")
            .help("Prints the message to <NAME>.")
        );
    match cl.get_matches() {
        Some(("say", _, args)) => {
            if let Some(msg) = args.get("msg") {
                println!("You say: \"{msg}\"");
            } else {
                println!("Expected msg");
            }
        }
        Some(("sayTo", flags, args)) => {
            if let Some(msg) = args.get("msg") {
                if let Some(Some(name)) = flags.get("-t") {
                    println!("You say: \"{msg}\"\nTo: {name}");
                } else {
                    println!("You say: \"{msg}\"");
                }
            }
        }
        _ =>  cl.usage(),
    }
}


Commit count: 0

cargo fmt