Skip to main content

foch_cli/cli/handler/config/
show.rs

1use crate::cli::arg::ShowConfigArgs;
2use crate::cli::handler::HandlerResult;
3use foch::input::Config;
4
5pub fn handle_show(config: &Config, show_args: &ShowConfigArgs) -> HandlerResult {
6	if show_args.json {
7		println!("{}", serde_json::to_string_pretty(config)?);
8	} else {
9		println!("current configuration:");
10		println!(
11			"  steam_root_path: {}",
12			display_opt_path(config.steam_root_path.as_deref())
13		);
14		println!(
15			"  paradox_data_path: {}",
16			display_opt_path(config.paradox_data_path.as_deref())
17		);
18		if config.game_path.is_empty() {
19			println!("  game_path: <empty>");
20		} else {
21			println!("  game_path:");
22			for (game, path) in &config.game_path {
23				println!("    {game}: {}", path.display());
24			}
25		}
26	}
27
28	Ok(0)
29}
30
31fn display_opt_path(path: Option<&std::path::Path>) -> String {
32	path.map(|p| p.display().to_string())
33		.unwrap_or_else(|| "<unset>".to_string())
34}