use crate::config::Config;
use anyhow::Result;
pub fn handle(steam_id: Option<String>, show: bool) -> Result<()> {
let mut config = Config::load()?;
if show {
show_config(&config)?;
return Ok(());
}
if let Some(id) = steam_id {
set_steam_id(&mut config, id)?;
} else {
show_usage();
}
Ok(())
}
fn show_config(config: &Config) -> Result<()> {
if let Some(id) = config.get_steam_id() {
println!("Steam ID: {}", id);
} else {
println!("No Steam ID configured");
}
if let Ok(path) = Config::config_path() {
println!("Config file: {}", path.display());
}
Ok(())
}
fn set_steam_id(config: &mut Config, id: String) -> Result<()> {
config.set_steam_id(id.clone());
config.save()?;
println!("Steam ID configured: {}", id);
if let Ok(path) = Config::config_path() {
println!("Config saved to: {}", path.display());
}
Ok(())
}
fn show_usage() {
println!("Usage: bl4 configure --steam-id YOUR_STEAM_ID");
println!(" or: bl4 configure --show");
println!();
println!("Note: Borderlands 4 uses your Steam ID to encrypt saves.");
println!(" Find it in the top left of your Steam account page.");
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_show_usage_does_not_panic() {
show_usage();
}
#[test]
fn test_config_path_exists() {
let result = Config::config_path();
assert!(result.is_ok());
}
#[test]
fn test_config_load() {
let result = Config::load();
assert!(result.is_ok());
}
}