Skip to main content

zoi_cli/cmd/
telemetry.rs

1//! Telemetry command implementation.
2
3use anyhow::Result;
4use colored::Colorize;
5
6/// Telemetry subcommands.
7#[derive(Debug, Clone, Copy)]
8pub enum TelemetryCommand {
9    /// Show telemetry status.
10    Status,
11    /// Enable telemetry.
12    Enable,
13    /// Disable telemetry.
14    Disable
15}
16
17/// Run the telemetry command.
18///
19/// # Errors
20///
21/// Returns an error if the configuration cannot be read or written.
22pub fn run(cmd: TelemetryCommand) -> Result<()> {
23    match cmd {
24        TelemetryCommand::Status => {
25            let cfg = crate::pkg::config::read_config()?;
26            let status = if cfg.telemetry_enabled {
27                "Enabled".green()
28            } else {
29                "Disabled".yellow()
30            };
31            println!(
32                "{} telemetry is currently {}.",
33                "::".bold().blue(),
34                status
35            );
36
37            if cfg.telemetry_enabled {
38                let id = crate::pkg::telemetry::get_anonymous_id();
39                println!("Anonymous Client ID: {}", id.cyan());
40                println!(
41                    "\nThank you for helping us improve Zoi! We collect \
42                     minimal, anonymous data about:"
43                );
44                println!(
45                    "- {} (OS, Arch, Distro, Shell)",
46                    "Environment".bold()
47                );
48                println!("- {} (Action, Scope, Reason)", "Operations".bold());
49                println!(
50                    "- {} (Name, Version, Repo, License)",
51                    "Package Metadata".bold()
52                );
53            } else {
54                println!(
55                    "\nTelemetry is anonymous and helps us prioritize \
56                     features and platforms."
57                );
58                println!("Run 'zoi telemetry enable' to help the project.");
59            }
60        }
61        TelemetryCommand::Enable => {
62            let mut cfg = crate::pkg::config::read_user_config()?;
63
64            println!(
65                "{}",
66                "Notice: Enabling telemetry shares anonymous usage data to \
67                 help improve Zoi."
68                    .dimmed()
69            );
70            println!(
71                "{}",
72                "No personal data or IP addresses are ever collected.".dimmed()
73            );
74            println!(
75                "{} {}",
76                "Full Privacy Policy:".dimmed(),
77                "https://zillowe.qzz.io/legal/privacy".cyan()
78            );
79
80            cfg.telemetry_enabled = true;
81            crate::pkg::config::write_user_config(&cfg)?;
82            println!("{} telemetry enabled", "Success:".green());
83        }
84        TelemetryCommand::Disable => {
85            let mut cfg = crate::pkg::config::read_user_config()?;
86            cfg.telemetry_enabled = false;
87            crate::pkg::config::write_user_config(&cfg)?;
88            println!("{} telemetry disabled", "Success:".green());
89        }
90    }
91    Ok(())
92}