diff --git a/src/cli/cmd/init/prompt.rs b/src/cli/cmd/init/prompt.rs index f56d48f1..7921eb95 100644 --- a/src/cli/cmd/init/prompt.rs +++ b/src/cli/cmd/init/prompt.rs @@ -2,7 +2,7 @@ use std::{fmt::Display, process::exit}; use inquire::{ ui::{Color, RenderConfig, StyleSheet, Styled}, - Confirm, MultiSelect, Select, Text, + Confirm, MultiSelect, Password, Select, Text, }; use once_cell::sync::Lazy; @@ -102,6 +102,25 @@ impl Prompt { } } + // Prompts for a FlakeHub token without confirmation. + pub(crate) fn maybe_token(msg: &str) -> Option { + let result = Password::new(msg) + .with_render_config(*PROMPT_CONFIG) + .without_confirmation() + .prompt(); + + match result { + Ok(s) => { + if s.is_empty() { + None + } else { + Some(s) + } + } + Err(_) => exit(1), + } + } + pub(crate) fn for_language(lang: &str) -> bool { Self::bool(&format!("This seems to be a {lang} project. Would you like to initialize your flake with some standard dependencies for {lang}?")) } diff --git a/src/cli/cmd/login/mod.rs b/src/cli/cmd/login/mod.rs index e6def215..3dfe2a97 100644 --- a/src/cli/cmd/login/mod.rs +++ b/src/cli/cmd/login/mod.rs @@ -41,7 +41,7 @@ impl LoginSubcommand { println!("And then follow the prompts below:"); println!(); - let token = crate::cli::cmd::init::prompt::Prompt::maybe_string("Paste your token here:"); + let token = crate::cli::cmd::init::prompt::Prompt::maybe_token("Paste your token here:"); let (token, status) = match token { Some(token) => { // This serves as validating that provided token is actually a JWT, and is valid.