use std::path::PathBuf;
use clap::Parser;
const VERSION_STR: &str = concat!("re:patch ", env!("CARGO_PKG_VERSION"));
#[derive(Debug, Parser)]
#[command(version, name = "re:patch", max_term_width = 120, help_expected = true)]
#[command(before_help(VERSION_STR))]
pub struct Args {
pub find: String,
pub replace: String,
#[clap(required = true)]
pub paths: Vec<PathBuf>,
#[clap(long, short)]
pub ignore_case: bool,
#[clap(long)]
pub ignore_errors: bool,
#[clap(long, default_value_t, value_name = "N")]
pub context: Context,
#[clap(long, conflicts_with_all(["apply"]))]
pub show: bool,
#[clap(long)]
pub apply: bool,
}
#[derive(Copy, Clone, Debug)]
pub enum Context {
Num(u64),
Infinite,
}
impl std::str::FromStr for Context {
type Err = std::num::ParseIntError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"infinite" => Self::Infinite,
x => Self::Num(x.parse()?),
})
}
}
impl std::fmt::Display for Context {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Num(x) => write!(f, "{x}"),
Self::Infinite => write!(f, "infinite"),
}
}
}
impl Default for Context {
fn default() -> Self {
Self::Num(5)
}
}