refactor: split src/cli.ts into focused modules#2900
Conversation
Extract cli.ts (1394 lines) into four focused modules: - src/cli-options.ts: program creation, custom help formatter, and all option/argument declarations (~370 lines) - src/commands/main-action.ts: the main awf action handler with signal handling and orchestration (~700 lines) - src/commands/subcommands.ts: validateFormat, handlePredownloadAction, and Commander predownload/logs subcommand registrations (~160 lines) - src/cli.ts: thin entry point that wires the above together and keeps backward-compat re-exports (~90 lines) All 1817 tests pass and type-check is clean."
- Replace direct program import in main-action.ts with injectable OptionSourceResolver type and createMainAction() factory, decoupling the handler from the global program instance for easier unit testing - Consolidate cli.ts imports to avoid duplicate import/re-export for program, validateFormat, and handlePredownloadAction
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
✨ New Files (3 files)
Coverage comparison generated by |
🧪 Smoke Test Results
Overall: FAIL — GitHub MCP auth is not available in this environment. Note: PR details unavailable due to MCP auth failure; no assignee info retrievable.
|
Smoke Test: Copilot BYOK (Offline) Mode
Note: Running in BYOK offline mode ( Overall: FAIL — pre-step template variables were not expanded; GitHub MCP returned 401.
|
Smoke Tests
**Status: 3/4 PASS
|
Chroot Smoke Test Results
Result: ❌ Not all versions matched — Go matches, but Python and Node.js differ between host and chroot environments.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results
Overall: FAIL —
|
|
Overall status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the CLI entrypoint by splitting the former monolithic src/cli.ts into focused modules, keeping the existing public re-exports intact while making the main action handler injectable/testable without requiring a global Commander singleton.
Changes:
- Extracted Commander program construction + option/argument declarations into
src/cli-options.ts. - Extracted the main
awfaction handler intosrc/commands/main-action.ts, now produced via a factory that injectsgetOptionValueSource. - Extracted subcommand registration + helpers into
src/commands/subcommands.ts, leavingsrc/cli.tsas a thin wiring/entry module.
Show a summary per file
| File | Description |
|---|---|
| src/cli.ts | Reduced to a thin entrypoint that preserves backwards-compat re-exports and wires program/action/subcommands. |
| src/cli-options.ts | Centralizes Commander program creation, help formatting, and all option/argument declarations. |
| src/commands/main-action.ts | Houses the main CLI action handler, now created via a factory for better testability/decoupling. |
| src/commands/subcommands.ts | Registers predownload and logs/* subcommands and exports the related helpers for compatibility/tests. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
|
@copilot address review feedback |
src/cli.tshad grown to 1,394 lines serving four unrelated responsibilities, making the main action handler (~700 lines) untestable in isolation and every subcommand addition inflating the entry point further.Changes
src/cli-options.ts— Commanderprogramcreation, custom help formatter, and allprogram.option()/.argument()declarations (~280 lines)src/commands/main-action.ts— the mainawfaction handler extracted verbatim, with one design improvement: instead of importing the globalprograminstance to callgetOptionValueSource, the handler is now produced by a factory:src/commands/subcommands.ts—validateFormat,handlePredownloadAction, andregisterSubcommands()which registers thepredownload,logs,logs stats,logs summary, andlogs auditCommander subcommands (~165 lines)src/cli.ts— reduced to a ~75-line thin entry point that wires the above together; all backward-compat re-exports are preserved so no existing callers break