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
Branches
Tags
1 merge request!41Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
......@@ -1214,7 +1214,7 @@ dependencies = [
"crossterm 0.27.0",
"strum",
"strum_macros",
"unicode-width 0.1.14",
"unicode-width",
]
[[package]]
......@@ -1260,19 +1260,6 @@ dependencies = [
"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]]
name = "const-oid"
version = "0.9.6"
......@@ -1667,19 +1654,6 @@ dependencies = [
"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]]
name = "digest"
version = "0.9.0"
......@@ -1918,12 +1892,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "encode_unicode"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]]
name = "encoding_rs"
version = "0.8.34"
......@@ -2350,6 +2318,24 @@ 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 = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "gcli"
version = "0.3.0"
......@@ -2362,7 +2348,6 @@ dependencies = [
"colored",
"comfy-table",
"confy",
"dialoguer",
"directories 5.0.1",
"env_logger",
"futures",
......@@ -2949,18 +2934,19 @@ dependencies = [
[[package]]
name = "inquire"
version = "0.6.2"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c33e7c1ddeb15c9abcbfef6029d8e29f69b52b6d6c891031b88ed91b5065803b"
checksum = "0fddf93031af70e75410a2511ec04d49e758ed2f26dad3404a934e0fb45cc12a"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.6.0",
"crossterm 0.25.0",
"dyn-clone",
"lazy_static",
"fuzzy-matcher",
"fxhash",
"newline-converter",
"thiserror",
"once_cell",
"unicode-segmentation",
"unicode-width 0.1.14",
"unicode-width",
]
[[package]]
......@@ -3575,9 +3561,9 @@ dependencies = [
[[package]]
name = "newline-converter"
version = "0.2.2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f"
checksum = "47b6b097ecb1cbfed438542d16e84fd7ad9b0c76c8a65b7f9039212a3d14dc7f"
dependencies = [
"unicode-segmentation",
]
......@@ -5413,12 +5399,6 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "shell-words"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
[[package]]
name = "shlex"
version = "1.3.0"
......@@ -7108,12 +7088,6 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "unicode-xid"
version = "0.2.6"
......
......@@ -36,14 +36,13 @@ log = "^0.4.22"
reqwest = { version = "^0.11.27", default-features = false, features = [
"rustls-tls",
] }
inquire = "^0.7.5"
rpassword = "^7.3.1"
dialoguer = "0.11.0"
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0.128"
tokio = { version = "^1.40.0", features = ["macros"] }
confy = "^0.5.1"
bs58 = "^0.5.1"
inquire = "^0.6.2"
directories = "^5.0.1"
comfy-table = "^7.1.1"
sea-orm = { version = "1.1.0", features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ] }
......
use crate::utils::GcliError;
use inquire::validator::Validation;
pub fn prompt_password() -> Result<String, GcliError> {
prompt_password_query("Password")
......@@ -9,22 +10,15 @@ pub fn prompt_password_confirm() -> Result<String, GcliError> {
}
pub fn prompt_password_query(query: impl ToString) -> Result<String, GcliError> {
dialoguer::Password::default()
.with_prompt(query.to_string())
.allow_empty_password(true)
.interact()
inquire::Password::new(query.to_string().as_str())
.without_confirmation()
.prompt()
.map_err(|e| GcliError::Input(e.to_string()))
}
pub fn prompt_password_query_confirm(query: impl ToString) -> Result<String, GcliError> {
dialoguer::Password::new()
.with_prompt(query.to_string())
.allow_empty_password(true)
.with_confirmation(
format!("Repeat {}", query.to_string()),
"Error: the values do not match.",
)
.interact()
inquire::Password::new(query.to_string().as_str())
.prompt()
.map_err(|e| GcliError::Input(e.to_string()))
}
......@@ -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
pub fn prompt_vault_name() -> Result<Option<String>, GcliError> {
let name = dialoguer::Input::new()
.with_prompt("Name")
.validate_with({
move |input: &String| -> Result<(), &str> {
inquire::Text::new("Name:")
.with_validator(|input: &str| {
if input.contains('<') || input.contains('>') || input.contains('/') {
Err("Name cannot contain characters '<', '>', '/'")
Ok(Validation::Invalid(
"Name cannot contain characters '<', '>', '/'".into(),
))
} else {
Ok(())
}
Ok(Validation::Valid)
}
})
.allow_empty(true)
.interact_text()
.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_skippable()
.map_err(|e| GcliError::Input(e.to_string()))
}
/// Prompt for a derivation path
pub fn prompt_vault_derivation_path() -> Result<String, GcliError> {
let path = dialoguer::Input::new()
.with_prompt("Derivation path")
.validate_with({
move |input: &String| -> Result<(), &str> {
inquire::Text::new("Derivation path:")
.with_validator(|input: &str| {
if !input.starts_with("/") {
Err("derivation path needs to start with one or more '/'")
Ok(Validation::Invalid(
"derivation path needs to start with one or more '/'".into(),
))
} else {
Ok(())
}
Ok(Validation::Valid)
}
})
.allow_empty(false)
.interact_text()
.map_err(|e| GcliError::Input(e.to_string()))?;
Ok(path)
.prompt()
.map_err(|e| GcliError::Input(e.to_string()))
}
pub fn confirm_action(query: impl ToString) -> Result<bool, GcliError> {
dialoguer::Confirm::new()
.with_prompt(query.to_string())
//.default(false)
.interact()
inquire::Confirm::new(query.to_string().as_str())
.prompt()
.map_err(|e| GcliError::Input(e.to_string()))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment