Skip to content

Commit f59b224

Browse files
authored
refactor : consolidate env variables (#871)
feat(paths): centralize Amazon Q path management with PathResolver
1 parent 880bf57 commit f59b224

File tree

25 files changed

+124
-43
lines changed

25 files changed

+124
-43
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ book/
4949
.env*
5050

5151
run-build.sh
52+
# Amazon Q CLI files
53+
.amazonq/

Cargo.lock

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/alacritty_terminal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ workspace = true
1818
[dependencies]
1919
bitflags.workspace = true
2020
camino.workspace = true
21+
fig_os_shim.workspace = true
2122
serde.workspace = true
2223
serde_yaml = "0.9"
2324
shell-color.workspace = true

crates/alacritty_terminal/src/term/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ impl<T> Term<T> {
833833
trace!("New command cursor: {:?}", self.shell_state.cmd_cursor);
834834

835835
// Add work around for emojis
836-
if let Ok(cursor_offset) = std::env::var("Q_PROMPT_OFFSET_WORKAROUND") {
836+
if let Ok(cursor_offset) = fig_os_shim::Env::new().q_prompt_offset_workaround() {
837837
if let Ok(offset) = cursor_offset.parse::<i32>() {
838838
self.shell_state.cmd_cursor = self.shell_state.cmd_cursor.map(|cursor| Point {
839839
column: Column((cursor.column.0 as i32 - offset).max(0) as usize),

crates/fig_api_client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ aws-types.workspace = true
2727
bytes.workspace = true
2828
fig_auth.workspace = true
2929
fig_aws_common.workspace = true
30+
fig_os_shim.workspace = true
3031
fig_request.workspace = true
3132
fig_settings.workspace = true
3233
fig_util.workspace = true

crates/fig_api_client/src/clients/streaming_client.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ pub struct StreamingClient {
5858

5959
impl StreamingClient {
6060
pub async fn new() -> Result<Self, Error> {
61-
let client = if fig_util::system_info::in_cloudshell()
62-
|| std::env::var("Q_USE_SENDMESSAGE").is_ok_and(|v| !v.is_empty())
63-
{
61+
let client = if fig_util::system_info::in_cloudshell() || fig_os_shim::Env::new().q_use_sendmessage() {
6462
Self::new_qdeveloper_client(&Endpoint::load_q()).await?
6563
} else {
6664
Self::new_codewhisperer_client(&Endpoint::load_codewhisperer()).await

crates/fig_desktop/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ async fn main() -> ExitCode {
149149

150150
#[cfg(target_os = "linux")]
151151
{
152-
match std::env::var("Q_BACKEND").ok().as_deref() {
152+
match fig_os_shim::Env::new().q_backend().ok().as_deref() {
153153
Some("default") => {},
154154
// SAFETY: we are calling set_var in a single-threaded context.
155155
Some(backend) => unsafe { std::env::set_var("GDK_BACKEND", backend) },

crates/fig_install/src/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const DEFAULT_RELEASE_URL: &str = "https://desktop-release.q.us-east-1.amazonaws
4545
/// - The setting `install.releaseUrl`
4646
/// - Falls back to the default or the build time env var `Q_BUILD_DESKTOP_RELEASE_URL`
4747
static RELEASE_URL: LazyLock<Url> = LazyLock::new(|| {
48-
match std::env::var("Q_DESKTOP_RELEASE_URL") {
48+
match fig_os_shim::Env::new().q_desktop_release_url() {
4949
Ok(s) => Url::parse(&s),
5050
Err(_) => match fig_settings::settings::get_string("install.releaseUrl") {
5151
Ok(Some(s)) => Url::parse(&s),

crates/fig_log/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ default = []
1616
# sentry = ["dep:sentry-tracing"]
1717

1818
[dependencies]
19+
fig_os_shim.workspace = true
1920
fig_util.workspace = true
2021
parking_lot.workspace = true
2122
thiserror.workspace = true

crates/fig_log/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::path::Path;
33
use std::sync::Mutex;
44

55
use fig_util::CHAT_BINARY_NAME;
6-
use fig_util::env_var::Q_LOG_LEVEL;
76
use thiserror::Error;
87
use tracing::info;
98
use tracing::level_filters::LevelFilter;
@@ -192,11 +191,11 @@ pub fn initialize_logging<T: AsRef<Path>>(args: LogArgs<T>) -> Result<LogGuard,
192191
///
193192
/// Returns a string identifying the current log level.
194193
pub fn get_log_level() -> String {
195-
Q_LOG_LEVEL_GLOBAL
196-
.lock()
197-
.unwrap()
198-
.clone()
199-
.unwrap_or_else(|| std::env::var(Q_LOG_LEVEL).unwrap_or_else(|_| DEFAULT_FILTER.to_string()))
194+
Q_LOG_LEVEL_GLOBAL.lock().unwrap().clone().unwrap_or_else(|| {
195+
fig_os_shim::Env::new()
196+
.q_log_level()
197+
.unwrap_or_else(|_| DEFAULT_FILTER.to_string())
198+
})
200199
}
201200

202201
/// Set the log level to the given level.
@@ -247,7 +246,7 @@ fn create_filter_layer() -> EnvFilter {
247246
.lock()
248247
.unwrap()
249248
.clone()
250-
.or_else(|| std::env::var(Q_LOG_LEVEL).ok());
249+
.or_else(|| fig_os_shim::Env::new().q_log_level().ok());
251250

252251
match log_level {
253252
Some(level) => EnvFilter::builder()

0 commit comments

Comments
 (0)