Skip to content

Commit

Permalink
Redirect updated code to stdout
Browse files Browse the repository at this point in the history
Instead of replacing the contents of file
and removed the code to removing and creating
a new file

Signed-off-by: Muhammad Mahad <[email protected]>
  • Loading branch information
MahadMuhammad authored and CohenArthur committed Aug 2, 2024
1 parent 430f19e commit 84b0da8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
14 changes: 2 additions & 12 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,8 @@ pub fn parse_arguments_and_read_file(args: &Arguments) -> Result<(String, Option
Ok((source_code, err_file))
}

pub fn update_source_code(args: &Arguments, new_code: String) -> Result<()> {
fs::remove_file(&args.source_file)
.with_context(|| format!("could not remove file `{}`", &args.source_file.display()))?;

fs::write(&args.source_file, new_code).with_context(|| {
format!(
"could not write updated code to file `{}`",
&args.source_file.display()
)
})?;

Ok(())
pub fn print_source_code(source_code: &String) {
println!("{source_code}");
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn try_parse() -> Result<()> {
)
})?;

cli::update_source_code(&args, new_code)?;
cli::print_source_code(&new_code);

Ok(())
}

0 comments on commit 84b0da8

Please sign in to comment.