44 lines
981 B
Rust
44 lines
981 B
Rust
|
use std::ffi::OsString;
|
||
|
|
||
|
use lexopt::prelude::*;
|
||
|
|
||
|
#[derive(Debug, Default)]
|
||
|
pub struct Args {
|
||
|
version: bool,
|
||
|
clear_screen: bool,
|
||
|
foreground: Option<OsString>,
|
||
|
autodecrypt: bool,
|
||
|
mask_blanks: bool,
|
||
|
}
|
||
|
|
||
|
pub fn parse_arguments() -> Result<Args, lexopt::Error> {
|
||
|
let mut parser = lexopt::Parser::from_env();
|
||
|
|
||
|
let mut args = Args::default();
|
||
|
|
||
|
while let Some(arg) = parser.next()? {
|
||
|
match arg {
|
||
|
Short('a') => {
|
||
|
args.autodecrypt = true;
|
||
|
}
|
||
|
Short('c') => {
|
||
|
args.clear_screen = true;
|
||
|
}
|
||
|
Short('f') => {
|
||
|
let foreground = parser.value()?;
|
||
|
args.foreground = Some(foreground);
|
||
|
}
|
||
|
Short('s') => {
|
||
|
args.mask_blanks = true;
|
||
|
}
|
||
|
Short('v') => {
|
||
|
args.version = true;
|
||
|
}
|
||
|
_ => return Err(arg.unexpected()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Ok(args)
|
||
|
}
|
||
|
|