Skip to main content

zoi_cli/cmd/install/
mod.rs

1/// Command-line arguments for the `install` command.
2pub mod args;
3/// High-level installation orchestration.
4pub mod orchestrator;
5
6use anyhow::Result;
7use zoi_project as project;
8
9use crate::pkg::types;
10
11/// The primary high-level orchestration for the `zoi install` command.
12///
13/// # Errors
14///
15/// Returns an error if the installation process fails.
16pub fn run(
17    sources: &[String],
18    repo: Option<String>,
19    force: bool,
20    all_optional: bool,
21    yes: bool,
22    scope: Option<crate::cli::InstallScope>,
23    local: bool,
24    global: bool,
25    save: bool,
26    build_type: Option<&str>,
27    dry_run: bool,
28    plugin_manager: Option<&crate::pkg::plugin::PluginManager>,
29    build: bool,
30    frozen: bool,
31    explain: bool,
32    plan_json: bool,
33    retry: u32,
34    verbose: bool,
35    purl: bool,
36    project_config: Option<project::config::ProjectConfig>
37) -> Result<()> {
38    if plan_json && !dry_run {
39        return Err(anyhow::anyhow!("--plan-json requires --dry-run"));
40    }
41    let mut resolved_scope = scope.map(|s| match s {
42        crate::cli::InstallScope::User => types::Scope::User,
43        crate::cli::InstallScope::System => types::Scope::System,
44        crate::cli::InstallScope::Project => types::Scope::Project
45    });
46
47    if local {
48        resolved_scope = Some(types::Scope::Project);
49    } else if global {
50        resolved_scope = Some(types::Scope::User);
51    }
52
53    let scope = resolved_scope
54        .unwrap_or_else(crate::pkg::utils::resolve_fallback_scope);
55
56    let options = orchestrator::InstallOptions {
57        scope,
58        force,
59        all_optional,
60        yes,
61        save,
62        build_type,
63        dry_run,
64        plugin_manager,
65        build,
66        frozen,
67        explain,
68        plan_json,
69        retry,
70        verbose,
71        purl,
72        project_config
73    };
74
75    let orchestrator = orchestrator::Orchestrator::new(options);
76    orchestrator.run(sources, repo)
77}