Crates.io | blarg |
lib.rs | blarg |
version | 1.0.4 |
source | src |
created_at | 2022-11-20 00:06:02.23216 |
updated_at | 2023-12-04 14:54:01.094044 |
description | A type-safe, domain sensitive, argument/option paradigm command line parser. |
homepage | |
repository | https://github.com/sawatzkylindsey/blarg |
max_upload_size | |
id | 718758 |
size | 71,656 |
blarg
is a command line argument parser for Rust.
In brief, it provides type-safe, domain sensitive, argument/option paradigm command line parser functionality.
Check out the rustdoc for more information.
"blarg" is derived from the following:
use blarg::{derive::*, CommandLineParser, Parameter, Scalar, Switch};
#[derive(Debug, Default, BlargParser)]
#[blarg(program = "example")]
struct Parameters {
#[blarg(short = 'v')]
verbose: bool,
value: u32,
}
fn main() {
let parameters = Parameters::blarg_parse();
println!(
"value: {}, verbose: {}",
parameters.value, parameters.verbose
);
}
$ ./main -h
usage: example [-h] [-v] VALUE
positional arguments:
VALUE type: u32
options:
-h, --help Show this help message and exit.
-v, --verbose
use blarg::{CommandLineParser, Parameter, Scalar, Switch};
fn main() {
let mut verbose: bool = false;
let mut value: u32 = 0;
let ap = CommandLineParser::new("example");
let parser = ap
.add(Parameter::option(
Switch::new(&mut verbose, true),
"verbose",
Some('v'),
))
.add(Parameter::argument(Scalar::new(&mut value), "value").meta(vec!["type: u32"]))
.build();
parser.parse();
println!("value: {value}, verbose: {verbose}");
}
$ ./main -h
usage: example [-h] [-v] VALUE
positional arguments:
VALUE type: u32
options:
-h, --help Show this help message and exit.
-v, --verbose
cargo build --workspace
cargo test --workspace
cargo doc --open --no-deps --all-features --package blarg
./target/debug/examples/reducer -h