Skip to content
Draft

CLI Reference

The draft CLI is the primary tool for working with Draft projects.

Create a new Draft project:

Terminal window
draft new <name> [options]

Options:

  • --template <name> — Project template (default, web, embedded, mobile, game)
  • --path <path> — Directory to create project in
Terminal window
draft new my-app
draft new my-app --template web
draft new my-app --template embedded

Compile a Draft project:

Terminal window
draft build [options]

Options:

  • --target <target> — Compilation target (native, wasm, wasi)
  • --release — Release build (optimized)
  • --debug — Debug build
  • --output <path> — Output path
  • --lib — Build as library
  • --minify — Minify output
  • --compress — Compress output
  • --source-map — Generate source map
Terminal window
draft build
draft build --release
draft build --target wasm
draft build --target wasm --minify
draft build --output my-app

Compile and run a Draft program:

Terminal window
draft run <file> [options]

Options:

  • --target <target> — Runtime target
  • --release — Release build
  • --args <args> — Arguments to pass to program
Terminal window
draft run main.draft
draft run main.draft --release
draft run main.draft --args "arg1 arg2"

Run tests:

Terminal window
draft test [options]

Options:

  • --target <target> — Test target
  • --filter <pattern> — Filter tests by name
  • --release — Release build
  • --watch — Watch for changes and re-run
Terminal window
draft test
draft test --filter "test_add"
draft test --watch

Format Draft source files:

Terminal window
draft fmt [options] [files]

Options:

  • --check — Check formatting without changes
  • --diff — Show formatting diff
Terminal window
draft fmt
draft fmt src/
draft fmt --check
draft fmt main.draft

Check code for errors without compiling:

Terminal window
draft check [options]

Options:

  • --warnings — Show warnings
Terminal window
draft check
draft check --warnings

Remove build artifacts:

Terminal window
draft clean

Generate documentation:

Terminal window
draft doc [options]

Options:

  • --output <path> — Output directory
  • --open — Open docs in browser
Terminal window
draft doc
draft doc --output docs/
draft doc --open

Manage dependencies:

Terminal window
draft deps <command>

Commands:

  • install — Install dependencies
  • update — Update dependencies
  • list — List dependencies
  • search <query> — Search for packages
Terminal window
draft deps install
draft deps update
draft deps list
draft deps search http

Add a dependency:

Terminal window
draft add <package> [version]
Terminal window
draft add http
draft add http 1.2.0
draft add json --features serde

Remove a dependency:

Terminal window
draft remove <package>

Publish a package:

Terminal window
draft publish [options]

Options:

  • --dry-run — Simulate publish
  • --registry <url> — Registry URL

Create a package:

Terminal window
draft package [options]

Initialize a new package in current directory:

Terminal window
draft init [options]

Manage compilation targets:

Terminal window
draft target <command>

Commands:

  • list — List installed targets
  • add <target> — Add a target
  • remove <target> — Remove a target
  • available — List available targets
Terminal window
draft target list
draft target add wasm
draft target add arm-none-eabi
draft target available

Run a compiled program:

Terminal window
draft run <binary>

Flash to embedded device:

Terminal window
draft flash [options]

Options:

  • --target <target> — Target platform
  • --probe <probe> — Debug probe
Terminal window
draft flash
draft flash --target thumbv7em-none-eabihf

Start debugging session:

Terminal window
draft debug [options]

Options:

  • --gdb — Use GDB
  • --lldb — Use LLDB
  • --swo — Enable SWO trace
Terminal window
draft debug
draft debug --gdb

Deploy application:

Terminal window
draft deploy [options]

Options:

  • --target <target> — Deployment target
Terminal window
draft deploy
draft deploy --target web
draft deploy --target ios

Upgrade Draft installation:

Terminal window
draft upgrade

Print version information:

Terminal window
draft version
draft --version
draft -V

Show help:

Terminal window
draft help
draft help <command>
draft --help
draft -h

Generate shell completions:

Terminal window
draft completion <shell>

Supported shells: bash, zsh, fish, powershell, elvish

Terminal window
draft completion bash > /etc/bash_completion.d/draft
  • --verbose / -v — Verbose output
  • --quiet / -q — Quiet output
  • --color <when> — Color output (auto, always, never)
  • --config <path> — Config file path
[package]
name = "my-app"
version = "0.1.0"
edition = "2024"
authors = ["Your Name <you@example.com>"]
description = "My Draft application"
license = "MIT"
[dependencies]
http = "1.2.0"
json = { version = "1.0", features = ["serde"] }
[profile.release]
opt-level = 3
lto = true
Variable Description
DRAFT_HOME Draft installation directory
DRAFT_TARGET Default compilation target
DRAFT_LOG Log level
DRAFT_REGISTRY Package registry URL
Code Meaning
0 Success
1 General error
2 Compilation error
3 Runtime error
4 Configuration error
5 I/O error