Ask for permission in the CLI (#6475)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -24,22 +24,30 @@ static TELEMETRY_DISABLED_BY_ENV: Lazy<AtomicBool> = Lazy::new(|| {
|
||||
.into()
|
||||
});
|
||||
|
||||
/// Check if the user has made a telemetry choice.
|
||||
///
|
||||
/// Returns Some(true) if telemetry is enabled, Some(false) if disabled,
|
||||
/// or None if the user hasn't made a choice yet.
|
||||
pub fn get_telemetry_choice() -> Option<bool> {
|
||||
// If disabled by env var, treat as explicit choice to disable
|
||||
if TELEMETRY_DISABLED_BY_ENV.load(Ordering::Relaxed) {
|
||||
return Some(false);
|
||||
}
|
||||
|
||||
let config = Config::global();
|
||||
config.get_param::<bool>(TELEMETRY_ENABLED_KEY).ok()
|
||||
}
|
||||
|
||||
/// Check if telemetry is enabled.
|
||||
///
|
||||
/// Returns false if:
|
||||
/// - GOOSE_TELEMETRY_OFF environment variable is set to "1" or "true"
|
||||
/// - GOOSE_TELEMETRY_ENABLED config value is set to false
|
||||
/// - User has not made a telemetry choice yet (opt-in required)
|
||||
///
|
||||
/// Returns true otherwise (telemetry is opt-out, enabled by default)
|
||||
/// Returns true only if the user has explicitly opted in.
|
||||
pub fn is_telemetry_enabled() -> bool {
|
||||
if TELEMETRY_DISABLED_BY_ENV.load(Ordering::Relaxed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let config = Config::global();
|
||||
config
|
||||
.get_param::<bool>(TELEMETRY_ENABLED_KEY)
|
||||
.unwrap_or(true)
|
||||
get_telemetry_choice().unwrap_or(false)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user