refactor(portal): move command runner into module

This commit is contained in:
igor04091968
2026-06-14 22:00:44 +03:00
parent 0cd6e4f856
commit d19b3d478f
2 changed files with 28 additions and 18 deletions
@@ -0,0 +1,26 @@
//! External command execution helpers for the portal.
//!
//! CONTRACT: these helpers are intentionally small and side-effect explicit.
//! They preserve stdout/stderr error text because readiness verification APIs
//! expose command failure diagnostics to operators.
use std::path::Path;
use std::process::Command;
pub(crate) fn run_in_dir(dir: &Path, command: &mut Command) -> std::result::Result<(), String> {
let output = command
.current_dir(dir)
.output()
.map_err(|err| format!("run command in {}: {err}", dir.display()))?;
if output.status.success() {
Ok(())
} else {
Err(format!(
"{}{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
)
.trim()
.to_string())
}
}
+2 -18
View File
@@ -23,12 +23,14 @@ use serde_json::{Value, json};
use sha2::{Digest, Sha256};
use tiny_http::{Header, Method, Request, Response, Server, StatusCode};
mod command_runner;
mod executive_actions;
mod portal_roles;
mod production;
mod risk_narrative;
mod workforce_kpi_explain;
use command_runner::run_in_dir;
use executive_actions::{
actions_from_center, build_action_center_from_report, filter_actions_for_role,
};
@@ -1810,24 +1812,6 @@ fn read_json_file(path: &Path) -> Result<Value> {
serde_json::from_str(&text).with_context(|| format!("parse {}", path.display()))
}
fn run_in_dir(dir: &Path, command: &mut Command) -> std::result::Result<(), String> {
let output = command
.current_dir(dir)
.output()
.map_err(|err| format!("run command in {}: {err}", dir.display()))?;
if output.status.success() {
Ok(())
} else {
Err(format!(
"{}{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
)
.trim()
.to_string())
}
}
fn query_flag(url: &str, key: &str) -> bool {
let Some(query) = url.split_once('?').map(|(_, query)| query) else {
return false;