Implementation:0xsline OpenChatCut CLI Args
Appearance
| Knowledge Sources | |
|---|---|
| Domains | CLI, Parsing |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Command-line argument parser for the `occ` CLI that parses `argv` into positionals and a flag map with typed accessors and unknown-flag rejection.
Description
The CLI Args module parses `argv` into positionals and a flag map, supporting `--flag=value`, `--flag value`, and boolean `--flag` syntax. Provides typed accessors (`flagText`, `flagBoolean`) and `rejectUnknownFlags` to fail loudly on typos. Declares `GLOBAL_FLAGS` shared by all subcommands.
Usage
- Every CLI subcommand: All subcommands rely on this parser for flag handling.
Code Reference
Source Location
- Repository: OpenChatCut
- File: cli/args.ts
- Lines: 1-75
Signature
export function parseCommandLine(argv: string[]): { flags: Map<string, string | true>; positionals: string[] };
export function flagText(flags: Map<string, string | true>, name: string): string | undefined;
export function flagBoolean(flags: Map<string, string | true>, name: string): boolean;
export function rejectUnknownFlags(flags: Map<string, string | true>, known: readonly string[]): void;
export function positional(args: string[], index: number, name: string): string;
export const GLOBAL_FLAGS: readonly string[];
Import
import { parseCommandLine, flagText, flagBoolean, rejectUnknownFlags, positional, GLOBAL_FLAGS } from './args.ts';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| argv | string[] | Yes │ Command-line arguments | |
| flags | Map | Yes | Parsed flag map (for accessors) |
| known | string[] | Yes | Known flag names (for rejection) |
Outputs
| Name | Type | Description |
|---|---|---|
| parseCommandLine() returns | { flags, positionals } | Parsed flags and positionals |
| flagText() returns | undefined | String flag value |
| flagBoolean() returns | boolean | Boolean flag value |
Usage Examples
Parsing CLI Arguments
import { parseCommandLine, flagText, flagBoolean, rejectUnknownFlags } from './args.ts';
const { flags, positionals } = parseCommandLine(process.argv.slice(2));
rejectUnknownFlags(flags, ['json', 'data-dir']);
const json = flagBoolean(flags, 'json');
const dataDir = flagText(flags, 'data-dir');
Related Pages
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment