You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

//! Stat mode
use super::*;
pub fn parse_stat<I: IntoIterator<Item=String>>(args: I) -> Result<Vec<(String, Password)>, error::Error>
{
let mut args = args.into_iter();
let mut output = Vec::new();
let mut reading=true;
while let Some(arg) = args.next()
{
macro_rules! take_one {
($msg:literal $($tt:tt)*) => {
match args.next() {
Some(v) => v,
None => return Err((arg, ParseErrorKind::ExpectedArg(format!($msg $($tt)*))).into()),
}
}
}
if reading && arg.starts_with("-") {
match arg.trim() {
"-" => reading=false,
"-P" => {
let password = take_one!("-P: expected password string");
let key = take_one!("-P: expected key file");
output.push((key, Password::Specific(password)));
},
other if other.starts_with("-p") => {
output.push(((&other[2..]).to_owned(), Password::Yes));
},
_ => return Err((arg, ParseErrorKind::UnexpectedArg(None)).into()),
}
} else {
output.push((arg, Password::No));
}
}
Ok(output)
}