foch_cli/cli/handler/
mod.rs1pub mod cache;
2pub mod check;
3pub mod config;
4pub mod data;
5pub mod graph;
6pub mod input;
7pub mod merge;
8pub mod plugin;
9pub mod simplify;
10pub mod testing;
11
12pub type HandlerResult = Result<i32, Box<dyn std::error::Error>>;
13
14use foch::input::{Config, InputSource};
15use std::path::{Path, PathBuf};
16
17pub fn resolve_input_source(
23 explicit: Option<&Path>,
24 config: &Config,
25) -> Result<InputSource, String> {
26 if let Some(path) = explicit {
27 return Ok(InputSource::from_path(path.to_path_buf()));
28 }
29 let paradox = config.paradox_data_path.as_ref().ok_or_else(|| {
30 "no <PLAYSET_PATH> given and `paradox_data_path` is not configured; either pass a path \
31 explicitly or run `foch config set --paradox-data-path <dir>` so foch can default to the \
32 launcher's `dlc_load.json` in that directory"
33 .to_string()
34 })?;
35 let candidate = paradox.join("dlc_load.json");
36 if !candidate.is_file() {
37 return Err(format!(
38 "no <PLAYSET_PATH> given and `{}` does not exist; pass an explicit playset path or \
39 launch the Paradox launcher once to write `dlc_load.json`",
40 candidate.display()
41 ));
42 }
43 Ok(InputSource::DlcLoad(candidate))
44}
45
46pub fn resolve_playset_path(explicit: Option<&Path>, config: &Config) -> Result<PathBuf, String> {
47 Ok(resolve_input_source(explicit, config)?.path().to_path_buf())
48}