From f14e45c30f67bd0030f82745925438a6ecb2e4ff Mon Sep 17 00:00:00 2001 From: Wim Velzeboer Date: Mon, 7 Sep 2026 11:01:59 +0100 Subject: [PATCH] change set subcommands into flag --- src/cli/mod.rs | 67 +++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 5ab76d2..19339e5 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -31,26 +31,16 @@ enum Commands { /// Lists the settings from the configuration file List, - /// Change Settings + /// Change settings Set { - #[command(subcommand)] - command: Option, - }, -} - -#[derive(clap::Subcommand, Debug)] -enum SettingsCommands { - - /// Set the Salesforce Authentication Url - SfdxAuthUrl { /// Salesforce Authentication Url #[arg( short = 'x', - long, + long = "sfdx-auth-url", env = "IMOJEFS_SFDX_AUTH_URL", hide_env_values = true )] - url: String, + sfdx_auth_url: Option, }, } @@ -169,11 +159,11 @@ fn list_config_settings(config_file: &str) -> Result<()> { Ok(()) } -fn set_sfdx_auth_url(config_file: &str, url: String) -> Result<()> { +fn set_sfdx_auth_url(config_file: &str, url: &str) -> Result<()> { let mut app_config = crate::config::load(config_file).context("Failed to load application configuration")?; - app_config.sfdx_auth_url = Some(url); + app_config.sfdx_auth_url = Some(url.to_string()); crate::config::save(config_file, &app_config) .context("Failed to save Salesforce authentication URL")?; @@ -186,8 +176,8 @@ pub(crate) fn run() { match &cli.command { Some(command) => match command { - Commands::Set { command } => { - run_set_command(&cli, command); + Commands::Set { sfdx_auth_url } => { + run_set_command(&cli, sfdx_auth_url); }, Commands::List => { run_list_command(&cli); @@ -227,24 +217,29 @@ fn run_list_command(cli: &Cli) { } } -fn run_set_command(cli: &Cli, commands: &Option) { - match commands { - Some(command) => match command { - SettingsCommands::SfdxAuthUrl { url } => { - match set_sfdx_auth_url(&cli.config, url.clone()) { - Ok(()) => { - println!("Salesforce authentication URL saved successfully"); - } - Err(e) => { - error!("Error saving Salesforce authentication URL: {:#}", e); - std::process::exit(1); - } - } - } - }, - None => { - println!("Expected subcommand, none given. Use --help for more information"); - std::process::exit(1); - } +fn run_set_command(cli: &Cli, sfdx_auth_url: &Option) { + let mut updated = false; + + updated = run_set_sfdx_auth_url(cli, sfdx_auth_url, &updated); + + if !updated { + println!("Expected at least one setting flag. Use --help for more information"); + std::process::exit(1); } } + +fn run_set_sfdx_auth_url(cli: &Cli, sfdx_auth_url: &Option, updated: &bool) -> bool { + if let Some(url) = sfdx_auth_url { + match set_sfdx_auth_url(&cli.config, url) { + Ok(()) => { + println!("Salesforce authentication URL saved successfully"); + return true; + } + Err(e) => { + error!("Error saving Salesforce authentication URL: {:#}", e); + std::process::exit(1); + } + } + } + *updated +}