diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-11 00:54:30 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-11 00:54:30 +0200 |
| commit | 5c39e7cf284a1f6e9a1657f2deb44e359fc47eb8 (patch) | |
| tree | c64baa8d5866c8e339eaf660dd3f94f30a3f7d8a /crates/atuin-client/src/settings.rs | |
| parent | chore: Somewhat simplify sync code (diff) | |
| download | atuin-5c39e7cf284a1f6e9a1657f2deb44e359fc47eb8.zip | |
chore: Move everything into one big crate
That helps remove duplicated code and rustc/cargo will now also show
dead code correctly.
Diffstat (limited to '')
| -rw-r--r-- | crates/turtle/src/atuin_client/settings.rs (renamed from crates/atuin-client/src/settings.rs) | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/crates/atuin-client/src/settings.rs b/crates/turtle/src/atuin_client/settings.rs index 5fb65c17..b0ffc7c1 100644 --- a/crates/atuin-client/src/settings.rs +++ b/crates/turtle/src/atuin_client/settings.rs @@ -1,8 +1,8 @@ use std::{collections::HashMap, fmt, io::prelude::*, path::PathBuf, str::FromStr, sync::OnceLock}; use tokio::sync::OnceCell; -use atuin_common::record::HostId; -use atuin_common::utils; +use crate::atuin_common::record::HostId; +use crate::atuin_common::utils; use clap::ValueEnum; use config::{ Config, ConfigBuilder, Environment, File as ConfigFile, FileFormat, builder::DefaultState, @@ -16,11 +16,10 @@ use serde_with::DeserializeFromStr; use time::{OffsetDateTime, UtcOffset, format_description::FormatItem, macros::format_description}; pub const HISTORY_PAGE_SIZE: i64 = 100; -static EXAMPLE_CONFIG: &str = include_str!("../config.toml"); static DATA_DIR: OnceLock<PathBuf> = OnceLock::new(); static META_CONFIG: OnceLock<(String, f64)> = OnceLock::new(); -static META_STORE: OnceCell<crate::meta::MetaStore> = OnceCell::const_new(); +static META_STORE: OnceCell<crate::atuin_client::meta::MetaStore> = OnceCell::const_new(); pub(crate) mod meta; pub mod watcher; @@ -374,8 +373,8 @@ impl SyncAuth { /// Convert into the auth token type used by the API client. /// /// Returns an error with an actionable message for `NotLoggedIn`. - pub fn into_auth_token(self) -> Result<crate::api_client::AuthToken> { - use crate::api_client::AuthToken; + pub fn into_auth_token(self) -> Result<crate::atuin_client::api_client::AuthToken> { + use crate::atuin_client::api_client::AuthToken; match self { SyncAuth::Legacy { token } => Ok(AuthToken::Token(token)), SyncAuth::NotLoggedIn { reason } => Err(eyre!(reason)), @@ -1038,7 +1037,6 @@ pub struct Settings { pub timezone: Timezone, pub style: Style, pub auto_sync: bool, - pub update_check: bool, /// The sync address for atuin. pub sync_address: String, @@ -1144,18 +1142,18 @@ impl Settings { DATA_DIR .get() .cloned() - .unwrap_or_else(atuin_common::utils::data_dir) + .unwrap_or_else(crate::atuin_common::utils::data_dir) } // -- Meta store: lazily initialized on first access -- - pub async fn meta_store() -> Result<&'static crate::meta::MetaStore> { + pub async fn meta_store() -> Result<&'static crate::atuin_client::meta::MetaStore> { META_STORE .get_or_try_init(|| async { let (db_path, timeout) = META_CONFIG.get().ok_or_else(|| { eyre!("meta store config not set — Settings::new() has not been called") })?; - crate::meta::MetaStore::new(db_path, *timeout).await + crate::atuin_client::meta::MetaStore::new(db_path, *timeout).await }) .await } @@ -1240,7 +1238,7 @@ impl Settings { /// `AuthToken`. Callers that need to distinguish between auth states /// (e.g. to show different UI) should call `resolve_sync_auth` directly. #[cfg(feature = "sync")] - pub async fn sync_auth_token(&self) -> Result<crate::api_client::AuthToken> { + pub async fn sync_auth_token(&self) -> Result<crate::atuin_client::api_client::AuthToken> { self.resolve_sync_auth().await.into_auth_token() } @@ -1262,7 +1260,7 @@ impl Settings { } pub fn builder() -> Result<ConfigBuilder<DefaultState>> { - Self::builder_with_data_dir(&atuin_common::utils::data_dir()) + Self::builder_with_data_dir(&crate::atuin_common::utils::data_dir()) } fn builder_with_data_dir(data_dir: &std::path::Path) -> Result<ConfigBuilder<DefaultState>> { @@ -1271,9 +1269,9 @@ impl Settings { let kv_path = data_dir.join("kv.db"); let scripts_path = data_dir.join("scripts.db"); let ai_sessions_path = data_dir.join("ai_sessions.db"); - let socket_path = atuin_common::utils::runtime_dir().join("atuin.sock"); + let socket_path = crate::atuin_common::utils::runtime_dir().join("atuin.sock"); let pidfile_path = data_dir.join("atuin-daemon.pid"); - let logs_dir = atuin_common::utils::logs_dir(); + let logs_dir = crate::atuin_common::utils::logs_dir(); let key_path = data_dir.join("key"); let meta_path = data_dir.join("meta.db"); @@ -1286,7 +1284,6 @@ impl Settings { .set_default("dialect", "us")? .set_default("timezone", "local")? .set_default("auto_sync", true)? - .set_default("update_check", cfg!(feature = "check-update"))? .set_default("sync_address", "https://api.atuin.sh")? .set_default("sync_frequency", "5m")? .set_default("search_mode", "fuzzy")? @@ -1390,7 +1387,7 @@ impl Settings { } pub fn get_config_path() -> Result<PathBuf> { - let config_dir = atuin_common::utils::config_dir(); + let config_dir = crate::atuin_common::utils::config_dir(); create_dir_all(&config_dir) .wrap_err_with(|| format!("could not create dir {config_dir:?}"))?; @@ -1447,10 +1444,10 @@ impl Settings { .map_err(|e| eyre!("failed to expand data_dir path: {}", e))?; PathBuf::from(expanded.as_ref()) } - None => atuin_common::utils::data_dir(), + None => crate::atuin_common::utils::data_dir(), } } else { - atuin_common::utils::data_dir() + crate::atuin_common::utils::data_dir() }; DATA_DIR.set(effective_data_dir.clone()).ok(); @@ -1467,7 +1464,10 @@ impl Settings { config_builder.add_source(ConfigFile::new(config_file_str, FileFormat::Toml)) } else { let mut file = File::create(config_file).wrap_err("could not create config file")?; - file.write_all(EXAMPLE_CONFIG.as_bytes()) + + let config = config_builder.build_cloned()?; + // TODO(@bpeetz): Not so sure about this <2026-06-10> + file.write_all(config.cache.to_string().as_bytes()) .wrap_err("could not write default config file")?; config_builder @@ -1590,10 +1590,6 @@ impl Settings { .map_err(|e| eyre!("failed to expand path: {}", e)) } - pub fn example_config() -> &'static str { - EXAMPLE_CONFIG - } - pub fn paths_ok(&self) -> bool { let paths = [ &self.db_path, @@ -1766,7 +1762,7 @@ mod tests { assert_eq!(meta_db_path, custom_dir.join("meta.db").to_str().unwrap()); assert_eq!( daemon_socket_path, - atuin_common::utils::runtime_dir() + crate::atuin_common::utils::runtime_dir() .join("atuin.sock") .to_str() .unwrap() @@ -1783,7 +1779,7 @@ mod tests { #[test] fn effective_data_dir_returns_default_when_not_set() { let effective = super::Settings::effective_data_dir(); - let default = atuin_common::utils::data_dir(); + let default = crate::atuin_common::utils::data_dir(); assert!(effective.to_str().is_some()); assert!(effective.ends_with("atuin") || effective == default); |
