arg
Positional argument schema factory.
Entry point for defining args on a command. Use arg.<kind>() to create an ArgBuilder, then chain modifiers and pass the result to command().arg(name, builder).
Four kinds are available:
arg.string()— raw string (most common)arg.number()— parsed to number, errors on NaNarg.enum(values)— constrained to listed literalsarg.custom(fn)— arbitrary parse function, infers return typeImport:
@kjanat/dreamcliExport kind: constant
Declared in:
src/core/schema/arg.tsSource link:
packages/dreamcli/src/core/schema/arg.ts:668
Signatures
ts
const arg: ArgFactory;Examples
ts
import { command, arg } from '@kjanat/dreamcli';
command('deploy')
.arg('target', arg.string().env('DEPLOY_TARGET').describe('Where to deploy'))
.arg('port', arg.number().env('PORT').default(3000))
.action(({ args }) => {
console.log(`Deploying to ${args.target} on port ${args.port}`);
});
// $ mycli deploy production 8080 → target='production', port=8080
// $ DEPLOY_TARGET=staging mycli deploy → target='staging', port=3000Related Examples
- Basic single-command CLI. -
examples/standalone/basic.ts - Interactive prompts with config file fallback. -
examples/standalone/interactive.ts - Mixed machine-readable JSON and human-readable side-channel output. -
examples/standalone/json-mode.ts - Middleware patterns: auth guard, request timing, error handling. -
examples/standalone/middleware.ts - Multi-command CLI with nested command groups (git-like). -
examples/standalone/multi-command.ts - Testing examples using @kjanat/dreamcli/testkit. -
examples/standalone/testing.ts