Make sure that we can also specify the no-analytics flags with a boolean

This commit is contained in:
Clément Renault 2021-12-08 11:23:16 +01:00
parent 9906db9e64
commit 8c9e51e94f
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 15 additions and 5 deletions

View File

@ -50,7 +50,7 @@ async fn main() -> anyhow::Result<()> {
let auth_controller = AuthController::new(&opt.db_path, &opt.master_key)?; let auth_controller = AuthController::new(&opt.db_path, &opt.master_key)?;
#[cfg(all(not(debug_assertions), feature = "analytics"))] #[cfg(all(not(debug_assertions), feature = "analytics"))]
let (analytics, user) = if !opt.no_analytics { let (analytics, user) = if opt.analytics() {
analytics::SegmentAnalytics::new(&opt, &meilisearch).await analytics::SegmentAnalytics::new(&opt, &meilisearch).await
} else { } else {
analytics::MockAnalytics::new(&opt) analytics::MockAnalytics::new(&opt)
@ -125,9 +125,7 @@ pub fn print_launch_resume(opt: &Opt, user: &str) {
#[cfg(all(not(debug_assertions), feature = "analytics"))] #[cfg(all(not(debug_assertions), feature = "analytics"))]
{ {
if opt.no_analytics { if opt.analytics() {
eprintln!("Anonymous telemetry:\t\"Disabled\"");
} else {
eprintln!( eprintln!(
" "
Thank you for using MeiliSearch! Thank you for using MeiliSearch!
@ -136,6 +134,8 @@ We collect anonymized analytics to improve our product and your experience. To l
Anonymous telemetry:\t\"Enabled\"" Anonymous telemetry:\t\"Enabled\""
); );
} else {
eprintln!("Anonymous telemetry:\t\"Disabled\"");
} }
} }

View File

@ -38,7 +38,7 @@ pub struct Opt {
/// Do not send analytics to Meili. /// Do not send analytics to Meili.
#[cfg(all(not(debug_assertions), feature = "analytics"))] #[cfg(all(not(debug_assertions), feature = "analytics"))]
#[structopt(long, env = "MEILI_NO_ANALYTICS")] #[structopt(long, env = "MEILI_NO_ANALYTICS")]
pub no_analytics: bool, pub no_analytics: Option<Option<bool>>,
/// The maximum size, in bytes, of the main lmdb database directory /// The maximum size, in bytes, of the main lmdb database directory
#[structopt(long, env = "MEILI_MAX_INDEX_SIZE", default_value = "100 GiB")] #[structopt(long, env = "MEILI_MAX_INDEX_SIZE", default_value = "100 GiB")]
@ -129,6 +129,16 @@ pub struct Opt {
} }
impl Opt { impl Opt {
/// Wether analytics should be enabled or not.
#[cfg(all(not(debug_assertions), feature = "analytics"))]
pub fn analytics(&self) -> bool {
match self.no_analytics {
None => true,
Some(None) => false,
Some(Some(disabled)) => !disabled,
}
}
pub fn get_ssl_config(&self) -> anyhow::Result<Option<rustls::ServerConfig>> { pub fn get_ssl_config(&self) -> anyhow::Result<Option<rustls::ServerConfig>> {
if let (Some(cert_path), Some(key_path)) = (&self.ssl_cert_path, &self.ssl_key_path) { if let (Some(cert_path), Some(key_path)) = (&self.ssl_cert_path, &self.ssl_key_path) {
let client_auth = match &self.ssl_auth_path { let client_auth = match &self.ssl_auth_path {