LogoRobo.js

API Reference

Full API documentation for @robojs/cli exports.

API Reference

The @robojs/cli package re-exports CLI primitives from robo.js/cli.js for convenience. You can import from either package.

// These are equivalent
import { Command, parseCliOptions } from '@robojs/cli'
import { Command, parseCliOptions } from 'robo.js/cli.js'

Functions

createCliCommandConfig

Type-safe configuration helper that enables TypeScript inference for command options. This is an identity function — it returns the config object unchanged but provides type narrowing.

import { createCliCommandConfig } from 'robo.js/cli.js'

export const config = createCliCommandConfig({
  description: 'My command',
  options: [
    { alias: '-n', name: '--name', type: 'string', required: true }
  ]
} as const) // Don't forget `as const`!

The as const assertion is required for type inference. Without it, option types are widened and CliContext cannot infer specific option types.

parseCliOptions

Parses raw command-line arguments into typed options. Used internally by the Command class but available for custom parsing scenarios.

import { parseCliOptions } from 'robo.js/cli.js'

const result = parseCliOptions(process.argv.slice(2), [
  { alias: '-n', name: '--name', description: 'Name', type: 'string' },
  { alias: '-v', name: '--verbose', description: 'Verbose', type: 'boolean' }
])

console.log(result.parsedOptions)  // { name: '...', verbose: true }
console.log(result.positionalArgs) // remaining positional args
console.log(result.errors)         // validation errors

Classes

Command

CLI command builder class. Handles argument parsing, subcommand routing, help generation, and handler execution.

import { Command } from 'robo.js/cli.js'

const cmd = new Command('mycli')
cmd.version('1.0.0')
cmd.description('My CLI tool')
cmd.option('-h', '--help', 'Shows this help menu')
cmd.parse()

You typically don't need to use Command directly. The generated entry point handles command registration automatically. It's available for advanced use cases like programmatic CLI construction.

Types

CliContext<C>

Handler context object passed to every command handler. When a config type parameter C is provided, options is typed based on the config's option definitions.

Prop

Type

CliCommandConfig

Configuration shape for a CLI command.

Prop

Type

CliOptionConfig

Configuration for an individual command option.

Prop

Type

CliHandler

Type for command handler functions.

type CliHandler = (context: CliContext) => unknown | Promise<unknown>

ParseCliOptionsConfig

Configuration for the parseCliOptions function.

Prop

Type

Next steps

On this page