Commands¶
Commands are objects in a hierarchical tree. Every node extends Command; namespace nodes extend CommandContainer.
Factories¶
command(name, description, execute, aliases?) / command(name, description, argDefs, execute, aliases?) {#command}¶
Returns a Command ready for terminal.register(). When the command takes no arguments, omit argDefs and pass the handler directly. Optional aliases provide alternate names.
command('greet', 'Say hello', (ctx) => ctx.stdout.write('Hello!\n'));
command('deploy', 'Deploy the app', handler, ['d']); // alias: deploy via "d"
container(name, description?, children?, aliases?) {#container}¶
Returns a CommandContainer. Children can also be added later via .add().
container('config', 'Configuration', [
command('get', 'Get a value', handler),
command('set', 'Set a value', handler)
]);
container('server', 'Server commands', [], ['srv']); // alias: server via "srv"
arg(name, description?, schema, position?, aliases?, secret?) {#arg}¶
Shortcut for a single CommandArgumentDefinition. See Argument Definitions for details, examples, and schema patterns.
When position is provided, the argument can be given as a bare token instead of --name value. When secret is true, missing arguments prompt with hidden input.
Registration¶
Register at root with terminal.register():
Subcommands are added to a parent container via .add():
const cfg = container('config', 'Configuration');
cfg.add(command('get', 'Get a value', handler));
term.register(cfg);
Tree structure¶
- Command names are single words (
greet,config,get) - Parent paths use dot-separated segments (
'config','config.set') - Containers act as namespace nodes;
execute()is called when no subcommand matches - Unknown commands throw
CommandNotFoundErrorwith prefix-matched suggestions
CommandContext¶
Every command's execute(ctx, args) receives a CommandContext:
| Property | Description |
|---|---|
terminal |
The running Terminal instance |
stdout / stdin |
I/O streams |
state |
Shared mutable state between commands |
logger |
Console-compatible logger |
exit |
Shorthand for terminal.stop() |
Classes — explicit Command / CommandContainer subclasses
Definitions — argument definitions, positional args, schemas
Arguments — typed accessors and prompting