change set subcommands into flag
This commit is contained in:
+31
-36
@@ -31,26 +31,16 @@ enum Commands {
|
|||||||
/// Lists the settings from the configuration file
|
/// Lists the settings from the configuration file
|
||||||
List,
|
List,
|
||||||
|
|
||||||
/// Change Settings
|
/// Change settings
|
||||||
Set {
|
Set {
|
||||||
#[command(subcommand)]
|
|
||||||
command: Option<SettingsCommands>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(clap::Subcommand, Debug)]
|
|
||||||
enum SettingsCommands {
|
|
||||||
|
|
||||||
/// Set the Salesforce Authentication Url
|
|
||||||
SfdxAuthUrl {
|
|
||||||
/// Salesforce Authentication Url
|
/// Salesforce Authentication Url
|
||||||
#[arg(
|
#[arg(
|
||||||
short = 'x',
|
short = 'x',
|
||||||
long,
|
long = "sfdx-auth-url",
|
||||||
env = "IMOJEFS_SFDX_AUTH_URL",
|
env = "IMOJEFS_SFDX_AUTH_URL",
|
||||||
hide_env_values = true
|
hide_env_values = true
|
||||||
)]
|
)]
|
||||||
url: String,
|
sfdx_auth_url: Option<String>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,11 +159,11 @@ fn list_config_settings(config_file: &str) -> Result<()> {
|
|||||||
Ok(())
|
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 =
|
let mut app_config =
|
||||||
crate::config::load(config_file).context("Failed to load application configuration")?;
|
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)
|
crate::config::save(config_file, &app_config)
|
||||||
.context("Failed to save Salesforce authentication URL")?;
|
.context("Failed to save Salesforce authentication URL")?;
|
||||||
@@ -186,8 +176,8 @@ pub(crate) fn run() {
|
|||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Some(command) => match command {
|
Some(command) => match command {
|
||||||
Commands::Set { command } => {
|
Commands::Set { sfdx_auth_url } => {
|
||||||
run_set_command(&cli, command);
|
run_set_command(&cli, sfdx_auth_url);
|
||||||
},
|
},
|
||||||
Commands::List => {
|
Commands::List => {
|
||||||
run_list_command(&cli);
|
run_list_command(&cli);
|
||||||
@@ -227,24 +217,29 @@ fn run_list_command(cli: &Cli) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_set_command(cli: &Cli, commands: &Option<SettingsCommands>) {
|
fn run_set_command(cli: &Cli, sfdx_auth_url: &Option<String>) {
|
||||||
match commands {
|
let mut updated = false;
|
||||||
Some(command) => match command {
|
|
||||||
SettingsCommands::SfdxAuthUrl { url } => {
|
updated = run_set_sfdx_auth_url(cli, sfdx_auth_url, &updated);
|
||||||
match set_sfdx_auth_url(&cli.config, url.clone()) {
|
|
||||||
Ok(()) => {
|
if !updated {
|
||||||
println!("Salesforce authentication URL saved successfully");
|
println!("Expected at least one setting flag. Use --help for more information");
|
||||||
}
|
std::process::exit(1);
|
||||||
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_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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user