Skip to content

Command API reference ​

Import the application factory, decorators and context types from @chojs/command. The package re-exports the dependency injection declarations used to build a command module. Generated signatures on JSR

Application ​

APIContract
ChoCommand.create(Root, options?)Synchronous graph validation. Returns a reusable command application
app.run(argv: string[])Resolves to a numeric exit status. Expects the arguments after the executable and script
app.close()Asynchronously releases initialized resources
app[Symbol.asyncDispose]()Enables block-scoped async disposal

Options are name (default "chojs"), version, parseOptions, overrides and onError. --help and --version are reserved long flags. See launching a CLI.

Decorators and providers ​

APITarget and behavior
@Main(flags?)One implicit command in the application
@Action(name, flags?)Named command. Names are unique, contain no whitespace and cannot begin with a dash
@Help(text)Controller group or method help. The first line serves as its summary
@Middlewares(...items)Module, controller or method. Calls downstream through next()
@Catch(handler)Selects an error handler for that scope
@Module, @Controller, @InjectableDeclare ownership and constructor dependencies
token<T>, providerIdentify values and declare factories

Arguments and handlers ​

CommandFlags supports boolean, string, collect, negatable, alias, default and describe. ParserOptions configures the application parser, including options such as stopEarly and "--". Local flag definitions are merged for the selected action. Flag semantics

ChoCommandContext memberValue
argsChoArgs with _ for positional strings and fields for parsed flags
argvOriginal list passed to run
command"main" or the selected action name
statePer-run Map<PropertyKey, unknown>

Use ChoCommandMiddlewareFn and ChoCommandNext for function middleware. ChoCommandMiddleware also accepts a class with handle. The analogous error-handler types are ChoCommandErrorHandlerFn and ChoCommandErrorHandler.

Exit codes ​

A valid code is a non-negative integer, capped at 255. A normal command with no code succeeds with 0. Unhandled command errors and unknown actions produce 1. A failing error handler produces 2. A successful error handler may choose its own code. Full exit-code rules

Released under the MIT License.