[repository-quality] Repository Quality: CLI Command Definition Inconsistency (2026-04-16) #26649
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Repository Quality Improvement Agent. A newer discussion is available at Discussion #26871. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🎯 Repository Quality Improvement Report — CLI Command Definition Inconsistency
Analysis Date: 2026-04-16
Focus Area: CLI Command Definition Inconsistency
Strategy Type: Custom (first run — no prior history)
Custom Area: Yes — This focus area was chosen after observing that
cmd/gh-aw/main.gomixes two architecturally incompatible patterns for defining CLI commands, creating a growing inconsistency that impedes testability, discoverability, and contribution experience.Executive Summary
The
gh-awCLI entry point (cmd/gh-aw/main.go, 895 lines) currently defines five commands inline (new,compile,run,remove,enable,disable,version) while all other commands follow the established pattern of being implemented inpkg/cli/and simply instantiated inmain.go. The largest inline command,compileCmd, spans ~126 lines with significant business logic directly in the cobraRunEclosure, making it untestable via standard package-level tests.This inconsistency has concrete downstream costs: inline commands cannot be unit tested, adding new features requires editing the 895-line
main.go, and contributors looking for command logic inpkg/cli/will miss critical behavior implemented elsewhere. Theinit()function alone is ~403 lines registering all commands, which further adds to the cognitive load of understanding the entry point.The fix is straightforward: move each inline command to a dedicated
*_command.gofile inpkg/cli/, following the existingNewXCommand()/RunX()pattern already used by 25+ other commands in the codebase.Full Analysis Report
Focus Area: CLI Command Definition Inconsistency
Current State Assessment
Metrics Collected:
main.gototal linesinit()function linesnew,compile,run,remove/enable/disable,version)pkg/cli/compileCmdinline linesrunCmdinline linesnewCmdinline linesFindings
Strengths
pkg/cli/pattern withNewXCommand()andRunX()functions is well-established and followed consistently by 25+ commandspkg/cli/are testable and follow the*_command.gonaming conventionpkg/cli/Areas for Improvement
compileCmd(126 lines inline inmain.go) — contains real logic in a cobra closure that cannot be unit testedrunCmd(85 lines inline inmain.go) — same issue; run workflow logic is a core user pathnewCmd,removeCmd,enableCmd,disableCmd,versionCmd— smaller but create the same discoverability and testing gapinit()function (~403 lines) could be broken into smaller registration helpersDetailed Analysis
Searching for all inline
var *Cmd = &cobra.Command{...}definitions incmd/gh-aw/main.goreveals:Every other command (
add,logs,audit,mcp,health,checks,pr,secrets,fix,upgrade,validate,hash,domains,project,status,list, etc.) is implemented inpkg/cli/with the properNewXCommand()factory function and is directly testable.The pattern to follow is already well documented in
AGENTS.mdunder "CLI Command Patterns":*_command.goinpkg/cli/logger.New("cli:command_name")NewXCommand()andRunX()functions defined*_command_test.go🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: The following tasks are designed for GitHub Copilot coding agent execution. Please split these into individual work items for Claude to process.
Improvement Tasks
Task 1: Extract
compileCmdfrommain.gotopkg/cli/compile_command.goPriority: High
Estimated Effort: Medium
Focus Area: CLI Command Definition Inconsistency
Description:
The
compileCmdvariable incmd/gh-aw/main.go(lines ~233–359, ~126 lines) defines thecompilecommand inline with real business logic in the cobraRunEclosure. This prevents unit testing and violates thepkg/clicommand pattern.Move it to
pkg/cli/compile_command.gofollowing the exact same structure as other commands likepkg/cli/audit_command.goorpkg/cli/logs_command.go.Acceptance Criteria:
pkg/cli/compile_command.gocontainsNewCompileCommand()factory andRunCompile()testable functioncmd/gh-aw/main.goreplaces the inlinevar compileCmd = &cobra.Command{...}withcompileCmd := cli.NewCompileCommand(validateEngine)--engine,--output,--force,--approve, etc.) preserved with identical behaviorpkg/cli/compile_command_test.gowith at least 3 test cases (valid input, missing file, invalid engine)make agent-finishpasses with no errorsCode Region:
cmd/gh-aw/main.go:233–359, new filepkg/cli/compile_command.goTask 2: Extract
runCmdfrommain.gotopkg/cli/run_command.goPriority: High
Estimated Effort: Medium
Focus Area: CLI Command Definition Inconsistency
Description:
The
runCmdvariable incmd/gh-aw/main.go(lines ~360–445, ~85 lines) defines theruncommand with execution logic inline. This is a critical user path (running workflows) that deserves proper isolation, testing, and documentation inpkg/cli/.Acceptance Criteria:
pkg/cli/run_command.gowithNewRunCommand()andRunWorkflow()functionscmd/gh-aw/main.gousesrunCmd := cli.NewRunCommand(validateEngine)(if engine validation needed) orcli.NewRunCommand()--ref,--engine,--push,--dry-run, etc.)pkg/cli/run_command_test.gowith at least 3 test casesmake agent-finishpasses with no errorsCode Region:
cmd/gh-aw/main.go:360–445, new filepkg/cli/run_command.goTask 3: Extract
newCmd,removeCmd,enableCmd,disableCmdintopkg/cli/Priority: Medium
Estimated Effort: Small
Focus Area: CLI Command Definition Inconsistency
Description:
Four smaller commands (
new,remove,enable,disable) are still defined inline inmain.go. While individually smaller, they contribute to the inconsistency. Consolidate them intopkg/cli/to complete the migration.Acceptance Criteria:
pkg/cli/new_command.gocontainsNewNewCommand()factorypkg/cli/workflow_lifecycle_commands.go(or separate files) containsNewRemoveCommand(),NewEnableCommand(),NewDisableCommand()main.goshrinks by ~120 lines from removing these inline definitionsmake agent-finishpassesCode Region:
cmd/gh-aw/main.go:108–232, new files inpkg/cli/Task 4: Refactor
init()inmain.gointo focused registration helpersPriority: Low
Estimated Effort: Small
Focus Area: CLI Command Definition Inconsistency
Description:
After extracting inline commands (Tasks 1–3), the
init()function will still be long due to manyrootCmd.AddCommand(...)calls and persistent flag setup. Organize this into two or three focused helper functions to make the command registration clear and scannable.Acceptance Criteria:
init()is reduced to ~50 lines by delegating to helpers likeregisterCommands(rootCmd)andregisterPersistentFlags(rootCmd)make agent-finishpassesCode Region:
cmd/gh-aw/main.go:459–862📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions (This Week)
compileCmd— Task 1 above — Priority: High (core user path, large inline block)runCmd— Task 2 above — Priority: High (core user path, currently untestable)Short-term Actions (This Month)
newCmd/removeCmd/enableCmd/disableCmd— Task 3 — Priority: MediumLong-term Actions (This Quarter)
init()— Task 4 — Priority: Low (cleanup after Tasks 1–3 shrink main.go)📈 Success Metrics
Track these metrics to measure improvement in CLI Command Definition Inconsistency:
main.goline count: 895 → ≤ 300 linesinit()function lines: ~403 → ≤ 50pkg/cli/package tests: 25 → 30+ (all commands)Next Steps
main.goline count is the easiest health metricReferences:
Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Beta Was this translation helpful? Give feedback.
All reactions