Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions tools/hygiene/audit-agencysignature-main-tip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ interface ArgParseResult {
readonly errorMessage: string;
}

type ArgStep =
| { readonly kind: "ok"; readonly key: keyof MutableArgs; readonly value: string; readonly setMode: Mode | null; readonly skip: 1 }
| { readonly kind: "error"; readonly message: string }
| { readonly kind: "help" };

interface MutableArgs {
mode: Mode;
commitSha: string;
Expand All @@ -90,8 +85,18 @@ interface MutableArgs {
v1ShipDate: string;
}

// Derived from MutableArgs so adding/removing string fields cannot drift
// from the ArgStep narrowing. `mode` is set via the parallel `setMode`
// channel, never via key/value.
type StringArgKey = Exclude<keyof MutableArgs, "mode">;

type ArgStep =
| { readonly kind: "ok"; readonly key: StringArgKey; readonly value: string; readonly setMode: Mode | null; readonly skip: 1 }
| { readonly kind: "error"; readonly message: string }
| { readonly kind: "help" };

function classifyArg(arg: string, next: string | undefined): ArgStep {
const requiresNext: Record<string, { key: keyof MutableArgs; setMode: Mode | null; missing: string }> = {
const requiresNext: Record<string, { key: StringArgKey; setMode: Mode | null; missing: string }> = {
"--commit": { key: "commitSha", setMode: "commit", missing: "error: --commit requires SHA" },
"--max": { key: "maxN", setMode: "max", missing: "error: --max requires N" },
"--since": { key: "sinceDate", setMode: "since", missing: "error: --since requires DATE (YYYY-MM-DD)" },
Expand Down
Loading