Skip to main content

nodejs/
cli.rs

1//! Command-line interface for the `node` binary.
2
3use clap::Parser;
4
5#[derive(Parser, Debug)]
6#[command(
7    name = "node",
8    version,
9    about = "JavaScript on fusevm — a compiled JS runtime (bytecode VM + Cranelift JIT)",
10    long_about = None,
11)]
12pub struct Cli {
13    /// Evaluate a one-liner instead of a file (`node -e 'console.log(1+1)'`).
14    #[arg(short = 'e', long = "eval", value_name = "SRC")]
15    pub eval: Option<String>,
16
17    /// Start the interactive REPL.
18    #[arg(long = "repl")]
19    pub repl: bool,
20
21    /// Speak the Language Server Protocol over stdio.
22    #[arg(long = "lsp")]
23    pub lsp: bool,
24
25    /// Speak the Debug Adapter Protocol over stdio.
26    #[arg(long = "dap")]
27    pub dap: bool,
28
29    /// Ahead-of-time compile the script to a standalone native executable.
30    #[arg(long = "build")]
31    pub build: bool,
32
33    /// Print the compiled fusevm bytecode for the script and exit.
34    #[arg(long = "dump-bytecode")]
35    pub dump_bytecode: bool,
36
37    /// Print the lexer token stream for the script and exit.
38    #[arg(long = "dump-tokens")]
39    pub dump_tokens: bool,
40
41    /// Print the parsed AST for the script and exit.
42    #[arg(long = "dump-ast")]
43    pub dump_ast: bool,
44
45    /// Print a fusevm bytecode disassembly listing for the script and exit.
46    #[arg(long = "disasm")]
47    pub disasm: bool,
48
49    /// Run the script, then report which fusevm tiers took each of its chunks.
50    #[arg(long = "tiers")]
51    pub tiers: bool,
52
53    /// The `.js` script to run (omit with --repl / --lsp / --dap / -e).
54    #[arg(value_name = "FILE")]
55    pub file: Option<String>,
56
57    /// Arguments passed through to the JS program.
58    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
59    pub argv: Vec<String>,
60}
61
62/// Parse the process arguments.
63pub fn parse() -> Cli {
64    Cli::parse()
65}