use super::utils::ensure_rustfmt_installed;
use crate::{Error, Result};
use std::path::Path;
pub async fn check_file_formatting(file_path: &Path) -> Result<bool> {
ensure_rustfmt_installed().await?;
let output = tokio::process::Command::new("rustfmt")
.args(&["--check", "--edition", "2021"])
.arg(file_path)
.output()
.await
.map_err(|e| Error::process(format!("Failed to check file formatting: {}", e)))?;
Ok(output.status.success())
}
pub async fn format_file(file_path: &Path) -> Result<()> {
ensure_rustfmt_installed().await?;
let status = tokio::process::Command::new("rustfmt")
.args(&["--edition", "2021"])
.arg(file_path)
.status()
.await
.map_err(|e| Error::process(format!("Failed to format file: {}", e)))?;
if !status.success() {
return Err(Error::process(format!(
"Failed to format file: {}",
file_path.display()
)));
}
Ok(())
}