#[cfg(feature = "mkcws")]
#[derive(clap::Parser, Clone)]
pub struct Mkcws {
#[arg(long, short)]
directory: std::path::PathBuf,
#[arg(long, short)]
output_file: Option<std::path::PathBuf>,
}
#[cfg(feature = "mkcws")]
impl Mkcws {
pub fn main(&self) -> sysexits::Result<()> {
use crate::PatternWriter;
self.output_file.truncate(Box::new(
"{ \"folders\" : [ { \"path\" : \"".to_string()
+ &format!("{}", self.directory.display())
+ "\" } ] }\n",
))
}
pub fn new<T>(directory: T, output_file: Option<T>) -> Self
where
std::path::PathBuf: From<T>,
{
Self {
directory: std::path::PathBuf::from(directory),
output_file: output_file.map(Into::into),
}
}
}
#[cfg(feature = "rs2md")]
#[derive(clap::Parser, Clone)]
pub struct Rs2md {
#[arg(long = "inner")]
extract_inner: bool,
#[arg(long = "outer")]
extract_outer: bool,
#[arg(long = "input", short)]
input_file: Vec<std::path::PathBuf>,
#[arg(long = "output", short)]
output_file: Option<std::path::PathBuf>,
}
#[cfg(feature = "rs2md")]
impl Rs2md {
pub fn main(&self) -> sysexits::Result<()> {
use crate::PatternIOProcessor;
(|s: String| {
s.lines()
.map(str::trim_start)
.filter(|l| {
(self.extract_inner && l.starts_with("///"))
|| (self.extract_outer && l.starts_with("//!"))
})
.map(|l| {
if l.len() > 3 {
l.split_at(4).1.trim_end().to_string() + "\n"
} else {
"\n".to_string()
}
})
.collect::<String>()
})
.io(&self.input_file, &self.output_file)
}
pub fn new<T>(
input_file: Vec<T>,
output_file: Option<T>,
extract_inner: bool,
extract_outer: bool,
) -> Self
where
std::path::PathBuf: From<T>,
{
Self {
extract_inner,
extract_outer,
input_file: {
let mut i = Vec::new();
for file in input_file {
i.push(file.into());
}
i
},
output_file: output_file.map(Into::into),
}
}
}
#[cfg(feature = "uncrlf")]
#[derive(clap::Parser, Clone)]
pub struct Uncrlf {
#[arg(long = "edit", short = 'e')]
file_to_edit: Option<std::path::PathBuf>,
#[arg(long = "input", short)]
input_file: Option<std::path::PathBuf>,
#[arg(long = "output", short)]
output_file: Option<std::path::PathBuf>,
}
#[cfg(feature = "uncrlf")]
impl Uncrlf {
pub fn main(&self) -> sysexits::Result<()> {
use crate::{PatternIOProcessor, Prefer};
(|s: String| s.replace("\r\n", "\n")).io(
self.input_file.prefer(self.file_to_edit.clone()),
self.output_file.prefer(self.file_to_edit.clone()),
)
}
pub fn new<T>(
input_file: Option<T>,
output_file: Option<T>,
file_to_edit: Option<T>,
) -> Self
where
std::path::PathBuf: From<T>,
{
Self {
file_to_edit: file_to_edit.map(Into::into),
input_file: input_file.map(Into::into),
output_file: output_file.map(Into::into),
}
}
}