diff options
author | Akshay <[email protected]> | 2021-10-26 14:48:28 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-10-26 15:20:23 +0100 |
commit | 20d195988de1014517ff1a1c8c1041cff5f88e05 (patch) | |
tree | 89b3f1cbce339211cad7f3489592e2bddc5c0518 /bin/src/main.rs | |
parent | 393c28566206b4a077be3cfb0e4e931544f0709e (diff) |
set internal crates to 0.0.0, bump to v0.2.0v0.2.0
Diffstat (limited to 'bin/src/main.rs')
-rw-r--r-- | bin/src/main.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/bin/src/main.rs b/bin/src/main.rs index cbf2601..4063621 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs | |||
@@ -6,7 +6,10 @@ mod traits; | |||
6 | 6 | ||
7 | use std::io; | 7 | use std::io; |
8 | 8 | ||
9 | use crate::{err::{StatixErr, FixErr, SingleFixErr}, traits::WriteDiagnostic}; | 9 | use crate::{ |
10 | err::{FixErr, SingleFixErr, StatixErr}, | ||
11 | traits::WriteDiagnostic, | ||
12 | }; | ||
10 | 13 | ||
11 | use clap::Clap; | 14 | use clap::Clap; |
12 | use config::{Opts, SubCommand}; | 15 | use config::{Opts, SubCommand}; |
@@ -17,7 +20,8 @@ fn _main() -> Result<(), StatixErr> { | |||
17 | match opts.cmd { | 20 | match opts.cmd { |
18 | SubCommand::Check(check_config) => { | 21 | SubCommand::Check(check_config) => { |
19 | let vfs = check_config.vfs()?; | 22 | let vfs = check_config.vfs()?; |
20 | let (lints, errors): (Vec<_>, Vec<_>) = vfs.iter().map(lint::lint).partition(Result::is_ok); | 23 | let (lints, errors): (Vec<_>, Vec<_>) = |
24 | vfs.iter().map(lint::lint).partition(Result::is_ok); | ||
21 | let lint_results = lints.into_iter().map(Result::unwrap); | 25 | let lint_results = lints.into_iter().map(Result::unwrap); |
22 | let errors = errors.into_iter().map(Result::unwrap_err); | 26 | let errors = errors.into_iter().map(Result::unwrap_err); |
23 | 27 | ||
@@ -28,7 +32,7 @@ fn _main() -> Result<(), StatixErr> { | |||
28 | errors.for_each(|e| { | 32 | errors.for_each(|e| { |
29 | eprintln!("{}", e); | 33 | eprintln!("{}", e); |
30 | }); | 34 | }); |
31 | }, | 35 | } |
32 | SubCommand::Fix(fix_config) => { | 36 | SubCommand::Fix(fix_config) => { |
33 | let vfs = fix_config.vfs()?; | 37 | let vfs = fix_config.vfs()?; |
34 | for entry in vfs.iter() { | 38 | for entry in vfs.iter() { |
@@ -40,17 +44,17 @@ fn _main() -> Result<(), StatixErr> { | |||
40 | println!( | 44 | println!( |
41 | "{}", | 45 | "{}", |
42 | text_diff | 46 | text_diff |
43 | .unified_diff() | 47 | .unified_diff() |
44 | .context_radius(4) | 48 | .context_radius(4) |
45 | .header(&old_file, &new_file) | 49 | .header(&old_file, &new_file) |
46 | ); | 50 | ); |
47 | } else { | 51 | } else { |
48 | let path = entry.file_path; | 52 | let path = entry.file_path; |
49 | std::fs::write(path, &*fix_result.src).map_err(FixErr::InvalidPath)?; | 53 | std::fs::write(path, &*fix_result.src).map_err(FixErr::InvalidPath)?; |
50 | } | 54 | } |
51 | } | 55 | } |
52 | } | 56 | } |
53 | }, | 57 | } |
54 | SubCommand::Single(single_config) => { | 58 | SubCommand::Single(single_config) => { |
55 | let path = single_config.target; | 59 | let path = single_config.target; |
56 | let src = std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)?; | 60 | let src = std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)?; |
@@ -63,12 +67,13 @@ fn _main() -> Result<(), StatixErr> { | |||
63 | println!( | 67 | println!( |
64 | "{}", | 68 | "{}", |
65 | text_diff | 69 | text_diff |
66 | .unified_diff() | 70 | .unified_diff() |
67 | .context_radius(4) | 71 | .context_radius(4) |
68 | .header(&old_file, &new_file) | 72 | .header(&old_file, &new_file) |
69 | ); | 73 | ); |
70 | } else { | 74 | } else { |
71 | std::fs::write(&path, &*single_fix_result.src).map_err(SingleFixErr::InvalidPath)?; | 75 | std::fs::write(&path, &*single_fix_result.src) |
76 | .map_err(SingleFixErr::InvalidPath)?; | ||
72 | } | 77 | } |
73 | } | 78 | } |
74 | } | 79 | } |