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);
20    let lua_root = lua
21        .include_dir
22        .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}