Skip to main content

asimov_cli/commands/module/
enable.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::{BoxError, StandardOptions, SysexitsError::*};
4use asimov_module::ModuleName;
5use color_print::cprintln;
6
7pub async fn enable(
8    module_names: Vec<ModuleName>,
9    flags: &StandardOptions,
10) -> Result<(), BoxError> {
11    let registry = asimov_registry::Registry::default();
12    for module_name in module_names {
13        if flags.verbose > 1 {
14            cprintln!("<s,c>»</> Enabling module <s>{module_name}</>...");
15        }
16
17        registry.enable_module(&module_name).await.map_err(|e| {
18            tracing::error!("failed to enable module `{module_name}`: {e}");
19            EX_UNAVAILABLE
20        })?;
21
22        if flags.verbose > 0 {
23            cprintln!("<s,g>✓</> Enabled module <s>{module_name}</>.");
24        }
25    }
26    Ok(())
27}