From 213fb25686ac0aeb8a4f29c24897285d33f78e46 Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Wed, 23 Apr 2025 11:56:55 -0400 Subject: [PATCH] feat: Use inquire::Confirm instead of raw std::io::Read for K8sAnywhere installation confirmation prompt --- Cargo.lock | 1 + Cargo.toml | 1 + harmony/Cargo.toml | 1 + harmony/src/domain/topology/k8s_anywhere.rs | 17 ++++++----------- harmony_cli/Cargo.toml | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00a9b0e..8020fb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1344,6 +1344,7 @@ dependencies = [ "harmony_macros", "harmony_types", "http 1.3.1", + "inquire", "k8s-openapi", "kube", "libredfish", diff --git a/Cargo.toml b/Cargo.toml index 7219d71..48fe426 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ k8s-openapi = { version = "0.24.0", features = ["v1_30"] } serde_yaml = "0.9.34" serde-value = "0.7.0" http = "1.2.0" +inquire = "0.7.5" [workspace.dependencies.uuid] version = "1.11.0" diff --git a/harmony/Cargo.toml b/harmony/Cargo.toml index c5348d9..a5d53d1 100644 --- a/harmony/Cargo.toml +++ b/harmony/Cargo.toml @@ -30,3 +30,4 @@ k8s-openapi = { workspace = true } serde_yaml = { workspace = true } http = { workspace = true } serde-value = { workspace = true } +inquire.workspace = true diff --git a/harmony/src/domain/topology/k8s_anywhere.rs b/harmony/src/domain/topology/k8s_anywhere.rs index 2ba5a72..b1d5390 100644 --- a/harmony/src/domain/topology/k8s_anywhere.rs +++ b/harmony/src/domain/topology/k8s_anywhere.rs @@ -1,6 +1,7 @@ use std::io; use async_trait::async_trait; +use inquire::Confirm; use log::{info, warn}; use tokio::sync::OnceCell; @@ -76,18 +77,12 @@ impl K8sAnywhereTopology { info!("No kubernetes configuration found"); if !k8s_anywhere_config.autoinstall { - info!( - "Harmony autoinstallation is not activated, do you wish to launch autoinstallation? (y/N) : " - ); - let mut input = String::new(); + let confirmation = Confirm::new( "Harmony autoinstallation is not activated, do you wish to launch autoinstallation? : ") + .with_default(false) + .prompt() + .expect("Unexpected prompt error"); - io::stdin() - .read_line(&mut input) - .expect("Failed to read line"); - - let input = input.trim(); - - if !input.eq_ignore_ascii_case("y") { + if !confirmation { warn!( "Installation cancelled, K8sAnywhere could not initialize a valid Kubernetes client" ); diff --git a/harmony_cli/Cargo.toml b/harmony_cli/Cargo.toml index ad681bd..9d92103 100644 --- a/harmony_cli/Cargo.toml +++ b/harmony_cli/Cargo.toml @@ -10,7 +10,7 @@ assert_cmd = "2.0.17" clap = { version = "4.5.35", features = ["derive"] } harmony = { path = "../harmony" } harmony_tui = { path = "../harmony_tui", optional = true } -inquire = "0.7.5" +inquire.workspace = true tokio.workspace = true