From b09f1f958423dee8c235f2eeb9c148b73936830f Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 24 Oct 2021 13:26:37 +0530 Subject: rework cli, fix is now a flag, implement dry-run mode --- bin/src/config.rs | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'bin/src/config.rs') diff --git a/bin/src/config.rs b/bin/src/config.rs index cb03a4b..6d7bc49 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -17,39 +17,30 @@ use crate::err::ConfigErr; pub struct Opts { /// File or directory to run statix on #[clap(default_value = ".")] - target: String, + pub target: String, - // /// Path to statix config - // #[clap(short, long, default_value = ".statix.toml")] - // config: String, - /// Regex of file patterns to not lint + /// Globs of file patterns to skip #[clap(short, long)] - ignore: Vec, + pub ignore: Vec, - /// Output format. Supported values: json, errfmt + /// Output format. + /// Supported values: errfmt, json (on feature flag only) #[clap(short = 'o', long)] format: Option, - #[clap(subcommand)] - pub subcmd: Option, -} - -#[derive(Clap, Debug)] -#[clap(version = "0.1.0", author = "Akshay ")] -pub enum SubCommand { /// Find and fix issues raised by statix - Fix(Fix), -} + #[clap(short = 'f', long)] + pub fix: bool, -#[derive(Clap, Debug)] -pub struct Fix { - /// Do not write to files, display a diff instead + /// Do not fix files in place, display a diff instead #[clap(short = 'd', long = "dry-run")] diff_only: bool, } + #[derive(Debug, Copy, Clone)] pub enum OutFormat { + #[cfg(feature = "json")] Json, Errfmt, StdErr, @@ -66,9 +57,10 @@ impl FromStr for OutFormat { fn from_str(value: &str) -> Result { match value.to_ascii_lowercase().as_str() { - "json" => Ok(Self::Json), + #[cfg(feature = "json")] "json" => Ok(Self::Json), "errfmt" => Ok(Self::Errfmt), "stderr" => Ok(Self::StdErr), + "json" => Err("statix was not compiled with the `json` feature flag"), _ => Err("unknown output format, try: json, errfmt"), } } @@ -122,11 +114,7 @@ impl FixConfig { .filter(|path| !ignores.is_match(path)) .collect(); - let diff_only = match opts.subcmd { - Some(SubCommand::Fix(f)) => f.diff_only, - _ => false, - }; - + let diff_only = opts.diff_only; Ok(Self { files, diff_only }) } -- cgit v1.2.3