Skip to main content

lux_cli/
install.rs

1use eyre::Result;
2use lux_lib::{
3    config::Config, lockfile::PinnedState, lua_version::LuaVersion, operations,
4    package::PackageReq, progress::MultiProgress,
5};
6
7use crate::utils::install::apply_build_behaviour;
8
9#[derive(clap::Args)]
10pub struct Install {
11    /// Package or list of packages to install.
12    package_req: Vec<PackageReq>,
13
14    /// Pin the packages so that they don't get updated.
15    #[arg(long)]
16    pin: bool,
17
18    /// Reinstall without prompt if a package is already installed.
19    #[arg(long)]
20    force: bool,
21}
22
23/// Install a rock into the user tree.
24pub async fn install(data: Install, config: Config) -> Result<()> {
25    let pin = PinnedState::from(data.pin);
26
27    let lua_version = LuaVersion::from(&config)?.clone();
28    let tree = config.user_tree(lua_version)?;
29
30    let packages = apply_build_behaviour(data.package_req, pin, data.force, &tree)?;
31
32    // TODO(vhyrro): If the tree doesn't exist then error out.
33    operations::Install::new(&config)
34        .packages(packages)
35        .tree(tree)
36        .progress(MultiProgress::new_arc(&config))
37        .install()
38        .await?;
39
40    Ok(())
41}