use std::path::PathBuf;
use anyhow::anyhow;
use clap::Args;
#[derive(Args, Debug)]
pub(crate) struct DestFileArgs {
#[arg(short = 'o', long = "output", value_name = "FILE", value_hint = clap::ValueHint::FilePath)]
pub(crate) file_path: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub(crate) struct DestDirArgs {
#[arg(short = 't', long = "target-dir", value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
pub(crate) dir_path: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub(crate) struct MarkdownDirArgs {
#[arg(short = 'm', long = "markdown-dir", value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
pub(crate) markdown_dir_path: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub(crate) struct CargoTomlDirArgs {
#[arg(short = 'c', long = "cargo-toml-dir", value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
pub(crate) cargo_toml_dir_path: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub(crate) struct UrlArgs {
#[arg(short='b', long="base-url", value_name = "URL", value_parser = parse_url)]
pub(crate) url: Option<url::Url>,
}
fn parse_url(s: &str) -> Result<url::Url, Box<dyn std::error::Error + Send + Sync + 'static>> {
let url = url::Url::parse(s).map_err(|_| anyhow!("Invalid URL: {s}"))?;
Ok(url)
}
#[derive(Debug, Args)]
#[command(flatten_help = true)]
pub(crate) struct MarkdownSrcDirAndDestFileArgs {
#[command(flatten)]
pub(crate) src: MarkdownDirArgs,
#[command(flatten)]
pub(crate) dest: DestFileArgs,
}
#[derive(Debug, Args)]
#[command(flatten_help = true)]
pub(crate) struct DependenciesDirAndDestFileArgs {
#[command(flatten)]
pub(crate) src: MarkdownDirArgs,
#[command(flatten)]
pub(crate) manifest: CargoTomlDirArgs,
#[command(flatten)]
pub(crate) dest: DestFileArgs,
}
#[derive(Args, Debug)]
pub(crate) struct MarkdownSrcDirAndDestDirArgs {
#[command(flatten)]
pub(crate) src: MarkdownDirArgs,
#[command(flatten)]
pub(crate) dest: DestDirArgs,
}
#[derive(Debug, Args)]
#[command(flatten_help = true)]
pub(crate) struct MarkdownSrcDirUrlAndDestFileArgs {
#[command(flatten)]
pub(crate) src: MarkdownDirArgs,
#[command(flatten)]
pub(crate) base: UrlArgs,
#[command(flatten)]
pub(crate) dest: DestFileArgs,
}
#[cfg(test)]
mod test {
}