Commands
Every CLI command in Moost is a method decorated with @Cli(). The decorator argument defines the command path — the words a user types to invoke it.
Defining a command
import { Cli, Controller } from '@moostjs/event-cli'
@Controller()
export class AppController {
@Cli('deploy')
deploy() {
return 'Deploying...'
}
}Running my-cli deploy calls the deploy() method and prints the return value.
Command paths
A command path is a sequence of segments separated by spaces or slashes (both are equivalent):
// These two are identical:
@Cli('config set')
@Cli('config/set')The user always types space-separated words:
my-cli config setPositional arguments
Segments that start with : become positional arguments:
@Cli('greet/:name')
greet(@Param('name') name: string) {
return `Hello, ${name}!`
}my-cli greet World # → Hello, World!Multiple arguments work the same way:
@Cli('copy/:source/:dest')
copy(
@Param('source') source: string,
@Param('dest') dest: string,
) {
return `Copying ${source} → ${dest}`
}my-cli copy fileA.txt fileB.txtEscaped colons
If a command name contains a literal colon (like build:dev), escape it with a backslash:
@Cli('build\\:dev')
buildDev() {
return 'Building for dev...'
}my-cli build:devDefault path from method name
When @Cli() is called without an argument, the method name becomes the command:
@Cli()
status() {
return 'All systems operational'
}my-cli statusCommand aliases
Use @CliAlias() to define alternative names for a command. Stack multiple decorators for multiple aliases:
import { Cli, CliAlias, Controller } from '@moostjs/event-cli'
@Controller()
export class AppController {
@Cli('install/:package')
@CliAlias('i/:package')
@CliAlias('add/:package')
install(@Param('name') pkg: string) {
return `Installing ${pkg}...`
}
}All three invoke the same handler:
my-cli install lodash
my-cli i lodash
my-cli add lodashReturn values
Whatever a command handler returns is printed to stdout. Return a string for plain text, or an object/array for JSON output:
@Cli('info')
info() {
return { name: 'my-app', version: '1.0.0' }
}my-cli info
# → {"name":"my-app","version":"1.0.0"}What's next
- Options & Arguments — add flags like
--verboseand typed parameters - Controllers — group commands under prefixes