Skip to main content

foch_cli/cli/handler/config/
set.rs

1use crate::cli::arg;
2use crate::cli::arg::SetConfigArgs;
3use crate::cli::handler::HandlerResult;
4use foch::input::Config;
5use std::path::Path;
6
7pub fn handle_set(
8	set_args: &SetConfigArgs,
9	config: &mut Config,
10	config_file: &Path,
11) -> HandlerResult {
12	tracing::info!("setting configuration: {:?}", set_args);
13
14	match &set_args.command {
15		arg::FochCliSetCommands::SteamPath(path_args) => {
16			let path = path_args
17				.path
18				.canonicalize()
19				.unwrap_or_else(|_| path_args.path.clone());
20			println!("set Steam path: {}", path.display());
21			config.steam_root_path = Some(path);
22		}
23		arg::FochCliSetCommands::ParadoxDataPath(path_args) => {
24			let path = path_args
25				.path
26				.canonicalize()
27				.unwrap_or_else(|_| path_args.path.clone());
28			println!("set Paradox data path: {}", path.display());
29			config.paradox_data_path = Some(path);
30		}
31		arg::FochCliSetCommands::GamePath(game_path_args) => {
32			let path = game_path_args
33				.path
34				.canonicalize()
35				.unwrap_or_else(|_| game_path_args.path.clone());
36			println!(
37				"set game '{}' path: {}",
38				game_path_args.game_name,
39				path.display()
40			);
41			config
42				.game_path
43				.insert(game_path_args.game_name.clone(), path);
44		}
45	}
46
47	config.save_config(config_file)?;
48	Ok(0)
49}