use crate::{
profile::Profile,
utils::{run_command_or_exit, string_vec},
};
pub fn fmt(files: Vec<String>, check: bool) {
let pyproject_toml = Profile::load(None).unwrap().materialize(None).unwrap();
{
let mut uv_command = string_vec![
"uv",
"run",
"--with",
"ruff",
"ruff",
"format",
"--config",
pyproject_toml.to_string_lossy().to_string()
];
if check {
uv_command.push("--check".to_owned());
}
if files.is_empty() {
uv_command.push(".".to_owned());
} else {
uv_command.extend(files.clone());
}
run_command_or_exit(uv_command);
}
{
let mut uv_command = string_vec![
"uv",
"run",
"--with",
"ruff",
"ruff",
"check",
"--config",
pyproject_toml.to_string_lossy().to_string(),
"--select",
"I"
];
if !check {
uv_command.push("--fix".to_owned());
}
if files.is_empty() {
uv_command.push(".".to_owned());
} else {
uv_command.extend(files);
}
run_command_or_exit(uv_command);
}
}