Skip to content
Edit this page

Console

The Console kernel is separate from HTTP. It uses argparse for parsing and asyncio for process entry, while the application container owns injected services and cleanup. Only Console loads routes/console.py.

A source application's artisan executable composes the application and kernel:

from bootstrap.app import create_application
from titancore.foundation.console import Kernel

raise SystemExit(Kernel(create_application()).handle())

Use await kernel.run(arguments) when already inside an event loop. Each invocation owns one application lifecycle, including help, usage errors and command failures. The shared exception handler reports command failures before application resources close. Startup or shutdown failures render on stderr.

Application commands

from titancore.console import Command


class WelcomeCommand(Command):
    signature = "app:welcome {name=Guest} {--shout}"
    description = "Welcome a user."

    async def handle(self) -> int:
        message = f"Hello, {self.argument('name')}"
        self.info(message.upper() if self.option("shout") else message)
        return 0

Register classes with kernel.commands(WelcomeCommand). Constructors resolve through the existing container, including asynchronous service factories. argument, option, secret and info provide framework input/output access.

Signatures support required positionals, ? optional arguments, positional defaults, * arrays, boolean options, options with values/defaults and short aliases such as {--u|username=admin}. Native parsing owns usage errors and help. Advanced signature grammar, command generators, scheduling and queue workers are not implemented by this module.

For small callback commands, use routes/console.py:

from titancore.facades import Artisan

Artisan.command("hello {name=Guest}", lambda name: print(f"Hello, {name}"))

Parsed arguments are supplied explicitly to the callback. Other synchronous constructor dependencies use the canonical container call API; prefer command classes for services backed by asynchronous factories. HTTP never discovers these declarations.

Framework commands

Command Behavior
env:setup Copy missing local configuration and initialize an empty app key
key:generate Explicitly rotate the app key; tokens become invalid after application reload
migrate Apply native Alembic revisions
migrate:status Show the current schema's applied revision heads
migrate:rollback --step=1 Reverse an explicit number of native revisions
db:seed Resolve and execute the configured root application seeder

Migration and seed commands are available when the database feature is registered. Environment setup preserves existing values and nonempty keys; it does not print secrets. Database extension installation, database creation and hosted infrastructure provisioning remain operator responsibilities.

Programmatic calls and workers

Construct the kernel before application startup. Inside an active application, await kernel.call(["command", "argument"]) borrows that lifecycle. Repeated calls and native help do not close the application. Nested callbacks can call await Artisan.call('app:welcome "Ada Lovelace" --shout'). Command input is isolated with context variables. Quoted strings are split into arguments without shell expansion or execution. Pass a sequence when values come from user input or contain literal backslashes. Invalid quoting is a usage error with exit status 2.

Callback injection retains the existing synchronous container call boundary; use command classes for async constructor dependencies.

Option arrays such as {--tag=*} collect repeated native option values. When a queue service is registered, queue:work delegates bounded receiving to that module. SIGINT and SIGTERM drain the receiver before app shutdown. Command discovery, generators and general scheduling are not implemented.