use std::collections::BTreeSet;
use serde_json::Value as Json;
use shep_core::paths::ShepPaths;
use crate::commands::dogs::{DogSchema, ManifestRead, VERSION_BUDGET, ask_schema, read_manifest};
use crate::commands::shep_toml::ShepToml;
use crate::dog::builtin_schema;
pub(super) fn known_dogs(paths: &ShepPaths) -> BTreeSet<String> {
let from_file = ShepToml::read_only(&paths.daemon_config)
.map(|doc| {
doc.adopted_dog_names()
.into_iter()
.chain(doc.enabled_dog_names())
.collect::<Vec<_>>()
})
.unwrap_or_default();
crate::dog::BUILT_IN_DOGS
.iter()
.map(|name| (*name).to_string())
.chain(from_file)
.collect()
}
pub(super) fn dog_schema(name: &str, paths: &ShepPaths) -> Option<Json> {
if let Some(schema) = builtin_schema(name) {
return Some(schema);
}
let adopted = ShepToml::read_only(&paths.daemon_config)
.ok()
.and_then(|doc| doc.adopted_dog_path(name));
let path = adopted?;
if let Ok(ManifestRead::Read(manifest)) =
read_manifest(&path, &paths.home, name, VERSION_BUDGET)
{
return manifest.settings;
}
match ask_schema(&path, &paths.home, name, VERSION_BUDGET) {
DogSchema::Published(schema) => Some(schema),
DogSchema::Silent | DogSchema::Unreadable => None,
}
}