use super::common::run as run_tool;
use super::common::{fail, hl, ok, repo_root, staged_files, warn, which};
use crate::check::Outcome;
pub const NAMES: &[&str] = &["Dockerfile"];
fn staged_dockerfiles() -> Vec<String> {
staged_files(&[])
.into_iter()
.filter(|p| {
let base = p.rsplit('/').next().unwrap_or(p);
NAMES.contains(&base)
})
.collect()
}
pub fn run(settings: &crate::config::Settings, _args: &[std::ffi::OsString]) -> Outcome {
let files = staged_dockerfiles();
if files.is_empty() {
return Outcome::Passed;
}
let root = repo_root();
let Some(bin) = which("hadolint") else {
warn(&format!(
"A Dockerfile is staged but hadolint is not installed. Install {}",
hl("hadolint")
));
return Outcome::Unavailable;
};
let argv = vec![bin];
let mut with_files = vec!["--".to_string()];
with_files.extend(files);
if !run_tool(settings, &root, &argv, &with_files) {
fail("hadolint found issues. Please fix");
return Outcome::Failed;
}
ok(settings, "hadolint passed");
Outcome::Passed
}