CLI
Capy
function CLI() function CLI(request : any) function CLI:NAME() function CLI:NAME(request : any)
CLI defines the local command entrypoint. bearer-cli /unit.capy runs it, and bearer-cli /unit.capy:NAME runs the named entry point CLI:NAME of the same unit, so one unit can offer several commands.
The handler binds request implicitly as an any. An explicit request : any declaration receives the same value. Use print to write command output. A CLI handler returns no value.
Read command input
With --get, command pairs arrive as strings in request.query:
bearer-cli --get /unit.capy:ECHO message=hellofunction CLI:ECHO()
{
print(request.query.message, "\n")
}
When pairs are present, the default is a JSON POST, not a query string or a form body. Decode it with json_decode(request.body) and read the value of the result:
bearer-cli /unit.capy:ECHO message=hellofunction CLI:ECHO(request : any)
{
var input := json_decode(string(request.body)).value
print(input.message, "\n")
}
The default POST converts numeric, Boolean, and null values. Use --get when values must remain strings. Use --json to supply a JSON body directly. request.form does not contain JSON fields. With no pairs or body, the command defaults to GET.
Request lifetime
Each command gets a fresh request workspace. Unit variables do not persist between CLI commands. A file can define HTTP and CLI handlers separately. Calling its CLI handler does not call its RENDER handler.
print(request.method, "\n")
Output
GET