Problem
Every command action navigates the Commander parent chain manually:
const ctx = createContext(command.parent!.parent!.opts());
This pattern appears ~25 times across all command files. It is:
- Fragile — breaks silently if command nesting changes (wrong opts object, missing API token)
- Non-obvious — a new contributor has to understand the Commander tree to know why it's
.parent!.parent!
- Non-null assertions —
! operators mask potential runtime errors
Proposed fix
Extract a helper in src/common/context.ts:
import type { Command } from "commander";
export function getRootOpts(command: Command): CommandOptions {
let current: Command | null = command;
while (current?.parent) {
current = current.parent;
}
return current.opts() as CommandOptions;
}
Then replace all call sites:
// Before
const ctx = createContext(command.parent!.parent!.opts());
// After
const ctx = createContext(getRootOpts(command));
Affected files
All files in src/commands/:
auth.ts, comments.ts, cycles.ts, documents.ts, files.ts, issues.ts, labels.ts, milestones.ts, projects.ts, teams.ts, users.ts
Acceptance criteria
Problem
Every command action navigates the Commander parent chain manually:
This pattern appears ~25 times across all command files. It is:
.parent!.parent!!operators mask potential runtime errorsProposed fix
Extract a helper in
src/common/context.ts:Then replace all call sites:
Affected files
All files in
src/commands/:auth.ts,comments.ts,cycles.ts,documents.ts,files.ts,issues.ts,labels.ts,milestones.ts,projects.ts,teams.ts,users.tsAcceptance criteria
getRootOpts()helper exists and walks to the root commandcommand.parent!.parent!.opts()replacedparent!assertions remain in command files