add sfdx_auth_url setting
This commit is contained in:
+59
-9
@@ -1,7 +1,7 @@
|
||||
use crate::logger;
|
||||
use anyhow::{Context, Result};
|
||||
use clap::{Parser, ValueEnum};
|
||||
use log::error;
|
||||
use clap::{CommandFactory, Parser, ValueEnum};
|
||||
use log::{error, info};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
@@ -11,7 +11,8 @@ struct Cli {
|
||||
pub wait: u64,
|
||||
|
||||
/// The logging level
|
||||
#[arg(short = 'l', long, value_enum, default_value_t = LogLevel::Info, env = "IMOJEFS_LOG_LEVEL")]
|
||||
#[arg(short = 'l', long, value_enum, default_value_t = LogLevel::Info, env = "IMOJEFS_LOG_LEVEL"
|
||||
)]
|
||||
pub log_level: LogLevel,
|
||||
|
||||
/// The configuration to use
|
||||
@@ -36,13 +37,14 @@ enum Commands {
|
||||
|
||||
#[derive(clap::Subcommand, Debug)]
|
||||
enum SettingsCommands {
|
||||
|
||||
/// Set the Salesforce Authentication Url
|
||||
SfdxAuthUrl {
|
||||
/// Salesforce Authentication Url
|
||||
#[arg(
|
||||
short = 'x',
|
||||
long,
|
||||
env = "IMOJEEH_SFDX_AUTH_URL",
|
||||
env = "IMOJEFS_SFDX_AUTH_URL",
|
||||
hide_env_values = true
|
||||
)]
|
||||
url: String,
|
||||
@@ -147,10 +149,42 @@ fn load_configuration_file(config_file: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn set_sfdx_auth_url(config_file: &str, url: String) -> Result<()> {
|
||||
let mut app_config =
|
||||
crate::config::load(config_file).context("Failed to load application configuration")?;
|
||||
|
||||
app_config.sfdx_auth_url = Some(url);
|
||||
|
||||
crate::config::save(config_file, &app_config)
|
||||
.context("Failed to save Salesforce authentication URL")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub(crate) fn run() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match &cli.command {
|
||||
Some(command) => match command {
|
||||
Commands::Set { command } => {
|
||||
run_set_command(&cli, command);
|
||||
},
|
||||
Commands::FileSync { .. } => {
|
||||
run_file_sync(&cli);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
println!("Expected subcommand, none given. Use --help for more information");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_file_sync(cli: &Cli) {
|
||||
logger::init(&cli.log_level);
|
||||
|
||||
match load_configuration_file(&cli.config) {
|
||||
Ok(()) => {}
|
||||
Err(e) => {
|
||||
@@ -159,11 +193,27 @@ pub(crate) fn run() {
|
||||
}
|
||||
}
|
||||
|
||||
match cli.command {
|
||||
Some(subcommand) => match subcommand {
|
||||
Commands::FileSync { .. } => {}
|
||||
Commands::Set { .. } => {}
|
||||
crate::file_sync::run();
|
||||
}
|
||||
|
||||
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 => {}
|
||||
None => {
|
||||
println!("Expected subcommand, none given. Use --help for more information");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-2
@@ -15,13 +15,13 @@ const NONCE_LEN: usize = 12;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AppConfig {
|
||||
pub dummy_setting: String,
|
||||
pub sfdx_auth_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
dummy_setting: "dummy-value".to_string(),
|
||||
sfdx_auth_url: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,12 @@ pub fn load(config_file: &str) -> Result<AppConfig> {
|
||||
.with_context(|| format!("Unable to decrypt configuration file {}", config_path.display()))
|
||||
}
|
||||
|
||||
pub fn save(config_file: &str, config: &AppConfig) -> Result<()> {
|
||||
let config_path = config_path(config_file)?;
|
||||
save_encrypted(&config_path, config)
|
||||
.with_context(|| format!("Unable to save configuration file {}", config_path.display()))
|
||||
}
|
||||
|
||||
fn config_path(config_file: &str) -> Result<PathBuf> {
|
||||
let home_dir = dirs::home_dir().ok_or_else(|| anyhow!("Unable to determine home directory"))?;
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
pub fn run() {
|
||||
unimplemented!("File sync not yet implemented");
|
||||
}
|
||||
@@ -14,6 +14,8 @@ mod logger;
|
||||
mod salesforce;
|
||||
mod terminator;
|
||||
|
||||
mod file_sync;
|
||||
|
||||
|
||||
pub static APP_CONFIG: OnceLock<config::AppConfig> = OnceLock::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user