Initial working version for a prompt for email

This commit is contained in:
Clément Renault 2025-06-05 10:54:46 +02:00
parent 5d0d12dfbd
commit 4d819ea636
No known key found for this signature in database
GPG key ID: F250A4C4E3AE5F5F
3 changed files with 40 additions and 1 deletions

View file

@ -21,6 +21,7 @@ use meilisearch::{
};
use meilisearch_auth::{generate_master_key, AuthController, MASTER_KEY_MIN_SIZE};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use tokio::io::{AsyncBufReadExt, BufReader};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::layer::SubscriberExt as _;
use tracing_subscriber::Layer;
@ -89,10 +90,16 @@ async fn main() -> anyhow::Result<()> {
}
async fn try_main() -> anyhow::Result<()> {
let (opt, config_read_from) = Opt::try_build()?;
let (mut opt, config_read_from) = Opt::try_build()?;
std::panic::set_hook(Box::new(on_panic));
opt.contact_email = match opt.contact_email.as_ref().map(|email| email.as_deref()) {
Some(Some("false")) | None => prompt_for_contact_email().await.map(Some)?,
Some(Some(email)) => Some(Some(email.to_string())),
Some(None) => None,
};
anyhow::ensure!(
!(cfg!(windows) && opt.experimental_reduce_indexing_memory_usage),
"The `experimental-reduce-indexing-memory-usage` flag is not supported on Windows"
@ -139,6 +146,27 @@ async fn try_main() -> anyhow::Result<()> {
Ok(())
}
/// Prompt the user about the contact email for support and news.
/// It only displays the prompt if the input is an interactive terminal.
async fn prompt_for_contact_email() -> anyhow::Result<Option<String>> {
let stdin = tokio::io::stdin();
if !stdin.is_terminal() {
return Ok(None);
}
println!("Would you mind providing your contact email for support and news?");
println!("We will use it to contact you with news only.");
print!("contact email> ");
std::io::stdout().flush()?;
let mut email = String::new();
let mut stdin = BufReader::new(stdin);
let _ = stdin.read_line(&mut email).await?;
Ok(Some(email.trim().to_string()))
}
async fn run_http(
index_scheduler: Arc<IndexScheduler>,
auth_controller: Arc<AuthController>,