subcommands 0.2.0

Command pattern
Documentation
  • Coverage
  • 0%
    0 out of 19 items documented0 out of 9 items with examples
  • Size
  • Source code size: 8.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • SIGMazer/subcommand
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SIGMazer

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();
}