mod check;
mod fix;
pub use check::TidyIssue;
use crate::cli::global::GlobalFlags;
use clap::Args;
#[derive(Debug, Args)]
#[command(after_help = "\
EXAMPLES:
patchloom tidy fix . --apply
patchloom tidy fix src/ --ensure-final-newline --apply
patchloom tidy fix . --trim-trailing-whitespace --apply
patchloom tidy check . --normalize-eol lf
With no write-policy flags, `tidy fix` enables final-newline and trailing-
whitespace fixes (the same issues `tidy check` always reports). Pass explicit
flags to narrow the fix set.")]
pub struct TidyArgs {
#[command(subcommand)]
pub action: TidyAction,
#[command(flatten)]
pub write: crate::cli::global::WriteFlags,
}
#[derive(Debug, clap::Subcommand)]
pub enum TidyAction {
Check { paths: Vec<String> },
Fix {
paths: Vec<String>,
#[arg(long)]
dedent: Option<String>,
#[arg(long)]
indent: Option<String>,
#[arg(long)]
lines: Option<String>,
},
}
pub fn run(args: TidyArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
crate::verbose!("tidy: action={:?}", std::mem::discriminant(&args.action));
match args.action {
TidyAction::Check { paths } => check::run_check(&paths, global),
TidyAction::Fix {
paths,
dedent,
indent,
lines,
} => fix::run_fix(paths, dedent, indent, lines, global),
}
}
#[cfg(test)]
mod tests;