Skip to content

Commit

Permalink
specify default decision
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Mar 21, 2024
1 parent 1a711ae commit 1f16abf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub async fn new_wallet(cli: Cli) -> Result<Option<Wallet>, Error> {

let snapshot_path = Path::new(&init_params.stronghold_snapshot_path);
if !snapshot_path.exists() {
if enter_decision("Create a new wallet with default parameters?")? {
if enter_decision("Create a new wallet with default parameters?", "yes")? {
Some(init_command(storage_path, init_params).await?)
} else {
Cli::print_help()?;
Expand Down Expand Up @@ -385,7 +385,7 @@ pub async fn init_command(storage_path: &Path, init_params: InitParameters) -> R
let mut address = init_params.address.map(|s| Bech32Address::from_str(&s)).transpose()?;
let mut forced = false;
if address.is_none() {
if enter_decision("Do you want to set the address of the new wallet?")? {
if enter_decision("Do you want to set the address of the new wallet?", "no")? {
address.replace(enter_address()?);
} else {
forced = true;
Expand All @@ -394,14 +394,14 @@ pub async fn init_command(storage_path: &Path, init_params: InitParameters) -> R

let mut bip_path = init_params.bip_path;
if bip_path.is_none() {
if forced || enter_decision("Do you want to set the bip path of the new wallet?")? {
if forced || enter_decision("Do you want to set the bip path of the new wallet?", "yes")? {
bip_path.replace(select_or_enter_bip_path()?);
}
}

let mut alias = init_params.alias;
if alias.is_none() {
if enter_decision("Do you want to set an alias for the new wallet?")? {
if enter_decision("Do you want to set an alias for the new wallet?", "yes")? {
alias.replace(enter_alias()?);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ pub fn enter_password(prompt: &str, confirmation: bool) -> Result<Password, Erro
Ok(password.interact()?.into())
}

pub fn enter_decision(prompt: &str) -> Result<bool, Error> {
pub fn enter_decision(prompt: &str, default: &str) -> Result<bool, Error> {
loop {
let input = Input::<String>::new()
.with_prompt(prompt)
.default("yes".into())
.default(default.to_string())
.interact_text()?;

match input.to_lowercase().as_str() {
Expand Down

0 comments on commit 1f16abf

Please sign in to comment.