--- title: Arguments --- # Positional Arguments Positional arguments are declared directly in the command signature string using angle brackets `` and square brackets `[optional]`. ## Signature Syntax | Token | Meaning | Inferred `ctx.args` type (default `String`) | | --------------- | ----------------------------- | ------------------------------------------- | | `` | Required single argument | `string` | | `[region]` | Optional single argument | `string \| undefined` | | `` | Required variadic (1 or more) | `string[]` | | `[files...]` | Optional variadic (0 or more) | `string[]` | | `-- [extra...]` | Arguments captured after `--` | `string[]` | Kebab-case argument names are automatically converted to camelCase keys on `ctx.args` (for example, `` becomes `ctx.args.outDir`). ```ts import { command } from "clerc"; const copy = command("copy [dest-path] [extra-files...]", { args: { sourcePath: { description: "Source file" }, destPath: { default: "./dist", description: "Destination directory" }, extraFiles: { unique: true, description: "Additional files to copy", }, }, run(ctx) { ctx.args; // ^? }, }); ``` ::: tip Compile-time key checking The keys inside `args: { ... }` are constrained to the exact argument names extracted from your command signature. Mistyping `sourcePth` produces an immediate TypeScript error. Variadic arguments also support `unique`, `minItems`, and `maxItems`. ::: ## Defaults and Environment Fallbacks Optional arguments support `default` values (or factory functions). Both required and optional arguments support `env` fallbacks: ```ts import { command } from "clerc"; // ---cut--- const deploy = command("deploy [region]", { args: { token: { env: "DEPLOY_TOKEN", description: "API token (or set DEPLOY_TOKEN)", }, region: { default: "us-east-1", description: "Target region", }, }, run(ctx) { // If DEPLOY_TOKEN="sec_123" is set in env: // $ acme deploy -> ctx.args.token === "sec_123", ctx.args.region === "us-east-1" ctx.args.token; // ^? ctx.args.region; // ^? }, }); ``` When a required argument with `env` is missing from both `argv` and `process.env`, Clerc appends a hint: ## Double-Dash (`--`) Arguments POSIX `--` stops flag parsing. Clerc handles `--` in three ways depending on your signature: 1. **Named arguments after `--`** (`"test [filter] -- [vitest-args...]"`): tokens before `--` bind to `filter`, and tokens after `--` bind to `ctx.args.vitestArgs` (with full schema conversion and `--help` documentation). 2. **Bare `--` in signature** (`"run