parse: stat okay

master
Avril 4 years ago
parent 4894cf985e
commit 9310fa6834
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -23,7 +23,7 @@ pub fn usage() -> !
Usage: {program} [OPTIONS...] [-e|-d|-a] [-] [<files...>]
Usage: {program} --generate RSA [--input <old key>] [--input-password[=<password>]] [--password[=<password>]] [--format BIN|TEXT|PEM] <output> [<public part output>]
Usage: {program} --generate AES [--input <old key>] [--input-password[=<password>]] [--password[=<password>]] [--format BIN|TEXT] <output>
Usage: {program} --stat <key files...>
Usage: {program} --stat [-P=<password>] [-] [-p]<key files...>
Usage: {program} --help
- Stop reading argument flags:

@ -15,6 +15,7 @@ use error::ParseErrorKind;
mod normal;
mod generate;
mod stat;
#[derive(Debug, Hash, PartialEq, Eq)]
enum IsSigning
@ -166,7 +167,7 @@ pub async fn parse<I: IntoIterator<Item=String> + std::fmt::Debug>(args: I) -> R
handler
},
"--help" => return Ok(config::Operation::Help),
"--stat" => todo!(),
"--stat" => return Ok(config::Operation::KeyInfo(stat::parse_stat(args)?)),
_ => {
let handler = tokio::spawn(normal::handle(rx));
match normal::parse(std::iter::once(arg)

@ -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…
Cancel
Save