lux_cli/
install_lua.rs

1use eyre::Result;
2use lux_lib::{
3    config::{Config, LuaVersion},
4    lua_installation::LuaInstallation,
5    progress::{MultiProgress, ProgressBar},
6};
7
8pub async fn install_lua(config: Config) -> Result<()> {
9    let version_stringified = &LuaVersion::from(&config)?;
10
11    let progress = MultiProgress::new();
12    let bar = progress.add(ProgressBar::from(format!(
13        "🌔 Installing Lua ({version_stringified})",
14    )));
15
16    // TODO: Detect when path already exists by checking `Lua::path()` and prompt the user
17    // whether they'd like to forcefully reinstall.
18    let lua = LuaInstallation::install(version_stringified, &config).await?;
19    let lua_root = lua
20        .includes()
21        .first()
22        .and_then(|dir| dir.parent())
23        .expect("error getting parent directory");
24
25    bar.finish_with_message(format!(
26        "🌔 Installed Lua ({}) to {}",
27        version_stringified,
28        lua_root.display()
29    ));
30
31    Ok(())
32}