asimov_cli/commands/module/
resolve.rs1use crate::{BoxError, StandardOptions, SysexitsError::*};
4use asimov_module::{normalization::normalize_url, resolve::Resolver};
5use color_print::cprintln;
6
7pub async fn resolve(url: impl AsRef<str>, _flags: &StandardOptions) -> Result<(), BoxError> {
8 let registry = asimov_registry::Registry::default();
9
10 let manifests = registry
11 .enabled_modules()
12 .await
13 .map_err(|e| {
14 tracing::error!("failed to get installed modules: {e}");
15 EX_UNAVAILABLE
16 })?
17 .into_iter()
18 .map(|manifest| manifest.manifest);
19
20 let resolver = Resolver::try_from_iter(manifests)
21 .inspect_err(|e| tracing::error!("failed to create resolver: {e}"))?;
22
23 let url = url.as_ref().to_string();
24 let url = normalize_url(&url)
25 .inspect_err(|e| {
26 tracing::error!("proceeding with given unmodified URL, normalization failed: {e}, ")
27 })
28 .unwrap_or(url);
29
30 let modules = resolver
31 .resolve(&url)
32 .inspect_err(|e| tracing::error!("failed to resolve modules for URL <s>{url}</>: {e}"))
33 .map_err(|_| EX_USAGE)?;
34
35 for module in modules {
36 cprintln!("{}", module.name);
37 }
38
39 Ok(())
40}