Skip to content
Snippets Groups Projects
Commit 747e02da authored by Nicolas80's avatar Nicolas80
Browse files

Reusing `inquire` dependency (which I didn't see in the first place) for user inputs

* Had to bump up the dependency since version 0.6.2 had a bug for the password confirmation - see https://github.com/mikaelmello/inquire/issues/149
* Removed `dialoguer` dependency
* We may want to replace all `rpassword` usage with `inquire` in the future
parent 30ebcf10
No related branches found
No related tags found
1 merge request!41Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
...@@ -1214,7 +1214,7 @@ dependencies = [ ...@@ -1214,7 +1214,7 @@ dependencies = [
"crossterm 0.27.0", "crossterm 0.27.0",
"strum", "strum",
"strum_macros", "strum_macros",
"unicode-width 0.1.14", "unicode-width",
] ]
[[package]] [[package]]
...@@ -1260,19 +1260,6 @@ dependencies = [ ...@@ -1260,19 +1260,6 @@ dependencies = [
"toml 0.5.11", "toml 0.5.11",
] ]
[[package]]
name = "console"
version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b"
dependencies = [
"encode_unicode",
"libc",
"once_cell",
"unicode-width 0.2.0",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "const-oid" name = "const-oid"
version = "0.9.6" version = "0.9.6"
...@@ -1667,19 +1654,6 @@ dependencies = [ ...@@ -1667,19 +1654,6 @@ dependencies = [
"syn 2.0.87", "syn 2.0.87",
] ]
[[package]]
name = "dialoguer"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de"
dependencies = [
"console",
"shell-words",
"tempfile",
"thiserror",
"zeroize",
]
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.9.0" version = "0.9.0"
...@@ -1918,12 +1892,6 @@ dependencies = [ ...@@ -1918,12 +1892,6 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "encode_unicode"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.34" version = "0.8.34"
...@@ -2350,6 +2318,24 @@ dependencies = [ ...@@ -2350,6 +2318,24 @@ dependencies = [
"slab", "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 = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]] [[package]]
name = "gcli" name = "gcli"
version = "0.3.0" version = "0.3.0"
...@@ -2362,7 +2348,6 @@ dependencies = [ ...@@ -2362,7 +2348,6 @@ dependencies = [
"colored", "colored",
"comfy-table", "comfy-table",
"confy", "confy",
"dialoguer",
"directories 5.0.1", "directories 5.0.1",
"env_logger", "env_logger",
"futures", "futures",
...@@ -2949,18 +2934,19 @@ dependencies = [ ...@@ -2949,18 +2934,19 @@ dependencies = [
[[package]] [[package]]
name = "inquire" name = "inquire"
version = "0.6.2" version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c33e7c1ddeb15c9abcbfef6029d8e29f69b52b6d6c891031b88ed91b5065803b" checksum = "0fddf93031af70e75410a2511ec04d49e758ed2f26dad3404a934e0fb45cc12a"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 2.6.0",
"crossterm 0.25.0", "crossterm 0.25.0",
"dyn-clone", "dyn-clone",
"lazy_static", "fuzzy-matcher",
"fxhash",
"newline-converter", "newline-converter",
"thiserror", "once_cell",
"unicode-segmentation", "unicode-segmentation",
"unicode-width 0.1.14", "unicode-width",
] ]
[[package]] [[package]]
...@@ -3575,9 +3561,9 @@ dependencies = [ ...@@ -3575,9 +3561,9 @@ dependencies = [
[[package]] [[package]]
name = "newline-converter" name = "newline-converter"
version = "0.2.2" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f" checksum = "47b6b097ecb1cbfed438542d16e84fd7ad9b0c76c8a65b7f9039212a3d14dc7f"
dependencies = [ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
...@@ -5413,12 +5399,6 @@ dependencies = [ ...@@ -5413,12 +5399,6 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "shell-words"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "1.3.0"
...@@ -7108,12 +7088,6 @@ version = "0.1.14" ...@@ -7108,12 +7088,6 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.6" version = "0.2.6"
......
...@@ -36,14 +36,13 @@ log = "^0.4.22" ...@@ -36,14 +36,13 @@ log = "^0.4.22"
reqwest = { version = "^0.11.27", default-features = false, features = [ reqwest = { version = "^0.11.27", default-features = false, features = [
"rustls-tls", "rustls-tls",
] } ] }
inquire = "^0.7.5"
rpassword = "^7.3.1" rpassword = "^7.3.1"
dialoguer = "0.11.0"
serde = { version = "^1.0", features = ["derive"] } serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0.128" serde_json = "^1.0.128"
tokio = { version = "^1.40.0", features = ["macros"] } tokio = { version = "^1.40.0", features = ["macros"] }
confy = "^0.5.1" confy = "^0.5.1"
bs58 = "^0.5.1" bs58 = "^0.5.1"
inquire = "^0.6.2"
directories = "^5.0.1" directories = "^5.0.1"
comfy-table = "^7.1.1" comfy-table = "^7.1.1"
sea-orm = { version = "1.1.0", features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ] } sea-orm = { version = "1.1.0", features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ] }
......
use crate::utils::GcliError; use crate::utils::GcliError;
use inquire::validator::Validation;
pub fn prompt_password() -> Result<String, GcliError> { pub fn prompt_password() -> Result<String, GcliError> {
prompt_password_query("Password") prompt_password_query("Password")
...@@ -9,22 +10,15 @@ pub fn prompt_password_confirm() -> Result<String, GcliError> { ...@@ -9,22 +10,15 @@ pub fn prompt_password_confirm() -> Result<String, GcliError> {
} }
pub fn prompt_password_query(query: impl ToString) -> Result<String, GcliError> { pub fn prompt_password_query(query: impl ToString) -> Result<String, GcliError> {
dialoguer::Password::default() inquire::Password::new(query.to_string().as_str())
.with_prompt(query.to_string()) .without_confirmation()
.allow_empty_password(true) .prompt()
.interact()
.map_err(|e| GcliError::Input(e.to_string())) .map_err(|e| GcliError::Input(e.to_string()))
} }
pub fn prompt_password_query_confirm(query: impl ToString) -> Result<String, GcliError> { pub fn prompt_password_query_confirm(query: impl ToString) -> Result<String, GcliError> {
dialoguer::Password::new() inquire::Password::new(query.to_string().as_str())
.with_prompt(query.to_string()) .prompt()
.allow_empty_password(true)
.with_confirmation(
format!("Repeat {}", query.to_string()),
"Error: the values do not match.",
)
.interact()
.map_err(|e| GcliError::Input(e.to_string())) .map_err(|e| GcliError::Input(e.to_string()))
} }
...@@ -32,54 +26,38 @@ pub fn prompt_password_query_confirm(query: impl ToString) -> Result<String, Gcl ...@@ -32,54 +26,38 @@ pub fn prompt_password_query_confirm(query: impl ToString) -> Result<String, Gcl
/// ///
/// Also preventing to use '<' and '>' as those are used in the display of /// Also preventing to use '<' and '>' as those are used in the display of
pub fn prompt_vault_name() -> Result<Option<String>, GcliError> { pub fn prompt_vault_name() -> Result<Option<String>, GcliError> {
let name = dialoguer::Input::new() inquire::Text::new("Name:")
.with_prompt("Name") .with_validator(|input: &str| {
.validate_with({ if input.contains('<') || input.contains('>') || input.contains('/') {
move |input: &String| -> Result<(), &str> { Ok(Validation::Invalid(
if input.contains('<') || input.contains('>') || input.contains('/') { "Name cannot contain characters '<', '>', '/'".into(),
Err("Name cannot contain characters '<', '>', '/'") ))
} else { } else {
Ok(()) Ok(Validation::Valid)
}
} }
}) })
.allow_empty(true) .prompt_skippable()
.interact_text() .map_err(|e| GcliError::Input(e.to_string()))
.map_err(|e| GcliError::Input(e.to_string()))?;
let name = if name.trim().is_empty() {
None
} else {
Some(name.trim().to_string())
};
Ok(name)
} }
/// Prompt for a derivation path /// Prompt for a derivation path
pub fn prompt_vault_derivation_path() -> Result<String, GcliError> { pub fn prompt_vault_derivation_path() -> Result<String, GcliError> {
let path = dialoguer::Input::new() inquire::Text::new("Derivation path:")
.with_prompt("Derivation path") .with_validator(|input: &str| {
.validate_with({ if !input.starts_with("/") {
move |input: &String| -> Result<(), &str> { Ok(Validation::Invalid(
if !input.starts_with("/") { "derivation path needs to start with one or more '/'".into(),
Err("derivation path needs to start with one or more '/'") ))
} else { } else {
Ok(()) Ok(Validation::Valid)
}
} }
}) })
.allow_empty(false) .prompt()
.interact_text() .map_err(|e| GcliError::Input(e.to_string()))
.map_err(|e| GcliError::Input(e.to_string()))?;
Ok(path)
} }
pub fn confirm_action(query: impl ToString) -> Result<bool, GcliError> { pub fn confirm_action(query: impl ToString) -> Result<bool, GcliError> {
dialoguer::Confirm::new() inquire::Confirm::new(query.to_string().as_str())
.with_prompt(query.to_string()) .prompt()
//.default(false)
.interact()
.map_err(|e| GcliError::Input(e.to_string())) .map_err(|e| GcliError::Input(e.to_string()))
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment