2023-07-23 03:04:59 -07:00
|
|
|
use std::ffi::OsString;
|
|
|
|
|
|
|
|
use lexopt::prelude::*;
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
2023-07-23 03:14:38 -07:00
|
|
|
pub(crate) struct Args {
|
|
|
|
pub(crate) version: bool,
|
|
|
|
pub(crate) clear_screen: bool,
|
|
|
|
pub(crate) foreground: Option<OsString>,
|
|
|
|
pub(crate) autodecrypt: bool,
|
|
|
|
pub(crate) mask_blanks: bool,
|
2023-07-23 03:04:59 -07:00
|
|
|
}
|
|
|
|
|
2023-07-23 03:14:38 -07:00
|
|
|
pub(crate) fn parse_arguments() -> Result<Args, lexopt::Error> {
|
2023-07-23 03:04:59 -07:00
|
|
|
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)
|
|
|
|
}
|