asimov_cli/commands/module/
list.rs1use crate::{BoxError, StandardOptions, SysexitsError::*};
4use color_print::cprintln;
5
6pub async fn list(output: String, _flags: &StandardOptions) -> Result<(), BoxError> {
7 let registry = asimov_registry::Registry::default();
8 let modules = registry.installed_modules().await.map_err(|e| {
9 tracing::error!("failed to read installed modules: {e}");
10 EX_UNAVAILABLE
11 })?;
12
13 for module in modules {
14 let name = module.manifest.name.parse()?;
15 let is_enabled = registry.is_module_enabled(&name).await.map_err(|e| {
16 tracing::error!("failed to check if module is enabled: {e}");
17 EX_UNAVAILABLE
18 })?;
19
20 match output.as_str() {
21 "jsonl" => {
22 let version = module.version.unwrap_or_default();
23 let label = module.manifest.label;
24 let uri = format!("https://asimov.directory/modules/{name}");
25 println!(
26 r#"{{"@type": "AsimovModule", "@id": "{}", "name": "{}", "label": "{}", "enabled": {}, "version": "{}"}}"#,
27 uri,
28 name,
29 label.unwrap_or_default(),
30 is_enabled,
31 version
32 );
33 },
34 _ => {
35 if is_enabled {
36 cprintln!("<s,g>✓</> {}", name);
37 } else {
38 cprintln!("<s,r>✗</> {}", name);
39 }
40 },
41 }
42 }
43
44 Ok(())
45}