aboutsummaryrefslogtreecommitdiff
path: root/bin/src/main.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-26 14:46:52 +0100
committerAkshay <[email protected]>2021-10-26 14:46:52 +0100
commit393c28566206b4a077be3cfb0e4e931544f0709e (patch)
treee7b8af9edef85920537ae31b60def57635b2a287 /bin/src/main.rs
parentcd527e849f0f05735cb1847a158b7104a00ce65c (diff)
fix single fix command
Diffstat (limited to 'bin/src/main.rs')
-rw-r--r--bin/src/main.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/bin/src/main.rs b/bin/src/main.rs
index 9c57d91..cbf2601 100644
--- a/bin/src/main.rs
+++ b/bin/src/main.rs
@@ -55,8 +55,21 @@ fn _main() -> Result<(), StatixErr> {
55 let path = single_config.target; 55 let path = single_config.target;
56 let src = std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)?; 56 let src = std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)?;
57 let (line, col) = single_config.position; 57 let (line, col) = single_config.position;
58 let single_result = fix::single(line, col, &src)?; 58 let single_fix_result = fix::single(line, col, &src)?;
59 std::fs::write(&path, &*single_result.src).map_err(SingleFixErr::InvalidPath)?; 59 if single_config.diff_only {
60 let text_diff = TextDiff::from_lines(src.as_str(), &single_fix_result.src);
61 let old_file = format!("{}", path.display());
62 let new_file = format!("{} [fixed]", path.display());
63 println!(
64 "{}",
65 text_diff
66 .unified_diff()
67 .context_radius(4)
68 .header(&old_file, &new_file)
69 );
70 } else {
71 std::fs::write(&path, &*single_fix_result.src).map_err(SingleFixErr::InvalidPath)?;
72 }
60 } 73 }
61 } 74 }
62 Ok(()) 75 Ok(())