use super::*;
pub(crate) fn resolve_project_root_and_config(
options: &AnalysisOptions,
) -> Result<(PathBuf, Config), String> {
let project_root = std::env::current_dir()
.map_err(|error| format!("unable to resolve current directory: {error}"))?;
let config = load_config(&project_root, options)?;
Ok((project_root, config))
}
pub(crate) fn resolve_fail_on(
cli_value: Option<FailThreshold>,
config: &Config,
command: &str,
binary_default: FailThreshold,
) -> FailThreshold {
cli_value
.or_else(|| config.minimum_severity.get(command).copied())
.unwrap_or(binary_default)
}
pub(crate) fn resolve_command_setup(
base: AnalysisOptions,
cli_fail_on: Option<FailThreshold>,
command: &str,
binary_default: FailThreshold,
) -> Result<(PathBuf, AnalysisOptions, Config), String> {
let (project_root, config) = resolve_project_root_and_config(&base)?;
let options = AnalysisOptions {
fail_on: resolve_fail_on(cli_fail_on, &config, command, binary_default),
..base
};
Ok((project_root, options, config))
}
pub(crate) fn emit_report_output(
writer: OutputWriter,
output: Option<PathBuf>,
outcome: RunOutcome,
rendered: &str,
) -> Result<(), String> {
if let Some(path) = output {
fs::write(&path, rendered)
.map_err(|error| format!("unable to write {}: {error}", path.display()))?;
} else {
writer.emit(outcome, rendered);
}
Ok(())
}