Build and Run Mech Programs
===============================================================================

The `mech` command-line tool provides various functionalities for working with Mech programs, including executing scripts, debugging, formatting code, and serving applications over HTTP. Below are the available options and subcommands.

1. Basic Usage
-------------------------------------------------------------------------------

(1.1) Usage

```sh
mech [OPTIONS] [mech_paths]... [SUBCOMMAND]
```

(1.2) Subcommands

| Command   | Description                                   |
|-----------|-----------------------------------------------|
| `build`   | Build Mech program into bytecode.             |
| `format`  | Format Mech source code into standard format. |
| `help`    | Print help message.                           |
| `serve`   | Serve Mech program over an HTTP server.       |

(1.3) Arguments

Source `.mec` files and directories. You can specify one or more `.mec`/`.mecb` files, or directories containing Mech scripts / bytecode.

If you run the Mech command without any files or subcommands, it will start the REPL.

(1.4) Options

| Option                | Description                                      |
|-----------------------|--------------------------------------------------|
| `-d`, `--debug`       | Prints debug information.                        |
| `-r`, `--repl`        | Starts the Mech Read-Eval-Print Loop (REPL).     |
| `-t`, `--time`        | Measures execution time of the program.          |
| `-e`, `--tree`        | Prints the parse tree of the Mech program.       |

(1.5) Examples

```sh
mech file1.mec file2.mec dir1
mech -d -e file.mec
mech -t file.mec
mech -r file.mec
```

2. Subcommands
-------------------------------------------------------------------------------

(2.1) build

Compiles Mech source code into bytecode.

```sh
mech build [OPTIONS] [FILES]
```

(2.1.1) Options

| Option          | Value      | Description                                 |
|-----------------|------------|---------------------------------------------|
| `-o`, `--out`   | `PATH`     | Specifies the output directory.             |

(2.1.2) Examples

```sh
mech build -o out_dir file1.mec
mech build -o out_dir file1.mec file2.mec dir1 dir2
```

(2.2) format

Formats Mech source code into a standard format.

```sh
mech format [OPTIONS] [FILES]
```

(2.2.1) Options


| Option               | Value               | Description                          |
|----------------------|---------------------|--------------------------------------|
| `-o`, `--out`        | `PATH`              | Specifies the output directory.      |
| `-s`, `--stylesheet` | `STYLESHEET`        | Sets the stylesheet for HTML output. |
| `-t`, `--html`       |                     | Outputs formatted code as HTML.      |


(2.2.2) Examples

```sh
mech format -o formatted/ my_script.mec
```

(2.3) serve

Serves a Mech program over an HTTP server.

```sh
mech serve [OPTIONS] [FILES]
```

(2.3.1) Options

| Option            | Value      | Description                                   |
|-------------------|------------|-----------------------------------------------|
| `-p`, `--port`    | `PORT`     | Sets the port for the server (default: 8081). |
| `-a`, `--address` | `ADDRESS`  | Sets the server address (default: 127.0.0.1). |

(2.3.2) Examples

```sh
mech serve -p 3000 -a 0.0.0.0 my_script.mec
```

4. Additional Help
-------------------------------------------------------------------------------

For more information on a specific command, you can use the `--help` option with that command. For example:

```sh
mech --help
mech serve --help
```

