From a703767da2a0dde01c4dcde8328bd3b406eb735b Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 26 Apr 2026 03:51:47 +0000 Subject: [PATCH] Absorb Config into Quire Config was a thin wrapper around repos_dir. Quire now owns all configuration directly and gains a config_path field, in preparation for the global config loader. Assisted-by: GLM-5.1 via pi --- src/bin/quire/main.rs | 3 +-- src/config.rs | 27 --------------------------- src/lib.rs | 2 -- src/quire.rs | 39 +++++++++++++++++++++++++++------------ 4 files changed, 28 insertions(+), 43 deletions(-) delete mode 100644 src/config.rs diff --git a/src/bin/quire/main.rs b/src/bin/quire/main.rs index 26d7f19..9fe3e8a 100644 --- a/src/bin/quire/main.rs +++ b/src/bin/quire/main.rs @@ -4,7 +4,6 @@ use clap::{CommandFactory, Parser, Subcommand}; use clap_complete::Shell; use miette::IntoDiagnostic; use miette::Result; -use quire::Config; use quire::Quire; use tracing_subscriber::EnvFilter; use tracing_subscriber::fmt; @@ -89,7 +88,7 @@ async fn main() -> Result<()> { return Ok(()); }; - let quire = Quire::new(Config::default()); + let quire = Quire::default(); match command { Commands::Serve => commands::serve::run(&quire).await?, diff --git a/src/config.rs b/src/config.rs deleted file mode 100644 index a4ad745..0000000 --- a/src/config.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::path::PathBuf; - -/// Application configuration. -#[derive(Debug, Clone)] -pub struct Config { - /// Root directory containing bare Git repositories. - pub repos_dir: PathBuf, -} - -impl Default for Config { - fn default() -> Self { - Self { - repos_dir: PathBuf::from("/var/quire/repos"), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn default_repos_dir() { - let config = Config::default(); - assert_eq!(config.repos_dir, PathBuf::from("/var/quire/repos")); - } -} diff --git a/src/lib.rs b/src/lib.rs index 08f4448..a9610e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,8 @@ -mod config; mod error; pub mod fennel; pub mod quire; pub mod secret; -pub use config::Config; pub use error::Error; pub use error::Result; pub use quire::Quire; diff --git a/src/quire.rs b/src/quire.rs index 6227fb2..04c2277 100644 --- a/src/quire.rs +++ b/src/quire.rs @@ -2,8 +2,6 @@ use std::path::{Path, PathBuf}; use miette::{IntoDiagnostic, Result, ensure}; -use crate::config::Config; - /// A resolved repository path. /// /// Created by `Quire::repo` after validating the name. @@ -24,18 +22,28 @@ impl Repo { /// Application runtime context. /// /// Carries configuration and provides resolved paths to repositories. -/// Commands receive a `&Quire` instead of threading `&Config` around. +/// Commands receive a `&Quire` instead of threading config around. pub struct Quire { - config: Config, + repos_dir: PathBuf, + config_path: PathBuf, } -impl Quire { - pub fn new(config: Config) -> Self { - Self { config } +impl Default for Quire { + fn default() -> Self { + Self { + repos_dir: PathBuf::from("/var/quire/repos"), + config_path: PathBuf::from("/var/quire/config.fnl"), + } } +} +impl Quire { pub fn repos_dir(&self) -> &Path { - &self.config.repos_dir + &self.repos_dir + } + + pub fn config_path(&self) -> &Path { + &self.config_path } /// Validate a repository name and return its resolved path. @@ -45,13 +53,13 @@ impl Quire { pub fn repo(&self, name: &str) -> Result { validate_repo_name(name)?; Ok(Repo { - path: self.config.repos_dir.join(name), + path: self.repos_dir.join(name), }) } /// List all repository names under the repos directory. pub fn repos(&self) -> Result + '_> { - let entries = fs_err::read_dir(&self.config.repos_dir).into_diagnostic()?; + let entries = fs_err::read_dir(&self.repos_dir).into_diagnostic()?; let mut repos: Vec = Vec::new(); for entry in entries { @@ -62,7 +70,7 @@ impl Quire { continue; } - let Ok(relative) = path.strip_prefix(&self.config.repos_dir) else { + let Ok(relative) = path.strip_prefix(&self.repos_dir) else { continue; }; let name = relative.to_string_lossy(); @@ -129,7 +137,14 @@ mod tests { use super::*; fn quire() -> Quire { - Quire::new(Config::default()) + Quire::default() + } + + #[test] + fn default_paths() { + let q = Quire::default(); + assert_eq!(q.repos_dir(), Path::new("/var/quire/repos")); + assert_eq!(q.config_path(), Path::new("/var/quire/config.fnl")); } #[test] -- 2.54.0