Skip to content
Sarj Code Standards

prefer-typed-cli

Declare Node CLI arguments with a typed parsing contract.

Why

Raw positional and option lookups scatter a command contract across individual uses. A declared parser makes positional meanings, options and defaults visible together.

Fix

Prefer a Zod schema for application arguments, with native Node flag parsing for transport. Existing adequate typed parser boundaries remain allowed. Preserve positional meanings, option aliases, defaults and exit behavior.

Examples

Before — flagged Detect the demonstrated gap
app.ts
deploy(process.argv[2]);
After — preferred Preserve the declared boundary
app.ts
import { z } from "zod";
const Args = z.tuple([z.string().min(1)]);
const [service] = Args.parse(process.argv.slice(2));
deploy(service);