Crates.io | easy-args |
lib.rs | easy-args |
version | 0.3.0 |
source | src |
created_at | 2021-06-12 18:40:29.303831 |
updated_at | 2021-06-15 07:47:55.28698 |
description | A small and lightweight library that helps with parsing command line arguments |
homepage | |
repository | |
max_upload_size | |
id | 409386 |
size | 29,638 |
A Rust library for simple and lightweight command-line argument parsing, with:
ArgSpec
,It's also worth pointing out what easy-args
is not:
Documentation:
Add this to your Cargo.toml
:
[dependencies]
easy-args = "0.3.0"
To get started using easy-args.
First you must define an ArgSpec
which will determine what the command-line
arguments are for your program and will be used by the parser to do some
simple checks.
You make an ArgSpec
with the builder pattern.
let spec = ArgSpec::build()
.boolean("fullscreen")
.uinteger_array(2, "size")
.done()?;
There is an arg_spec!
macro which provides a nicer syntax.
let spec = arg_spec! {
fullscreen: bool,
size: [u64; 2],
};
Second you call ArgSpecs
's parse()
method to retrieve the command-line
arguments in a processed form.
let args = spec.parse()?;
if args.boolean("fullscreen") == Some(&true) {
// Put application into fullscreen
}
And that's it! The arguments have been parsed and processed and can be
accessed via Args
's getter methods.
ArgSpecBuilder
also has a parse()
method so you don't have to make a
throwaway variable.
let args = ArgSpec::build()
.boolean("fullscreen")
.uinteger_array(2, "size")
.parse()
.unwrap();
easy-args is an immature crate and as such may make breaking changes in future versions.
Current easy-args versions are:
unsigned_integer
methods to uinteger
and added error checking for
to building ArgSpec
's.arg_spec!
macro to provide a nicer syntax for ArgSpec
building.f64
and [f64]
arguments now supported.easy-args is distributed under the terms of the MIT license.