1use crate::config::Config;
4use anyhow::{Result, bail};
5
6pub use shine_core::runtime::parse_shell_lifecycle_target as parse_lifecycle_target;
7pub use shine_core::runtime::{ShellCategory, ShellFile, ShellTarget};
8
9pub async fn load_active_target(
10 config: &Config,
11 target: ShellTarget<'_>,
12) -> Result<Vec<ShellCategory>> {
13 let mut categories = load_active_categories(config, Some(target.category)).await?;
14 let Some(category) = categories.first_mut() else {
15 bail!("shell preset category not found: {}", target.category);
16 };
17 if let Some(command) = target.command {
18 category.files.retain(|file| file.command_name == command);
19 if category.files.is_empty() {
20 bail!(
21 "shell preset command not found: {}/{}",
22 target.category,
23 command
24 );
25 }
26 }
27 Ok(categories)
28}
29
30pub fn load_embedded_categories(filter: Option<&str>) -> Result<Vec<ShellCategory>> {
31 crate::core_runtime::from_embedded_presets().shell_categories(filter)
32}
33
34pub async fn load_installed_categories(
35 config: &Config,
36 filter: Option<&str>,
37) -> Result<Vec<ShellCategory>> {
38 crate::core_runtime::from_installed_presets(config)
39 .await?
40 .shell_categories(filter)
41}
42
43pub async fn load_active_categories(
44 config: &Config,
45 filter: Option<&str>,
46) -> Result<Vec<ShellCategory>> {
47 crate::core_runtime::from_config(config)
48 .await?
49 .shell_categories(filter)
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn embedded_metadata_is_parsed_by_core() {
58 let categories = load_embedded_categories(Some("proxy")).unwrap();
59 assert_eq!(categories.len(), 1);
60 assert_eq!(categories[0].name, "proxy");
61 assert!(!categories[0].files.is_empty());
62 }
63}