aboutsummaryrefslogtreecommitdiff
path: root/bin/src/main.rs
diff options
context:
space:
mode:
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(())