lux_cli/
install_lua.rs

1use eyre::Result;
2use lux_lib::{
3    config::{Config, LuaVersion},
4    lua_installation::LuaInstallation,
5    progress::{MultiProgress, Progress, 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::Progress(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, &bar).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.map(|bar| {
26        bar.finish_with_message(format!(
27            "🌔 Installed Lua ({}) to {}",
28            version_stringified,
29            lua_root.display()
30        ))
31    });
32
33    Ok(())
34}