change set subcommands into flag

This commit is contained in:
Wim Velzeboer
2026-09-07 11:01:59 +01:00
parent 578f23001c
commit f14e45c30f
+31 -36
View File
@@ -31,26 +31,16 @@ enum Commands {
/// Lists the settings from the configuration file
List,
/// Change Settings
/// Change settings
Set {
#[command(subcommand)]
command: Option<SettingsCommands>,
},
}
#[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<String>,
},
}
@@ -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<SettingsCommands>) {
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<String>) {
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<String>, 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
}