diff options
Diffstat (limited to 'crates/mozart/src/commands/base_config.rs')
| -rw-r--r-- | crates/mozart/src/commands/base_config.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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<Self> { + 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), + }) + } +} |
