Commands

One binary, mctl, and a verb for each thing it can write. Every generator takes a file and writes beside it unless --dir says otherwise.

The surface

CommandReadsWrites
mctl gen api <file.api>a speca moonapi project tree — or one file with --flat
mctl gen rpc <file.proto>a protoa moonrpc project tree: messages, codecs, handler table, client
mctl gen gql <file.api>a speca moongql tree — the types as #gql.type, the routes as root fields
mctl gen model <file.api>a speca moonorm tree — the tables as #orm annotations, plus migrations
mctl gen crud <file.sql>DDLthe same tree, plus the typed CRUD helpers
mctl gen doc <file.api>a specan OpenAPI document and a Swagger page
mctl gen agent <file.api>a speca moonkoog agent skeleton
mctl api format <file.api>a specthe canonical text, on stdout, or in place with --write
mctl api validate <file.api>a specthe findings, then a count — nothing on disk
mctl api doc <file.api>a spec<stem>_api.md — routes, groups, types, constraints
mctl api ts|dart|kt|java <file.api>a specone typed client per route, in that language
mctl migrate <file.api>a spec<service>_migrate.sql — one table per type block
mctl model mongo <file.api>a spec<service>_mongo.mbt — documents and repositories
mctl model cache <file.api>a spec<service>_cache.mbt — cache-aside CRUD
mctl model mysql datasource <dsn>a live MySQL schemamysql_model.mbt
mctl model pg datasource <dsn>a live PostgreSQL schemapg_model.mbt
mctl gateway <file.proto>a proto, and <stem>.routes if present<stem>_gateway.mbt — an HTTP front door
mctl quickstart <name>—a service: scaffold, generate, build
mctl api new <name>—an empty moonapi project
mctl rpc new <name>—an empty moonrpc project
mctl gql new <name>—an empty moongql project
mctl model new <name>—an empty data-layer project
mctl docker <name>—Dockerfile and .dockerignore
mctl kube <name>—deploy/deployment.yaml and deploy/service.yaml
mctl plugin <exe> <file.api>a spec, a pluginwhatever the plugin returns, inside the output directory

Housekeeping

CommandWhat it does
mctl envprint the configuration in force and where each value came from
mctl config list|get|set|path|migrateread and write the config file
mctl template list|show [name]the bundled template catalogue
mctl completion <shell>a completion script for bash, zsh, fish or powershell
mctl upgrade [version]move the moonbitstack pins in moon.mod to a release
mctl bug [title]a bug report, pre-filled with the environment
mctl helpthe command table

Flags

FlagWhat it does
--dir <path>write the tree under path instead of here
--flatone .mbt file instead of a project tree
--style <template>how generated names are spelled: gozero, goZero, go_zero, …
--writerewrite the input file in place (api format)
--home <path>use this template home instead of the bundled library
--remote <url>read the template library from a git remote
--branch <name>the branch of --remote, main by default

The three library flags choose where gen api reads its templates from: a directory laid out like the catalogue for --home, a checkout of --remote at --branch for a shared one. A file's path and its text are both rendered over the parsed spec, so {{.service}}.mbt becomes the entry point of the service the spec describes. --home wins when both are given, and the home in the configuration file is used when neither is; see Configuration.

The template catalogue

terminal
$ mctl template list
TemplateSpecWhat it produces
api-serviceapia moonapi service: routes, handlers, logic, config and a Dockerfile
api-flatapithe same routes and types in one .mbt file, for a small service
rpc-serviceprotoa moonrpc service: messages, codecs, handler table and a client
gql-serviceapia moongql schema and resolver over the spec's types
mcp-serverapian MCP server whose tools are the spec's annotated handlers
model-mysqlddlmoonorm models and CRUD for a MySQL schema, reflected or from DDL
model-postgresddlmoonorm models and CRUD for a PostgreSQL schema
model-mongoapidocument models over a Mongo collection, with a typed collection port
gatewayprotoan HTTP gateway that routes to a moonrpc client

The command prints the same rows as a Markdown table.

mctl template show api-service prints one entry; mctl template init <dir> writes a starter library into a directory to edit — a moon.mod, a moon.pkg and one file per service that generates, compiles and answers every route with 200 until the bodies are filled in.

terminal
$ mctl template init my-templates
$ mctl gen api greet.api --home my-templates --dir out
mctl: wrote 4 file(s) from greet.api through the template library at my-templates

The library behind it

Every command is a thin layer over an exported function, so a build script can do the same thing without a subprocess:

moon.pkg
import {
  "moonbitstack/moonctl",
}
FunctionWhat it returns
parse, parse_alla Spec from one file, or from a file and the sources it imports
generate, generate_treea scaffold as text, or as a tree of files
render_template_dir, render_template_filea template library's files, rendered over a spec
format, validate, validate_filesthe canonical text, and the findings for a spec
generate_client, client_filea typed client in one of four languages
generate_markdown, generate_migrationsthe Markdown reference, the migration SQL
generate_mongo, generate_cacheddocuments and repositories, the cache-aside layer
generate_gateway, default_routesthe gateway, and the routes a proto implies
generate_grpc, parse_protothe moonrpc service, and the proto tree it came from
generate_model, generate_crudmodels and the CRUD layer, from a spec or from DDL

The library is pure logic — a string in, a string out — so it runs on all four MoonBit targets, and a build step, a test or a browser page can call it.