use crate::Execute;
use alloc::{string::String, vec::Vec};
use bon::Builder;
pub trait Adapter<T>: Execute<T> {}
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Builder)]
#[builder(derive(Debug), on(String, into))]
pub struct AdapterOptions {
#[builder(field)]
pub other: Vec<String>,
pub output: Option<String>,
}
impl<S: adapter_options_builder::State> AdapterOptionsBuilder<S> {
pub fn other(mut self, flag: impl Into<String>) -> Self {
self.other.push(flag.into());
self
}
pub fn maybe_other(mut self, flag: Option<impl Into<String>>) -> Self {
if let Some(flag) = flag {
self.other.push(flag.into());
}
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn optional_arguments_preserve_order_and_boundaries() {
let options = AdapterOptions::builder()
.other("--dataset")
.maybe_other(Some("value with spaces"))
.maybe_other(None::<&str>)
.other("query.rq")
.build();
assert_eq!(
options.other,
["--dataset", "value with spaces", "query.rq"]
);
}
}