# `dragon` CLI reference The `dragon` executable is the entry point for running, compiling and editing Dragon programs. Its behaviour is chosen by the first argument (a script path, a subcommand, or a flag). ``` dragon [options] [args...] ``` --- ## Commands | Invocation | Effect | | --- | --- | | `dragon [args...]` | Run a Dragon script. Extra arguments are passed to the script as `argv`. | | `dragon --repl` | Start the interactive REPL. | | `dragon run` | Run the project described by `./package.json`. | | `dragon -c -o ` | Compile/bundle a script into an executable or library. | | `dragon --ide` | Launch the TurboDragon terminal IDE. | | `dragon -v`, `dragon --version` | Print version information and exit. | --- ## Running a script ```bash dragon hello.dgn dragon hello.dgn Alice 42 --verbose ``` * Input: a UTF-8 `.dgn` source file. * Output: whatever the program prints with `show` / `showln` on **stdout** (errors and diagnostics are reported on stderr, with the offending line highlighted). * Everything after the file name is delivered to the program as the `argv` list, so scripts can read their own command-line arguments. --- ## Interactive REPL ```bash dragon --repl ``` A persistent session: variables, functions and classes defined on one line stay available on the next. Type `exit` to quit. --- ## Running a project: `dragon run` ```bash dragon run ``` Looks for a `package.json` in the current directory and runs the file named by its `"main"` field (the `"entry"` field is accepted as an alias). ```json { "name": "my-dragon-app", "main": "src/main.dgn" } ``` Input format: a JSON object with a `name` and a `main`/`entry` path relative to the directory containing `package.json`. --- ## Compiling a script: `-c` / `-o` ```bash # Bundle a script (and everything it imports) into one distributable executable dragon -c input.dgn -o output # GUI/background mode: do not attach a console window on Windows dragon -c input.dgn -o output --window # Build a shared library instead of an executable dragon -c input.dgn -o output.dll --lib # .so / .dylib on Linux / macOS # (Experimental) transpile to C and build a native binary with gcc/clang/MSVC dragon -c input.dgn -o output --native # (Experimental) native shared library dragon -c input.dgn -o output --native --lib # Keep the intermediate generated C source when using --native dragon -c input.dgn -o output --native --keep-c ``` | Option | Meaning | | --- | --- | | `-c ` | Compile mode; the value is the input script. | | `-o ` | Output file name (omit the extension for an executable; add `.dll` / `.so` / `.dylib` with `--lib`). | | `--lib` | Produce a shared library that can be embedded in another application. | | `--native` | Experimental: build the program with your system C compiler instead of bundling it. Requires `gcc`, `clang`, or `cl` on `PATH`. | | `--keep-c` | With `--native`, leave the generated C source on disk for inspection. | | `--window` | Windows only: start without a console window (GUI/background application). | Notes: * Bundled executables are **self-contained**: the script plus everything it imports is packaged inside the single output file, which can be distributed to machines that do not have Dragon installed. * `--native` produces an ordinary platform binary built by your C compiler, which starts faster than a bundled script because no translation happens when the program is launched. --- ## TurboDragon IDE ```bash dragon --ide ``` A lightweight, keyboard-driven terminal editor/runner: edit a script and run it without leaving the terminal. --- ## Output formats summary | Mode | Artifact produced | | --- | --- | | run | none (program output on stdout) | | `--repl` | none (session state is in-memory) | | `-c ... -o out` | `out` (native executable / bundled binary) | | `-c ... -o out --lib` | `out.dll` / `libout.so` / `out.dylib` | | `-c ... -o out --native` | platform executable built by the system C compiler | | `-c ... -o out --native --keep-c` | executable + retained generated C source |