|
|
@ -3,7 +3,7 @@ use super::*;
|
|
|
|
use tokio::sync::mpsc::Receiver;
|
|
|
|
use tokio::sync::mpsc::Receiver;
|
|
|
|
use std::collections::HashSet;
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
|
|
|
|
|
|
|
#[instrument]
|
|
|
|
#[instrument(level="trace", err, skip(rx))]
|
|
|
|
pub(super) async fn handle(mut rx: Receiver<Atom>) -> Result<config::Operation, error::ConstructError>
|
|
|
|
pub(super) async fn handle(mut rx: Receiver<Atom>) -> Result<config::Operation, error::ConstructError>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut had = smallmap::Map::new();
|
|
|
|
let mut had = smallmap::Map::new();
|
|
|
@ -37,7 +37,10 @@ pub(super) async fn handle(mut rx: Receiver<Atom>) -> Result<config::Operation,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut stage = Output{
|
|
|
|
let mut stage = Output{
|
|
|
|
kind: Some(match rx.recv().await.unwrap() {
|
|
|
|
kind: Some(match match rx.recv().await {
|
|
|
|
|
|
|
|
Some(val) => val,
|
|
|
|
|
|
|
|
None => return Err(error::ConstructError::Dropped),
|
|
|
|
|
|
|
|
} {
|
|
|
|
Atom::Generate(GenerateAtom::Type(ty)) => ty,
|
|
|
|
Atom::Generate(GenerateAtom::Type(ty)) => ty,
|
|
|
|
_ => invalidate!("First atom is not type."),
|
|
|
|
_ => invalidate!("First atom is not type."),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
@ -91,8 +94,8 @@ fn split<'a>(input: &'a str) -> (&'a str, Option<&'a str>)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[instrument(level="trace", skip(args, atoms))]
|
|
|
|
pub(super) async fn parse<I: IntoIterator<Item=String>>(args: I, atoms: &mut mpsc::Sender<Atom>) -> Result<(), error::Error>
|
|
|
|
pub(super) async fn parse<I: IntoIterator<Item=String>>(args: I, mut atoms: mpsc::Sender<Atom>) -> Result<(), error::Error>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut args = args.into_iter();
|
|
|
|
let mut args = args.into_iter();
|
|
|
|
let mut reading = true;
|
|
|
|
let mut reading = true;
|
|
|
@ -112,8 +115,9 @@ pub(super) async fn parse<I: IntoIterator<Item=String>>(args: I, atoms: &mut mps
|
|
|
|
_ => return Err(error::Error::ExpectedKind(arg)),
|
|
|
|
_ => return Err(error::Error::ExpectedKind(arg)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut had = HashSet::new();
|
|
|
|
|
|
|
|
let mut hadv = HashSet::new();
|
|
|
|
while let Some(arg) = args.next()
|
|
|
|
while let Some(arg) = args.next()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
macro_rules! take_one {
|
|
|
|
macro_rules! take_one {
|
|
|
@ -124,15 +128,12 @@ pub(super) async fn parse<I: IntoIterator<Item=String>>(args: I, atoms: &mut mps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut had = HashSet::new();
|
|
|
|
|
|
|
|
if reading && arg.starts_with("--") {
|
|
|
|
if reading && arg.starts_with("--") {
|
|
|
|
let (key, value) = split(&arg);
|
|
|
|
let (key, value) = split(&arg);
|
|
|
|
if had.contains(&key[..]) {
|
|
|
|
if !had.insert(key.to_owned()) {
|
|
|
|
return Err((error::ParseErrorKind::NotUniqueLong(Some(key.to_owned())), arg).swap().into());
|
|
|
|
return Err((error::ParseErrorKind::NotUniqueLong(Some(key.to_owned())), arg).swap().into());
|
|
|
|
} else {
|
|
|
|
|
|
|
|
had.insert(key.to_owned());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
match &key.to_lowercase().trim()[2..] {
|
|
|
|
match &key.to_lowercase().trim()[2..] {
|
|
|
|
"input" => send!(GenerateAtom::Input(take_one!("--input: Expected filename"))).await?,
|
|
|
|
"input" => send!(GenerateAtom::Input(take_one!("--input: Expected filename"))).await?,
|
|
|
|
"password" if value.is_some() => {
|
|
|
|
"password" if value.is_some() => {
|
|
|
@ -155,12 +156,12 @@ pub(super) async fn parse<I: IntoIterator<Item=String>>(args: I, atoms: &mut mps
|
|
|
|
})).await?,
|
|
|
|
})).await?,
|
|
|
|
_ => return Err((arg, error::ParseErrorKind::UnexpectedArg(None)).into()),
|
|
|
|
_ => return Err((arg, error::ParseErrorKind::UnexpectedArg(None)).into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if reading && arg == "-" {
|
|
|
|
|
|
|
|
reading= false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
if had.contains(&arg[..]) {
|
|
|
|
if !hadv.insert(arg.to_owned()) {
|
|
|
|
return Err((arg, error::ParseErrorKind::NotUniqueLong(None)).into());
|
|
|
|
return Err((arg, error::ParseErrorKind::NotUniqueLong(None)).into());
|
|
|
|
} else {
|
|
|
|
|
|
|
|
had.insert(arg.to_owned());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reading=false;
|
|
|
|
reading=false;
|
|
|
|
match sent_output
|
|
|
|
match sent_output
|
|
|
|