Skip to content

CLI Reference

Complete reference for the ZPy command-line interface.

Usage

bash
zpy [OPTIONS] [FILE]

Options

OptionDescription
-h, --helpShow help message
-v, --versionShow version information
-i, --interactiveRun file then enter REPL
-c, --code <CODE>Execute code string and exit
--tokensDump tokens (for debugging)
--astDump AST (for debugging)
--compileCompile script to .zig file
--standaloneCreate portable package
-o, --output <NAME>Output name for compiled executable
replStart interactive REPL

Commands

Run a Script

bash
zpy script.zpy

Start REPL

bash
zpy           # Start REPL
zpy repl      # Explicit REPL command

Execute Code String

bash
zpy -c "print(1 + 2)"
zpy --code "print('Hello')"

Run Script Then REPL

bash
zpy -i script.zpy

Useful for debugging - script runs, then you can inspect variables interactively.

Compilation

Quick Compile

bash
zpy --compile script.zpy
zig build-exe script.zig -O ReleaseSmall

Creates a .zig file that references the interpreter. Must run from ZPy project directory.

Portable Package

bash
zpy --standalone script.zpy
cd script_standalone
zig build-exe script.zig -O ReleaseSmall

Creates a self-contained folder with embedded interpreter source.

Custom Output Name

bash
zpy --compile script.zpy -o myapp
zpy --standalone script.zpy -o myapp

Debugging

Dump Tokens

bash
zpy --tokens script.zpy

Shows the token stream from the lexer:

TOKEN: { type: NAME, value: 'x', line: 1 }
TOKEN: { type: EQUAL, value: '=', line: 1 }
TOKEN: { type: NUMBER, value: '10', line: 1 }
TOKEN: { type: EOF, value: '', line: 1 }

Dump AST

bash
zpy --ast script.zpy

Shows the abstract syntax tree:

Program
└── VarDecl { name: 'x', value: Number(10) }

Environment Variables

ZPY_HOME

Points to the ZPy installation directory.

bash
# Linux/macOS
export ZPY_HOME=/path/to/zpy

# Windows PowerShell
$env:ZPY_HOME = "D:\path\to\zpy"

Effects:

ModeZPY_HOME SetBehavior
--compileNoOutput to current dir (must be in ZPy project)
--compileYesOutput to ZPY_HOME directory
--standaloneNoCopy src/ from current directory
--standaloneYesCopy src/ from ZPY_HOME

Examples

Basic Usage

bash
# Run a script
zpy hello.zpy

# Quick calculation
zpy -c "print(2 ** 10)"

# Interactive exploration
zpy -i data_processing.zpy

Development

bash
# Debug tokenization
zpy --tokens script.zpy

# Debug parsing
zpy --ast script.zpy

# Test in REPL
zpy -c "def test(): return 42" -i

Distribution

bash
# Create portable package
zpy --standalone myapp.zpy -o myapp
cd myapp_standalone
zig build-exe myapp.zig -O ReleaseSmall -fstrip -fsingle-threaded

# Distribute the entire myapp_standalone/ folder

Released under the MIT License.