diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 524ea235..2b5d10b0 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -483,15 +483,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "convert_case" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "core-foundation" version = "0.9.4" @@ -527,33 +518,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossterm" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" -dependencies = [ - "bitflags", - "crossterm_winapi", - "derive_more", - "document-features", - "mio", - "parking_lot", - "rustix", - "signal-hook", - "signal-hook-mio", - "winapi", -] - -[[package]] -name = "crossterm_winapi" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" -dependencies = [ - "winapi", -] - [[package]] name = "crunchy" version = "0.2.4" @@ -614,28 +578,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "derive_more" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" -dependencies = [ - "derive_more-impl", -] - -[[package]] -name = "derive_more-impl" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version", - "syn", -] - [[package]] name = "dialoguer" version = "0.12.0" @@ -700,15 +642,6 @@ dependencies = [ "const-random", ] -[[package]] -name = "document-features" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" -dependencies = [ - "litrs", -] - [[package]] name = "downpour" version = "0.1.0" @@ -724,7 +657,6 @@ dependencies = [ "droplet-rs", "fern", "indicatif", - "inquire", "log", "rand", "reqwest 0.13.1", @@ -960,15 +892,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fuzzy-matcher" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" -dependencies = [ - "thread_local", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1356,20 +1279,6 @@ dependencies = [ "web-time", ] -[[package]] -name = "inquire" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae51d5da01ce7039024fbdec477767c102c454dbdb09d4e2a432ece705b1b25d" -dependencies = [ - "bitflags", - "crossterm", - "dyn-clone", - "fuzzy-matcher", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "ipnet" version = "2.11.0" @@ -1480,21 +1389,6 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" -[[package]] -name = "litrs" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" - -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.29" @@ -1567,7 +1461,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" dependencies = [ "libc", - "log", "wasi", "windows-sys 0.61.2", ] @@ -1803,29 +1696,6 @@ version = "4.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" -[[package]] -name = "parking_lot" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link 0.2.1", -] - [[package]] name = "pem" version = "3.0.6" @@ -2023,15 +1893,6 @@ dependencies = [ "yasna", ] -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -dependencies = [ - "bitflags", -] - [[package]] name = "redox_users" version = "0.5.2" @@ -2193,15 +2054,6 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - [[package]] name = "rusticata-macros" version = "4.1.0" @@ -2348,12 +2200,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "security-framework" version = "2.11.1" @@ -2390,12 +2236,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" - [[package]] name = "serde" version = "1.0.228" @@ -2483,27 +2323,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "signal-hook" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-mio" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75a19a7a740b25bc7944bdee6172368f988763b744e3d4dfe753f6b4ece40cc" -dependencies = [ - "libc", - "mio", - "signal-hook", -] - [[package]] name = "signal-hook-registry" version = "1.4.7" @@ -2927,12 +2746,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - [[package]] name = "unicode-width" version = "0.2.2" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 0d407dd5..80b1d19f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -25,4 +25,3 @@ tokio-util = "0.7.18" url = "2.5.8" webbrowser = "1.0.6" color-eyre = "0.6.5" -inquire = "0.9.2" diff --git a/cli/src/commands/configure/config.rs b/cli/src/commands/configure/config.rs index 7035332f..a5697496 100644 --- a/cli/src/commands/configure/config.rs +++ b/cli/src/commands/configure/config.rs @@ -1,4 +1,9 @@ -use crate::commands::configure::{config_option::ConfigOption, s3::S3Config}; +use crate::commands::configure::{ + config_option::{ConfigOption, ConfigOptionCli}, + configurable::Configurable, + s3::S3Config, +}; +use dialoguer::{Confirm, theme::ColorfulTheme}; use log::warn; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, fs}; @@ -17,6 +22,9 @@ impl Config { active_s3: None, } } + pub fn exists(&self, name: &String) -> bool { + self.items.contains_key(name) + } pub fn save(&self) -> anyhow::Result<()> { let json = serde_json::to_string(self)?; let save_path = dirs::config_dir() @@ -69,3 +77,29 @@ impl Config { } } } + +pub async fn manage_configuration( + config: &mut Config, + name: &String, + option: &ConfigOptionCli, +) -> anyhow::Result<()> { + if config.exists(&name) { + let confirm = Confirm::with_theme(&ColorfulTheme::default()) + .with_prompt(format!( + "An entry already exists with the name \"{}\". Would you like to overwrite it?", + &name + )) + .interact()?; + if !confirm { + return Err(anyhow::anyhow!("User cancelled action")); + } + } + config.add_item( + name.clone(), + match option { + ConfigOptionCli::Server(server_config) => server_config.clone().configure().await?, + ConfigOptionCli::S3(s3_config_cli) => s3_config_cli.clone().configure().await?, + }, + ); + Ok(()) +} diff --git a/cli/src/main.rs b/cli/src/main.rs index 74fe1295..6c9527a3 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,4 @@ -use crate::commands::configure::config_option::ConfigOptionCli; -use crate::commands::configure::configurable::Configurable; +use crate::commands::configure::config::manage_configuration; use crate::{ cli::{Cli, Commands}, commands::configure::config::Config, @@ -19,13 +18,9 @@ async fn main() -> anyhow::Result<()> { let mut config = Config::read(); match &cli.command { - Commands::Configure { name, option } => config.add_item( - name.clone(), - match option { - ConfigOptionCli::Server(server_config) => server_config.clone().configure().await?, - ConfigOptionCli::S3(s3_config_cli) => s3_config_cli.clone().configure().await?, - }, - ), + Commands::Configure { name, option } => { + manage_configuration(&mut config, name, option).await? + } Commands::Upload(info) => { upload::interface::upload(info, config).await?; }