Expand description
§Argyle
This crate contains an agnostic CLI argument parser for Unix platforms called Argue
. Unlike more robust libraries like clap, Argue
does not hold information about expected or required arguments; it merely parses the raw arguments (std::env::args_os
) into a consistent state so the implementor can query them as needed.
Post-processing is an exercise largely left to the implementing library to do in its own way, in its own time. Argue
exposes several methods for quickly querying the individual pieces of the set, but it can also be dereferenced to a slice or consumed into an owned vector for fully manual processing if desired.
Arguments are processed and held as bytes rather than (os)strings, again leaving the choice of later conversion entirely up to the implementor.
For simple applications, this agnostic approach can significantly reduce the overhead of processing CLI arguments, but because handling is left to the implementing library, it might be too tedious or limiting for more complex use cases.
§Example
A general setup might look something like the following. Refer to the documentation for Argue
for more information, caveats, etc.
use argyle::{
Argue,
ArgyleError,
FLAG_HELP,
FLAG_REQUIRED,
FLAG_VERSION,
};
fn main() {
if let Err(e) = _main() {
match(e) {
// A "-V" or "--version" flag was present.
ArgyleError::WantsVersion => {
println!("MyApp v{}", env!("CARGO_PKG_VERSION"));
},
// A "-h" or "--help" flag was present.
ArgyleError::WantsHelp => {
println!("Help stuff goes here...");
},
// An actual error!
e => {
eprintln!("{}", e);
std::process::exit(1);
},
}
}
}
fn _main() -> Result<(), ArgyleError> {
// Parse CLI arguments.
let args = Argue::new(FLAG_HELP | FLAG_REQUIRED | FLAG_VERSION)?;
// Pull the pieces you want.
let clean: bool = args.switch(b"--clean");
let prefix: Option<&[u8]> = args.option2(b"-p", b"--prefix");
Ok(())
}
Re-exports§
pub use keykind::KeyKind;
Structs§
- Argument
OsStr
Iterator. Argue
is an agnostic CLI argument parser. Unlike more robust libraries like clap,Argue
does not hold information about expected or required arguments; it merely parses the raw arguments into a consistent state so the implementor can query them as needed.- Option Values Iterator.
- Option Values (
OsStr
) Iterator.
Enums§
- Error Struct.
Constants§
- FLAG_DYNAMIC_HELP
dynamic-help
Flag: Check For Help Flag. - Flag: Check For Help Flag.
- Flag: Argument(s) Required.
- Flag: Expect Subcommand.
- Flag: Check For Version Flag.