pub mod changelog;
pub mod deps;
pub mod doctor;
pub mod version;
use std::path::Path;
use crate::runners::shell;
fn formatter(language: &str) -> Option<&'static str> {
match language {
"rust" => Some("cargo fmt"),
"node" => Some("npx --yes prettier --write ."),
"python" => Some("black ."),
"go" => Some("gofmt -w ."),
_ => None,
}
}
fn linter(language: &str) -> Option<&'static str> {
match language {
"rust" => Some("cargo clippy"),
"node" => Some("npx --yes eslint ."),
"python" => Some("ruff check ."),
"go" => Some("go vet ./..."),
_ => None,
}
}
pub enum ToolOutcome {
Ran { success: bool },
NoCommand,
}
pub fn fmt(root: &Path, language: &str) -> ToolOutcome {
run_tool(root, formatter(language))
}
pub fn lint(root: &Path, language: &str) -> ToolOutcome {
run_tool(root, linter(language))
}
fn run_tool(root: &Path, command: Option<&str>) -> ToolOutcome {
match command {
Some(cmd) => match shell::run(cmd, root) {
Ok(r) => ToolOutcome::Ran { success: r.success },
Err(_) => ToolOutcome::NoCommand,
},
None => ToolOutcome::NoCommand,
}
}
pub fn fmt_command(language: &str) -> Option<&'static str> {
formatter(language)
}
pub fn lint_command(language: &str) -> Option<&'static str> {
linter(language)
}