use eyre::Result;
use lux_lib::{
config::Config, lockfile::PinnedState, lua_version::LuaVersion, operations,
package::PackageReq, progress::MultiProgress,
};
use crate::utils::install::apply_build_behaviour;
#[derive(clap::Args)]
pub struct Install {
package_req: Vec<PackageReq>,
#[arg(long)]
pin: bool,
#[arg(long)]
force: bool,
}
pub async fn install(data: Install, config: Config) -> Result<()> {
let pin = PinnedState::from(data.pin);
let lua_version = LuaVersion::from(&config)?.clone();
let tree = config.user_tree(lua_version)?;
let packages = apply_build_behaviour(data.package_req, pin, data.force, &tree, &config)?;
operations::Install::new(&config)
.packages(packages)
.tree(tree)
.progress(MultiProgress::new_arc(&config))
.install()
.await?;
Ok(())
}