no-more-secrets-rust/src/args.rs
2023-07-23 20:16:58 -07:00

56 lines
1.6 KiB
Rust

use std::ffi::OsString;
use lexopt::prelude::*;
#[derive(Debug, Default)]
pub(crate) struct Args {
pub(crate) version: bool,
pub(crate) clear_screen: bool,
///Pass the 'color' argument to the nmstermio module where it will set the
///foreground color of the unencrypted characters as they are
///revealed. Valid arguments are "white", "yellow", "magenta", "blue",
///"green", "red", and "cyan".
pub(crate) foreground: Option<OsString>,
/// Set the autoDecrypt flag according to the true/false value of the
/// 'setting' argument. When set to true, nmseffect_exec() will not
/// require a key press to start the decryption effect.
pub(crate) autodecrypt: bool,
/// Set the maskBlank flag according to the true/false value of the
/// 'setting' argument. When set to true, blank spaces characters
/// will be masked as well.
pub(crate) mask_blanks: bool,
}
pub(crate) 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)
}