[repository-quality] Repository Quality Improvement — main.go Modularization (2026-04-17) #26871
Closed
Replies: 1 comment
-
|
This discussion was automatically closed because it expired on 2026-04-18T13:23:42.486Z.
|
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 — main.go Modularization
Analysis Date: 2026-04-17
Focus Area: main.go Modularization
Strategy Type: Custom
Custom Area: Yes — This focus area was selected because
cmd/gh-aw/main.gohas grown to 895 lines and contains inline cobra.Command definitions for 9 commands — in stark contrast to the 29 commands that have already been properly extracted topkg/cli/. This creates a maintenance inconsistency and makes the entry point unnecessarily large.Executive Summary
cmd/gh-aw/main.gois 895 lines long and acts as both an application entry point and a command definition file for several core commands:compile,run,new,remove,enable,disable, andversion. These commands contain fullcobra.Commandstructs withLongdescriptions,RunEhandlers, and 103 inline flag registrations scattered throughout a largeinit()function spanning lines ~460–861.This contrasts with 29 other commands (e.g.,
audit,add,fix,validate,logs,mcp,checks) that have been cleanly extracted topkg/cli/*_command.gofiles following the project's established patterns. Notably,compile_command.goandrun_command.goeven contain explicit comments acknowledging they are "compatibility bridges" — meaning the extraction intent exists but the cobra.Command definitions and flag setup remain inmain.go.Completing the extraction would reduce
main.goto a clean entry point (~200 lines), improve discoverability of command implementations, and align all commands with theNewXCommand()pattern used throughout the codebase.Full Analysis Report
Focus Area: main.go Modularization
Current State Assessment
Metrics Collected:
main.gototal linescobra.Commanddefinitions inmain.gomain.gopkg/cli/compileCmdflagsrunCmdflagsinit()function spanFindings
Strengths
NewXCommand(...)extraction patterncompile_command.goandrun_command.gocontain explicit comments acknowledging the split — the intent is clearcompileis already split across 6 dedicated files (compile_config.go,compile_helpers.go,compile_validation.go,compile_watch.go,compile_campaign.go,compile_orchestrator.go)runhas been moved torun_workflow_tracking.goand related filesmain.goand are well-structuredAreas for Improvement
compileCmd(127 lines + 32 flags) is the largest inline command and has the most flags — its extraction is explicitly hinted by the existingcompile_command.gocommentrunCmd(86 lines + 11 flags) similarly hasrun_command.gomarked as a "compatibility bridge"newCmd(58 lines) defines interactive workflow creation inline with no extracted counterpartenableCmd(19 lines) anddisableCmd(21 lines) are small but inconsistently placedremoveCmd(27 lines) andversionCmd(small) could be extracted for completenessDetailed Analysis
The project already has a clear pattern for command organization:
The
init()function inmain.gowires these up:The same pattern should be applied to
compileCmd,runCmd,newCmd,enableCmd,disableCmd, andremoveCmd. ThevalidateEnginefunction (already used byNewAddCommand) can be passed as a parameter to commands that need it.The massive
init()would then shrink to just:Estimated
main.goreduction: ~500 lines → ~300 lines.🤖 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 the coding agent to process sequentially (later tasks may depend on earlier ones).
Improvement Tasks
Task 1: Extract
compileCmdfrom main.go to pkg/cli/compile_command.goPriority: High
Estimated Effort: Medium
Focus Area: main.go Modularization
Description:
cmd/gh-aw/main.godefinesvar compileCmd = &cobra.Command{...}inline (127 lines) along with 32 flag registrations ininit(). The filepkg/cli/compile_command.gocurrently contains only a comment saying "The compile functionality has been split into: ...". The task is to move thecobra.Commanddefinition and all its flag registrations into aNewCompileCommand(validateEngine func(string) error) *cobra.Commandfunction inpkg/cli/compile_command.go, then updatemain.goto callcli.NewCompileCommand(validateEngine).Acceptance Criteria:
NewCompileCommand(validateEngine func(string) error) *cobra.Commandis defined inpkg/cli/compile_command.goLongdescription,Use,Short,Args, andRunEare preserved exactlymain.goreplacescompileCmdvar definition withcompileCmd := cli.NewCompileCommand(validateEngine)make build && make test-unitpass with no regressionsCode Region:
cmd/gh-aw/main.go:233–359andpkg/cli/compile_command.goTask 2: Extract
runCmdfrom main.go to pkg/cli/run_command.goPriority: High
Estimated Effort: Medium
Focus Area: main.go Modularization
Description:
cmd/gh-aw/main.godefinesvar runCmd = &cobra.Command{...}inline (86 lines) with 11 flag registrations. The filepkg/cli/run_command.gocurrently says "This file now serves as a compatibility bridge." Move thecobra.Commanddefinition toNewRunCommand(validateEngine func(string) error) *cobra.Commandinpkg/cli/run_command.go.Acceptance Criteria:
NewRunCommand(validateEngine func(string) error) *cobra.Commandis defined inpkg/cli/run_command.goRunEmain.goreplaces therunCmdvar withrunCmd := cli.NewRunCommand(validateEngine)make build && make test-unitpass with no regressionsCode Region:
cmd/gh-aw/main.go:360–445andpkg/cli/run_command.goTask 3: Extract
newCmdfrom main.go to pkg/cli/new_command.goPriority: Medium
Estimated Effort: Small
Focus Area: main.go Modularization
Description:
cmd/gh-aw/main.godefinesvar newCmd = &cobra.Command{...}inline (58 lines) with 3 flags. There is no existingpkg/cli/new_command.go. Create this file withNewNewCommand(validateEngine func(string) error) *cobra.Commandfollowing the existing patterns.Acceptance Criteria:
pkg/cli/new_command.gois created withNewNewCommand(validateEngine func(string) error) *cobra.Command//go:build !integrationbuild tag at the very topmain.goreplacesvar newCmdwithnewCmd := cli.NewNewCommand(validateEngine)make build && make test-unitpassCode Region:
cmd/gh-aw/main.go:108–165→ new filepkg/cli/new_command.goTask 4: Extract
enableCmdanddisableCmdfrom main.goPriority: Medium
Estimated Effort: Small
Focus Area: main.go Modularization
Description:
cmd/gh-aw/main.godefinesvar enableCmd(19 lines) andvar disableCmd(21 lines) with 1 flag each (--repo). Extract both topkg/cli/enable_disable_command.goor separate files.Acceptance Criteria:
NewEnableCommand() *cobra.CommandandNewDisableCommand() *cobra.Commandare created inpkg/cli/(single file or separate files per project convention)//go:build !integrationbuild tag at top--repoflag is registered inside each command functionmain.gois updated to use the new constructorsmake build && make test-unitpassCode Region:
cmd/gh-aw/main.go:193–232→pkg/cli/enable_command.goandpkg/cli/disable_command.go📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions (This Week)
compileCmd— Priority: High — Biggest impact, most flags, clear extraction pathrunCmd— Priority: High — Second largest, marked as "compatibility bridge"Short-term Actions (This Month)
newCmd— Priority: Medium — Small effort, completes the interactive commands extractionenableCmd/disableCmd— Priority: Medium — Quick wins for consistencyLong-term Actions (This Quarter)
removeCmdandversionCmd— Priority: Low — Small files, complete the extractionNew*Command()function has a corresponding test verifying flag registration and basic invocation📈 Success Metrics
Track these metrics to measure improvement in main.go Modularization:
main.goline count: 895 → target ≤ 300 linescobra.Commanddefinitions: 9 → target ≤ 2 (onlyrootCmd+ custom help)init(): 103 → target ≤ 10 (only global persistent flags)New*Command()pattern: 29 → target 35+ (after all extractions)Next Steps
main.goline count is below 350References:
Beta Was this translation helpful? Give feedback.
All reactions