Skip to main content

lux_cli/
install_lua.rs

1use std::path::Path;
2
3use lux_lib::{config::Config, lua};
4
5use miette::{miette, Result};
6
7pub async fn install_lua(config: Config) -> Result<()> {
8    let version = lua::Version::from(&config)?;
9
10    // TODO: Detect when path already exists by checking `Lua::path()` and prompt the user
11    // whether they'd like to forcefully reinstall.
12    let lua = lua::Installation::install(version, &config).await?;
13    let lua_root = match version {
14        lua::Version::Luau => lua
15            .bin()
16            .as_ref()
17            .and_then(|bin| bin.parent())
18            .map(Path::to_path_buf),
19        _ => lua
20            .includes()
21            .first()
22            .and_then(|dir| dir.parent())
23            .map(Path::to_path_buf),
24    }
25    .ok_or_else(|| {
26        miette!(
27            help = "ensure that pkg-config is installed and configured, and that you have Lua installed",
28            "error getting the lua installation root directory"
29        )
30    })?;
31
32    tracing::info!("Installed Lua ({}) to {}", version, lua_root.display());
33
34    Ok(())
35}