use serde_json::json;
use crate::finish::Finished;
use crate::install::{self, Way};
use crate::json;
use crate::out::errln;
const SCHEMA: &str = "loft-record-install/1";
pub fn run(way: Way, as_json: bool) -> Finished {
match install::record(way) {
Ok(path) => {
if as_json {
let fields = json!({ "path": path, "way": way.as_str() });
json::print(&json::result(SCHEMA, "recorded", fields, Vec::new()));
}
Finished::success("recorded")
}
Err(error) => {
let message = error.to_string();
let errors = vec![json::error("settings", &message, &[])];
let finished = Finished::with(std::process::ExitCode::SUCCESS, "unwritten", &errors);
if as_json {
let fields = json!({ "way": way.as_str() });
json::print(&json::result(SCHEMA, "unwritten", fields, errors));
}
errln!("loft record-install: {message}");
finished
}
}
}