aether_cli/
settings_args.rs1use aether_project::{AetherSettings, AetherSettingsSource, AgentCatalog, SettingsError, SettingsFileSource};
2use std::path::{Path, PathBuf};
3
4#[derive(Clone, Debug, Default, clap::Args)]
5pub struct SettingsSourceArgs {
6 #[arg(long = "settings-json", conflicts_with = "settings_file")]
7 pub settings_json: Option<String>,
8
9 #[arg(long = "settings-file", conflicts_with = "settings_json")]
10 pub settings_file: Option<PathBuf>,
11}
12
13impl SettingsSourceArgs {
14 pub fn source(&self, root: &Path) -> Option<AetherSettingsSource> {
15 if let Some(json) = &self.settings_json {
16 Some(AetherSettingsSource::Json(json.clone()))
17 } else {
18 self.settings_file
19 .as_ref()
20 .map(|path| AetherSettingsSource::File(SettingsFileSource::new(path.clone(), root)))
21 }
22 }
23
24 pub fn load_settings(&self, cwd: &Path) -> Result<AetherSettings, SettingsError> {
25 match self.source(cwd) {
26 Some(source) => AetherSettings::load(cwd, [source]),
27 None => AetherSettings::load_default(cwd),
28 }
29 }
30
31 pub fn load_agent_catalog(&self, cwd: &Path) -> Result<AgentCatalog, SettingsError> {
32 let settings = self.load_settings(cwd)?;
33 if settings.agents.is_empty() {
34 Ok(AgentCatalog::empty(cwd.to_path_buf()))
35 } else {
36 AgentCatalog::from_settings(cwd, settings)
37 }
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn settings_json_maps_to_json_source() {
47 let args = SettingsSourceArgs { settings_json: Some("{\"agents\":[]}".to_string()), settings_file: None };
48
49 let Some(AetherSettingsSource::Json(json)) = args.source(Path::new(".")) else {
50 panic!("expected JSON settings source");
51 };
52 assert_eq!(json, "{\"agents\":[]}");
53 }
54
55 #[test]
56 fn settings_file_maps_to_file_source() {
57 let args = SettingsSourceArgs { settings_json: None, settings_file: Some(PathBuf::from("settings.json")) };
58
59 let Some(AetherSettingsSource::File(source)) = args.source(Path::new("/workspace")) else {
60 panic!("expected file settings source");
61 };
62 assert_eq!(source, SettingsFileSource::new("settings.json", "/workspace"));
63 }
64}