1use std::env;
2
3use clap::Args;
4use eyre::Result;
5use lux_lib::{
6 config::Config, lua_version::LuaVersion, operations, path::Paths, workspace::Workspace,
7};
8
9#[derive(Args)]
10pub struct Exec {
11 command: String,
13
14 args: Option<Vec<String>>,
16
17 #[clap(default_value_t = false)]
21 #[arg(long)]
22 no_loader: bool,
23}
24
25pub async fn exec(run: Exec, config: Config) -> Result<()> {
26 let workspace = Workspace::current()?;
27 let tree = match &workspace {
28 Some(project) => project.tree(&config)?,
29 None => {
30 let lua_version = LuaVersion::from(&config)?.clone();
31 config.user_tree(lua_version)?
32 }
33 };
34
35 let paths = Paths::new(&tree)?;
36 unsafe {
37 env::set_var("PATH", paths.path_prepended().joined());
39 }
40 operations::Exec::new(&run.command, workspace.as_ref(), &config)
41 .args(run.args.unwrap_or_default())
42 .disable_loader(run.no_loader)
43 .exec()
44 .await?;
45 Ok(())
46}