Skip to content

cmd

packages/cmd — command definition and argv parsing for @arbe/cli. No workspace dependencies.

Wraps node:util.parseArgs with a typed command schema: option defs (string, number, boolean, enum), short aliases, negation (--no-flag), comma-separated multiples (--tag a,b), number coercion, enum validation, and named positional args with required/optional semantics.

Defining a command

import { defineCommand } from '@arbe/cmd'
export default defineCommand({
description: 'Show current config',
options: {
json: { type: 'boolean', description: 'Output as JSON' },
format: { type: 'enum', values: ['table', 'raw'], default: 'table' },
},
args: {
key: { description: 'Config key to show', required: false },
},
run({ values, args }) {
// values.json, values.format, args.key
},
})

runCommand(cmd, name, argv) parses argv against the command schema, handles --help automatically, and calls cmd.run(). Return a string to print it to stdout.

Option types

string — passed through as-is. number — coerced, throws on NaN. boolean — supports --flag and --no-flag. enum — validated against values list.

All types support short, default, description, and multiple (repeatable or comma-separated).

Help

--help or -h on any command prints auto-generated usage from the schema — args, options with defaults, and examples.