Skip to main content

lux_cli/
install_lua.rs

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