parent
4894cf985e
commit
9310fa6834
@ -0,0 +1,38 @@
|
||||
//! 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)
|
||||
}
|
Loading…
Reference in new issue