Skip to main content

lux_cli/
run.rs

1use std::path::PathBuf;
2
3use clap::Args;
4use eyre::Result;
5use lux_lib::{config::Config, operations, project::Project};
6
7use crate::build::{self, Build};
8
9#[derive(Args)]
10pub struct Run {
11    args: Vec<String>,
12
13    /// Do not add `require('lux').loader()` to `LUA_INIT`.{n}
14    /// If a rock has conflicting transitive dependencies,{n}
15    /// disabling the Lux loader may result in the wrong modules being loaded.
16    #[clap(default_value_t = false)]
17    #[arg(long)]
18    no_loader: bool,
19
20    /// Path in which to run the command.{n}
21    /// Defaults to the project root.
22    #[arg(long)]
23    dir: Option<PathBuf>,
24
25    #[clap(flatten)]
26    build: Build,
27}
28
29pub async fn run(run_args: Run, config: Config) -> Result<()> {
30    let project = Project::current_or_err()?;
31
32    build::build(run_args.build, config.clone()).await?;
33
34    operations::Run::new()
35        .project(&project)
36        .args(&run_args.args)
37        .config(&config)
38        .disable_loader(run_args.no_loader)
39        .run()
40        .await?;
41
42    Ok(())
43}