#[cfg(feature = "sarge")]
mod sarge;
macro_rules! impls_for {
(
$name:ident => $type:path
) => {
impl Deref for $name {
type Target = $type;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for $name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl From<$type> for $name {
fn from(inputs: $type) -> Self {
Self(inputs)
}
}
impl From<$name> for $type {
fn from(args: $name) -> Self {
args.0
}
}
};
}
#[derive(Debug, Clone, Default)]
pub struct InputArgs(Vec<String>);
impl InputArgs {
pub fn new() -> Self {
Self::default()
}
pub fn with_input(mut self, path: impl Into<String>) -> Self {
self.push(path.into());
self
}
pub fn is_stdin(&self) -> bool {
self.iter()
.any(|s| s == "-" || s.eq_ignore_ascii_case("stdin"))
}
}
#[derive(Debug, Clone, Default)]
pub struct OutputArgs(Vec<String>);
impl OutputArgs {
pub fn new() -> Self {
Self::default()
}
pub fn with_output(mut self, path: impl Into<String>) -> Self {
self.push(path.into());
self
}
pub fn is_stdout(&self) -> bool {
self.iter()
.any(|s| s == "-" || s.eq_ignore_ascii_case("stdout"))
}
pub fn is_stderr(&self) -> bool {
self.iter().any(|s| s.eq_ignore_ascii_case("stderr"))
}
}
impls_for!(InputArgs => Vec<String>);
impls_for!(OutputArgs => Vec<String>);
use std::ops::{Deref, DerefMut};
use crate::format::FormatKind;
pub fn parse_format(s: &str) -> Option<FormatKind> {
s.parse::<FormatKind>().ok()
}
pub fn infer_format_from_path(path: &str) -> Option<FormatKind> {
let ext = std::path::Path::new(path)
.extension()
.and_then(|e| e.to_str())?;
ext.parse::<FormatKind>().ok()
}