blob: be663d56ff727627d4559a6b50fca697475ebbe3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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),
})
}
}
|