zoi/cmd/package/
install.rs

1use crate::cli::SetupScope;
2use anyhow::Result;
3use clap::Parser;
4use std::path::PathBuf;
5
6#[derive(Parser, Debug)]
7pub struct InstallCommand {
8    /// Path to the package archive file (e.g. path/to/name-os-arch.pkg.tar.zst)
9    #[arg(required = true)]
10    pub package_file: PathBuf,
11    /// The sub-packages to install from the archive.
12    #[arg(long, short, num_args = 1..)]
13    pub sub: Option<Vec<String>>,
14    /// The scope to install the package to (user or system-wide)
15    #[arg(long, value_enum, default_value_t = SetupScope::User)]
16    pub scope: SetupScope,
17    /// Automatically answer yes to all prompts
18    #[arg(long)]
19    pub yes: bool,
20}
21
22pub fn run(args: InstallCommand) -> Result<()> {
23    let scope = match args.scope {
24        SetupScope::User => crate::pkg::types::Scope::User,
25        SetupScope::System => crate::pkg::types::Scope::System,
26    };
27    crate::pkg::package::install::run(
28        &args.package_file,
29        Some(scope),
30        "local",
31        None,
32        args.yes,
33        args.sub,
34    )?;
35    Ok(())
36}