Expand description
Utility for simple and declarative style command line argument parsing.
easy-args is meant to be used to set up simple command-line argumenst for your applications and give them back in an easy to process way.
§Getting Started
// 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.
use easy_args::{arg_spec, ArgSpec};
let spec = ArgSpec::build()
.boolean("fullscreen")
.uinteger_array(2, "size")
.done()
.unwrap();
// 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().unwrap();
if args.boolean("fullscreen") == Some(&true) {
// Put application into windowed mode
}
And that’s it! The arguments have been parsed and processed and can be
accessed via Args
’s getter methods.
ArgSpec
also has a [parse()
] method so you don’t have to make a
throwaway variable.
use easy_args::ArgSpec;
let args = ArgSpec::build()
.boolean("windowed")
.string("mode")
.parse()
.unwrap();
Macros§
Structs§
- ArgSpec
- Specifies the valid arguments of the program and is used to parse
the command-line arguments into an [
Arg
]. - ArgSpec
Builder - Builder type for
ArgSpec
. - Args
- Holds all the command-line arguments given by the user.
Enums§
- ArgType
- Enumerates all data types that are handled by
ArgSpec::parse()
. - Error
- The error types for argument parsing.