3 unstable releases

0.2.0 Dec 22, 2023
0.1.1 Dec 22, 2023
0.1.0 Dec 22, 2023

#12 in #command-runner

Download history 7/week @ 2023-12-22 16/week @ 2024-02-23 6/week @ 2024-03-01 4/week @ 2024-03-08 1/week @ 2024-03-15 8/week @ 2024-03-22 97/week @ 2024-03-29

110 downloads per month

MIT license

9KB
181 lines

Subcommand

Subcommand it's library taht lets you easily add subcommand.

Usage

use std::env;
use subcommands::command::{ Commands, CommandRunner,CommandResult};

fn print_next(args: Vec<String>) -> CommandResult {
    if args.len() < 1 {
        return Err("Not enough arguments".into());
    }
    for arg in args {
        println!("{}", arg);
    }
    Ok(0)
}

fn main() {
    let args: Vec<String> = env::args().collect();
    let mut commands = Commands::new(args);
    commands.create("cmd1", "Description 1", |args| {
            println!("Command 1 executed with args: {:?}", args);
            Ok(0)
      });

    commands.create("cmd2", "Description 2", |args| {
            println!("Command 2 executed with args: {:?}", args);
            Ok(0)
      });
    commands.create("print", "Print next word in new line",print_next);
    commands.run();
}

No runtime deps