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 ({})",
14        version_stringified
15    )));
16
17    // TODO: Detect when path already exists by checking `Lua::path()` and prompt the user
18    // whether they'd like to forcefully reinstall.
19    let lua = LuaInstallation::install(version_stringified, &config).await?;
20    let lua_root = lua
21        .includes()
22        .first()
23        .and_then(|dir| dir.parent())
24        .expect("error getting parent directory");
25
26    bar.finish_with_message(format!(
27        "🌔 Installed Lua ({}) to {}",
28        version_stringified,
29        lua_root.display()
30    ));
31
32    Ok(())
33}