3 stable releases

2.0.2 Jun 6, 2024
0.1.4 Jun 3, 2024

#1942 in Command line utilities

Download history 6/week @ 2024-09-20 13/week @ 2024-09-27 2/week @ 2024-10-04 3/week @ 2024-10-11

215 downloads per month

MIT license

23KB
321 lines

Snap

Crates.io License

Need Help? Join the discord

Snap is a lightweight and efficient command-line argument handler, inspired by clap.

Features

  • Ease of Use: Simple and intuitive API for defining command-line arguments.
  • Performance: Optimized for fast argument parsing.
  • Customizability: Flexible configuration options to tailor argument parsing to your needs.
  • Error Handling: Comprehensive and user-friendly error messages.
  • Help Message Generation: Automatic generation of help and usage messages.

Installation

Add this to your Cargo.toml:

[dependencies]
snap = "2.0.2"

Usage Here's a simple example of how to use Snap:

use snap_cli::{app::App, arg::Arg, command::Command};

fn main() {
    let matches = App::new("myapp")
        .version("1.0")
        .author("Your Name <your@email.com>")
        .about("Does awesome things")
        .arg("<input> 'Sets the input file to use'")
        .arg("-v, --verbose 'Sets the level of verbosity'")
        .get_matches();

    if let Some(input) = matches.value_of("input") {
        println!("Using input file: {}", input);
    }

    if matches.is_present("verbose") {
        println!("Verbose mode is on");
    }
}

Examples

More detailed examples can be found in the examples directory.

use snap_cli::{app::App, arg::Arg, command::Command};

fn main() {
    let matches = App::new("myapp")
        .version("1.0")
        .author("Your Name <your@email.com>")
        .about("Does awesome things")
        .arg("<input> 'Sets the input file to use'")
        .arg("-v, --verbose 'Sets the level of verbosity'")
        .get_matches();

    if let Some(input) = matches.value_of("input") {
        println!("Using input file: {}", input);
    }

    if matches.is_present("verbose") {
        println!("Verbose mode is on");
    }
}

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License.

Dependencies

~245–710KB
~17K SLoC