Skip to main content

zoi_cli/cmd/package/
install.rs

1//! Installation of package archive files.
2
3use std::path::PathBuf;
4
5use anyhow::Result;
6use clap::Parser;
7
8use crate::cli::SetupScope;
9
10/// Command to install a package from a `.zpa` archive file.
11#[derive(Parser, Debug)]
12pub struct InstallCommand {
13    /// Path to the package archive file (e.g. path/to/name-os-arch.zpa)
14    #[arg(required = true)]
15    pub package_file: PathBuf,
16    /// The sub-packages to install from the archive.
17    #[arg(long, short, num_args = 1..)]
18    pub sub: Option<Vec<String>>,
19    /// The scope to install the package to (user or system-wide)
20    #[arg(long, value_enum, default_value_t = SetupScope::User)]
21    pub scope: SetupScope,
22    /// Automatically answer yes to all prompts
23    #[arg(long)]
24    pub yes: bool
25}
26
27/// Runs the package installation command.
28///
29/// This installs a package from a local `.zpa` archive into the specified
30/// scope.
31///
32/// # Errors
33///
34/// Returns an error if the package file cannot be read, if dependencies cannot
35/// be resolved, or if the installation fails.
36pub fn run(args: InstallCommand) -> Result<()> {
37    let scope = match args.scope {
38        SetupScope::User => crate::pkg::types::Scope::User,
39        SetupScope::System => crate::pkg::types::Scope::System
40    };
41    crate::pkg::install::pkg_install::run(
42        &args.package_file,
43        Some(scope),
44        "local",
45        None,
46        args.yes,
47        args.sub,
48        true,
49        None
50    )?;
51    Ok(())
52}