Skip to content

Commit f5d2995

Browse files
committed
refactor: use existing Env abstraction for Q-specific environment variables
- Add missing environment variable constants (Q_LOG_STDOUT, Q_DISABLE_TELEMETRY, AMAZON_Q_CHAT_SHELL) - Update Env methods to use constants instead of hardcoded strings - Add q_disable_telemetry() method to Env - Update telemetry module to use new Env method instead of direct access - Use existing Env abstraction instead of creating wrapper functions around std::env.
1 parent ac90afd commit f5d2995

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

crates/chat-cli/src/os/env.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::sync::{
1515
};
1616

1717
use crate::os::ACTIVE_USER_HOME;
18+
use crate::util::consts::env_var;
1819

1920
#[derive(Debug, Clone)]
2021
pub struct Env(inner::Inner);
@@ -165,35 +166,40 @@ impl Env {
165166
}
166167

167168
pub fn q_log_level(&self) -> Result<String, VarError> {
168-
self.get("Q_LOG_LEVEL")
169+
self.get(env_var::Q_LOG_LEVEL)
169170
}
170171

171172
pub fn q_log_stdout(&self) -> bool {
172-
self.get_os("Q_LOG_STDOUT").is_some()
173+
self.get_os(env_var::Q_LOG_STDOUT).is_some()
174+
}
175+
176+
pub fn q_disable_telemetry(&self) -> bool {
177+
self.get_os(env_var::Q_DISABLE_TELEMETRY).is_some()
173178
}
174179

175180
pub fn amazon_q_sigv4(&self) -> bool {
176181
self.get("AMAZON_Q_SIGV4").is_ok_and(|v| !v.is_empty())
177182
}
178183

179184
pub fn amazon_q_chat_shell(&self) -> String {
180-
self.get("AMAZON_Q_CHAT_SHELL").unwrap_or_else(|_| "bash".to_string())
185+
self.get(env_var::AMAZON_Q_CHAT_SHELL)
186+
.unwrap_or_else(|_| "bash".to_string())
181187
}
182188

183189
pub fn q_cli_client_application(&self) -> Result<String, VarError> {
184-
self.get("Q_CLI_CLIENT_APPLICATION")
190+
self.get(env_var::Q_CLI_CLIENT_APPLICATION)
185191
}
186192

187193
pub fn q_parent(&self) -> Result<String, VarError> {
188-
self.get("Q_PARENT")
194+
self.get(env_var::Q_PARENT)
189195
}
190196

191197
pub fn q_term(&self) -> Result<String, VarError> {
192-
self.get("Q_TERM")
198+
self.get(env_var::Q_TERM)
193199
}
194200

195201
pub fn q_using_zsh_autosuggestions(&self) -> bool {
196-
self.get_os("Q_USING_ZSH_AUTOSUGGESTIONS").is_some()
202+
self.get_os(env_var::Q_USING_ZSH_AUTOSUGGESTIONS).is_some()
197203
}
198204

199205
pub fn q_init_snapshot_test(&self) -> bool {

crates/chat-cli/src/telemetry/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ struct TelemetryClient {
396396
impl TelemetryClient {
397397
async fn new(env: &Env, fs: &Fs, database: &mut Database) -> Result<Self, TelemetryError> {
398398
let telemetry_enabled = !cfg!(test)
399-
&& env.get_os("Q_DISABLE_TELEMETRY").is_none()
399+
&& !env.q_disable_telemetry()
400400
&& database.settings.get_bool(Setting::TelemetryEnabled).unwrap_or(true);
401401

402402
// If telemetry is disabled we do not emit using toolkit_telemetry

crates/chat-cli/src/util/consts.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ pub mod env_var {
6767
Q_BUNDLE_METADATA_PATH = "Q_BUNDLE_METADATA_PATH",
6868

6969
/// Identifier for the client application or service using the chat-cli
70-
Q_CLI_CLIENT_APPLICATION = "Q_CLI_CLIENT_APPLICATION"
70+
Q_CLI_CLIENT_APPLICATION = "Q_CLI_CLIENT_APPLICATION",
71+
72+
/// Enables logging to stdout
73+
Q_LOG_STDOUT = "Q_LOG_STDOUT",
74+
75+
/// Disables telemetry collection
76+
Q_DISABLE_TELEMETRY = "Q_DISABLE_TELEMETRY",
77+
78+
/// The shell to use for Amazon Q chat
79+
AMAZON_Q_CHAT_SHELL = "AMAZON_Q_CHAT_SHELL"
7180
}
7281
}
7382

0 commit comments

Comments
 (0)