diff options
author | Akshay <[email protected]> | 2021-10-24 08:56:37 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-10-24 08:56:37 +0100 |
commit | b09f1f958423dee8c235f2eeb9c148b73936830f (patch) | |
tree | 0bab5509f6dfcb46af9aa686c313f556c7ae5f0b /bin/src/config.rs | |
parent | 5de0ba055cef7f2dc5451b1eaf0857deb77ae009 (diff) |
rework cli, fix is now a flag, implement dry-run mode
Diffstat (limited to 'bin/src/config.rs')
-rw-r--r-- | bin/src/config.rs | 38 |
1 files changed, 13 insertions, 25 deletions
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; | |||
17 | pub struct Opts { | 17 | pub struct Opts { |
18 | /// File or directory to run statix on | 18 | /// File or directory to run statix on |
19 | #[clap(default_value = ".")] | 19 | #[clap(default_value = ".")] |
20 | target: String, | 20 | pub target: String, |
21 | 21 | ||
22 | // /// Path to statix config | 22 | /// Globs of file patterns to skip |
23 | // #[clap(short, long, default_value = ".statix.toml")] | ||
24 | // config: String, | ||
25 | /// Regex of file patterns to not lint | ||
26 | #[clap(short, long)] | 23 | #[clap(short, long)] |
27 | ignore: Vec<String>, | 24 | pub ignore: Vec<String>, |
28 | 25 | ||
29 | /// Output format. Supported values: json, errfmt | 26 | /// Output format. |
27 | /// Supported values: errfmt, json (on feature flag only) | ||
30 | #[clap(short = 'o', long)] | 28 | #[clap(short = 'o', long)] |
31 | format: Option<OutFormat>, | 29 | format: Option<OutFormat>, |
32 | 30 | ||
33 | #[clap(subcommand)] | ||
34 | pub subcmd: Option<SubCommand>, | ||
35 | } | ||
36 | |||
37 | #[derive(Clap, Debug)] | ||
38 | #[clap(version = "0.1.0", author = "Akshay <[email protected]>")] | ||
39 | pub enum SubCommand { | ||
40 | /// Find and fix issues raised by statix | 31 | /// Find and fix issues raised by statix |
41 | Fix(Fix), | 32 | #[clap(short = 'f', long)] |
42 | } | 33 | pub fix: bool, |
43 | 34 | ||
44 | #[derive(Clap, Debug)] | 35 | /// Do not fix files in place, display a diff instead |
45 | pub struct Fix { | ||
46 | /// Do not write to files, display a diff instead | ||
47 | #[clap(short = 'd', long = "dry-run")] | 36 | #[clap(short = 'd', long = "dry-run")] |
48 | diff_only: bool, | 37 | diff_only: bool, |
49 | } | 38 | } |
50 | 39 | ||
40 | |||
51 | #[derive(Debug, Copy, Clone)] | 41 | #[derive(Debug, Copy, Clone)] |
52 | pub enum OutFormat { | 42 | pub enum OutFormat { |
43 | #[cfg(feature = "json")] | ||
53 | Json, | 44 | Json, |
54 | Errfmt, | 45 | Errfmt, |
55 | StdErr, | 46 | StdErr, |
@@ -66,9 +57,10 @@ impl FromStr for OutFormat { | |||
66 | 57 | ||
67 | fn from_str(value: &str) -> Result<Self, Self::Err> { | 58 | fn from_str(value: &str) -> Result<Self, Self::Err> { |
68 | match value.to_ascii_lowercase().as_str() { | 59 | match value.to_ascii_lowercase().as_str() { |
69 | "json" => Ok(Self::Json), | 60 | #[cfg(feature = "json")] "json" => Ok(Self::Json), |
70 | "errfmt" => Ok(Self::Errfmt), | 61 | "errfmt" => Ok(Self::Errfmt), |
71 | "stderr" => Ok(Self::StdErr), | 62 | "stderr" => Ok(Self::StdErr), |
63 | "json" => Err("statix was not compiled with the `json` feature flag"), | ||
72 | _ => Err("unknown output format, try: json, errfmt"), | 64 | _ => Err("unknown output format, try: json, errfmt"), |
73 | } | 65 | } |
74 | } | 66 | } |
@@ -122,11 +114,7 @@ impl FixConfig { | |||
122 | .filter(|path| !ignores.is_match(path)) | 114 | .filter(|path| !ignores.is_match(path)) |
123 | .collect(); | 115 | .collect(); |
124 | 116 | ||
125 | let diff_only = match opts.subcmd { | 117 | let diff_only = opts.diff_only; |
126 | Some(SubCommand::Fix(f)) => f.diff_only, | ||
127 | _ => false, | ||
128 | }; | ||
129 | |||
130 | Ok(Self { files, diff_only }) | 118 | Ok(Self { files, diff_only }) |
131 | } | 119 | } |
132 | 120 | ||