From eeb845f2f8629e3ccfb8ee1a1ec0602c0f186427 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 8 May 2026 23:03:11 +0900 Subject: fix(repository): align with Composer's RepositoryCommand pipeline Introduce JsonConfigSource in mozart-core mirroring Composer's JsonConfigSource fallback logic (add/insert/set-url/remove repository), and BaseConfigContext mirroring BaseConfigCommand's initialize(). Key behaviour fixes: - list: synthesise [packagist.org] only when no composer-type repo with a packagist.org host is present (was: always show enabled default) - disable: idempotent via add_repository(false) matching Composer's branch; now requires a name (no silent default to packagist.org) - enable: calls remove_repository only, no extra empty-array cleanup - set-url: preserves assoc-keyed format instead of converting to list - get-url: assoc fast-path + unquoted error message matching Composer - add: use regex pre-check (starts_with '{') instead of trial-parse - error messages reworded to match Composer verbatim (mozart brand kept) Co-Authored-By: Claude Sonnet 4.6 --- crates/mozart/src/commands/base_config.rs | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 crates/mozart/src/commands/base_config.rs (limited to 'crates/mozart/src/commands/base_config.rs') diff --git a/crates/mozart/src/commands/base_config.rs b/crates/mozart/src/commands/base_config.rs new file mode 100644 index 0000000..be663d5 --- /dev/null +++ b/crates/mozart/src/commands/base_config.rs @@ -0,0 +1,35 @@ +use std::path::PathBuf; + +use mozart_core::config_source::JsonConfigSource; + +use super::config_helpers::composer_home; + +/// Mirrors Composer's `BaseConfigCommand`: resolves the target config file path +/// and enforces the `--file` ↔ `--global` mutual exclusivity. +pub(crate) struct BaseConfigContext { + pub config_source: JsonConfigSource, +} + +impl BaseConfigContext { + pub fn initialize( + global: bool, + file: Option<&str>, + cli: &super::Cli, + ) -> anyhow::Result { + if global && file.is_some() { + anyhow::bail!("--file and --global can not be combined"); + } + + let path: PathBuf = if global { + composer_home().join("config.json") + } else if let Some(f) = file { + PathBuf::from(f) + } else { + cli.working_dir()?.join("composer.json") + }; + + Ok(Self { + config_source: JsonConfigSource::new(path, false), + }) + } +} -- cgit v1.3.1