Skip to main content

lux_cli/
install.rs

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