Skip to content

Commit 3e21370

Browse files
authored
feat(cli): handle only 1 file via the cli and handle other arguments in the runtime (#196)
the runtime
1 parent c797423 commit 3e21370

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

cli/src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@ struct Cli {
5454

5555
#[derive(Debug, Subcommand)]
5656
enum Command {
57-
/// Runs a file or files
57+
/// Runs a single file
5858
Run {
5959
#[arg(short, long)]
6060
verbose: bool,
6161

6262
#[arg(short, long)]
6363
no_strict: bool,
6464

65-
/// The files to run
65+
/// The file to run
6666
#[arg(required = true)]
67-
paths: Vec<String>,
67+
path: String,
68+
69+
/// Additional arguments (ignored by CLI, passed to Andromeda runtime)
70+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
71+
args: Vec<String>,
6872
},
6973

7074
/// Compiles a js file into a single-file executable
@@ -271,13 +275,15 @@ fn run_main() -> Result<()> {
271275
disable_gc: false,
272276
},
273277
}
274-
} else if raw_args.len() == 1 && raw_args[0].ends_with(".ts") {
275-
// If a single .ts file is provided, alias to `run file.ts`
278+
} else if !raw_args.is_empty() && raw_args[0].ends_with(".ts") {
279+
let path = raw_args[0].clone();
280+
let args = raw_args[1..].to_vec();
276281
Cli {
277282
command: Command::Run {
278283
verbose: false,
279284
no_strict: false,
280-
paths: vec![raw_args[0].clone()],
285+
path,
286+
args,
281287
},
282288
}
283289
} else {
@@ -302,13 +308,11 @@ fn run_main() -> Result<()> {
302308
Command::Run {
303309
verbose,
304310
no_strict,
305-
paths,
311+
path,
312+
args: _,
306313
} => {
307-
let runtime_files: Vec<RuntimeFile> = paths
308-
.into_iter()
309-
.map(|path| RuntimeFile::Local { path })
310-
.collect();
311-
run(verbose, no_strict, runtime_files)
314+
let runtime_file = RuntimeFile::Local { path };
315+
run(verbose, no_strict, vec![runtime_file])
312316
}
313317
Command::Compile {
314318
path,

cli/src/run.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use andromeda_runtime::{
1111
recommended_builtins, recommended_eventloop_handler, recommended_extensions,
1212
};
1313

14+
/// Run a single Andromeda file
15+
///
16+
/// Note: While this function accepts a Vec<RuntimeFile> for internal flexibility,
17+
/// the CLI interface only passes a single file.
1418
#[allow(clippy::result_large_err)]
1519
#[cfg_attr(feature = "hotpath", hotpath::measure)]
1620
pub fn run(verbose: bool, no_strict: bool, files: Vec<RuntimeFile>) -> Result<()> {

0 commit comments

Comments
 (0)