xPulse
πŸ‡¬πŸ‡§ EN

API

Command class

import { Command } from '@xpulse/cli/command';

`configure()`

Called in the constructor. Fully describes the command. Override in your subclass.

configure() {
this
.setName('doc:fetch')
.setAlias('df')
.setDescription('Fetch docs via git archive')
.setHelp('Fetches docs from an xPulse repo and stores them locally.')
.addArgument('tool', null, 'Tool name (e.g. chat)')
.addOption('tag', null, 'Git tag to fetch')
.addOption('output-dir', './docs','Target directory')
.addFlag('dry-run', false, 'Simulate only, write nothing');
}

Fluent setters

Method Description
setName(name) Command name – namespace:area:command
setAlias(alias) Short name shown in --list and --help
setDescription(text) Short description for --list and --help
setHelp(text) Longer text shown in --help <command>
addArgument(name, default, description) Positional argument
addOption(name, default, description) Named option (-key="value")
addFlag(name, default, description) Boolean flag (--flag)

All setters return this – fully chainable.

`run(input, output)` β†’ `Promise`

Must be implemented by the subclass. Returns an exit code.

async run(input, output) {
// ...
return 0; // 0 = success, 1 = error, 2 = misuse
}

`keepAlive()`

Resets the timeout timer. For long-running commands. No import of @xpulse/event needed – injected by @xpulse/cli.

async run(input, output) {
while (!done) {
await doWork();
this.keepAlive();
}
return 0;
}

Input class

import { Input } from '@xpulse/cli/input';

Built by @xpulse/cli and passed to run().

Positional arguments

input.getArgument('tool') // β†’ 'chat' | default | null

Positional arguments are matched by the order of addArgument() calls.

Named options

input.getOption('tag') // β†’ 'v1.3.0' | default | null
input.getOption('output-dir') // kebab-case
input.getOption('outputDir') // camelCase – equivalent
input.hasOption('tag') // β†’ true | false

Boolean flags

input.getFlag('dry-run') // kebab-case
input.getFlag('dryRun') // camelCase – equivalent

Global flags

Method Flag Shortcut
input.isVerbose() --verbose -V
input.isQuiet() --quiet -q
input.isAnsi() --no-ansi negated –
input.isNoDebug() --no-debug –

Output class

import { Output } from '@xpulse/cli/output';

Built by @xpulse/cli and passed to run(). Respects --no-ansi and --quiet automatically.

Method Description
output.write(text) Text without newline
output.writeln(text?) Text with newline
output.success(text) βœ“ green
output.warn(text) ! yellow
output.error(text) βœ— red – ignores --quiet
output.table(headers, rows) Formatted table

CLI flags

Flag Shortcut Description
--help [command] -h CLI help, or command help if name given
--list – All commands with alias and description
--version -v Print version
--verbose -V Verbose output β†’ input.isVerbose()
--quiet -q Errors only β†’ input.isQuiet()
--no-ansi – No colors β†’ input.isAnsi() = false
--no-debug – Logger console level raised to warn – info/debug suppressed on console, file log unaffected

`--help` variants

Both are equivalent:

npx xpulse --help tapp:hello # flag before command name
npx xpulse tapp:hello --help # flag after command name

Argument parser

Rules

Syntax Result
namespace:area:command Command name
value (no prefix) Positional argument β†’ rawArguments[]
-key="value" / -key=value { key: 'value' }
--key="value" / --key=value { key: 'value' } (camelCase)
-flag { flag: true }
--flag / --dry-run { dryRun: true } (camelCase)
-key value / --key value ⚠ Warning – value treated as positional
--verbose / -V Global flag
--quiet / -q Global flag
--no-ansi Global flag
--no-debug Global flag

Example

npx xpulse doc:fetch chat -tag="v1.3.0" --dry-run -V
β†’ {
name: 'doc:fetch',
args: { tag: 'v1.3.0', dryRun: true },
rawArguments: ['chat'],
verbose: true,
quiet: false,
ansi: true,
warnings: [],
}

Bootstrap

Before running a command, @xpulse/cli calls app.init() from @xpulse/app if it is installed. This gives every command full service context (config, logger, debug, router, controller) without starting the HTTP server.

If @xpulse/app is not installed, config.load() is called as a fallback.

Environment variables

Variable Default Description
CLI_TIMEOUT 30 Timeout in seconds before exit code 1
en/api.md 2026-03-27