[repository-quality] 🎯 Repository Quality Improvement Report - CLI Flag Boilerplate Duplication & Legacy-Alias Drift #48629
Replies: 0 comments
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.
Analysis Date: 2026-07-28
Focus Area: CLI Flag Boilerplate Duplication & Legacy-Alias Drift
Strategy Type: Custom
Custom Area: Yes —
pkg/clialready has aflags.gomodule with shared helpers (addEngineFlag,addRepoFlag,addOutputFlag,addJSONFlag) specifically to avoid per-command flag duplication, yet a newer deprecated-flag pattern (--no-security-scanner/ legacy--disable-security-scanner) was introduced independently in 5 separate command files instead of being added to this shared module, reintroducing the exact class of duplication the module was built to prevent.Executive Summary
gh-aw's CLI layer (pkg/cli) maintains aflags.gofile whose explicit purpose is to centralize flag registration so commands stay consistent. Despite this, the--no-security-scannerflag (with its deprecated--disable-security-scanneralias) was copy-pasted intoadd_command.go,add_wizard_command.go,deploy_command.go,trial_command.go, andupdate_command.go— five near-identical blocks of registration, deprecation-marking, and OR-fallback resolution logic (~4 lines each, 20+ lines total plus five near-duplicate unit tests). A similar smaller-scale duplication exists for--force-delete-host-repo-before→--delete-host-repo-beforeand--disable-release-bump→--no-release-bump.This drift creates real risk: any future change (new alias, help text tweak, additional mutual-exclusivity rule) must be replicated correctly across all five call sites, and a missed update already shows early divergence —
update_command_test.go's test name (HasDisableSecurityScannerFlag) does not match the naming convention used by the other four tests (DeprecatesDisableSecurityScannerFlag), suggesting the update path wasn't kept in sync with the same rigor.We recommend adding two small helpers to
pkg/cli/flags.go—addSecurityScannerFlag(cmd)and a genericresolveDeprecatedBoolFlag(cmd, newName, oldName string) bool— and migrating all five commands to use them, consolidating ~20 lines of duplicated logic and its associated tests into one authoritative implementation.Full Analysis Report
Focus Area: CLI Flag Boilerplate Duplication & Legacy-Alias Drift
Current State Assessment
pkg/cli/flags.gocurrently exposes 4 shared flag helpers (addEngineFlag,addEngineFilterFlag,addRepoFlag,addOutputFlag,addJSONFlag) — a good pattern that keeps flag definitions DRY. However, the deprecated boolean flag pattern used for security-scanner opt-outs was implemented ad hoc in each consuming command file rather than added to this module.Metrics Collected:
no-security-scanner/disable-security-scannerregistrationadd_command.go,add_wizard_command.go,deploy_command.go,trial_command.go,update_command.go)*_test.go, one inconsistently named)force-delete-host-repo-before,disable-release-bump)flags.goMarkDeprecatedcall sites acrosspkg/cliFindings
Strengths
pkg/cli/flags.goestablishes a clear, working precedent for centralizing repeated flag definitions (engine, repo, output, json).cmd.Flags().MarkDeprecated(...), socobrawill still emit its built-in deprecation warning to users.Areas for Improvement
--no-security-scanner/--disable-security-scannerregistration and OR-resolution logic across 5 files (add_command.go:222-224,add_wizard_command.go:134-136,deploy_command.go:102-104,trial_command.go:129-131,update_command.go:178-180).update_command_test.go:85usesTestNewUpdateCommand_HasDisableSecurityScannerFlagwhile the other four analogous tests use theDeprecates...naming convention, signalling the update path was written independently rather than derived from a shared source of truth.force-delete-host-repo-before/delete-host-repo-beforeintrial_command.go,disable-release-bump/no-release-bumpinupdate_command.go) follow the same one-off pattern and would benefit from the same generic helper.Detailed Analysis
The
--no-security-scannerflag with its--disable-security-scannerlegacy alias appears in:pkg/cli/add_command.go:222-224(register) /:131-133(resolve)pkg/cli/add_wizard_command.go:134-136(register) /:76-78(resolve)pkg/cli/deploy_command.go:102-104(register) /:152-154(resolve)pkg/cli/trial_command.go:129-131(register)pkg/cli/update_command.go:178,180(register) /:86-88(resolve)Each resolve site repeats the identical 3-line idiom:
A single generic helper in
flags.go, e.g.resolveDeprecatedBoolFlag(cmd *cobra.Command, newFlag, oldFlag string) bool, would remove the duplication risk and make future flag deprecations trivially consistent — that helper could also power theforce-delete-host-repo-beforeanddisable-release-bumpcases with no additional code.🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Improvement Tasks
Task 1: Add shared
addSecurityScannerFlaghelper toflags.goPriority: Medium
Estimated Effort: Small
Focus Area: CLI Flag Boilerplate Duplication
Description: Add a new function
addSecurityScannerFlag(cmd *cobra.Command)topkg/cli/flags.gothat registers both--no-security-scannerand the deprecated--disable-security-scanneralias, and marks the legacy one deprecated in a single call, matching the existing help text used in all 5 call sites.Acceptance Criteria:
pkg/cli/flags.gowith doc comment following existing styleCode Region:
pkg/cli/flags.goTask 2: Add generic
resolveDeprecatedBoolFlaghelper and migrate all 5 call sitesPriority: High
Estimated Effort: Medium
Focus Area: CLI Flag Boilerplate Duplication
Description: Add a generic helper
resolveDeprecatedBoolFlag(cmd *cobra.Command, newFlag, oldFlag string) booltopkg/cli/flags.gothat reads both flags and returns true if either is set. Replace the duplicated 3-line OR-resolution idiom inadd_command.go,add_wizard_command.go,deploy_command.go,update_command.go(and the analogous pattern forforce-delete-host-repo-before/delete-host-repo-beforeanddisable-release-bump/no-release-bumpintrial_command.goandupdate_command.go) with a call to this helper. Also replace the direct flag registration in these 5 files that currently duplicate the twocmd.Flags().Bool(...)+MarkDeprecatedcalls for security-scanner with the newaddSecurityScannerFlaghelper from Task 1.Acceptance Criteria:
resolveDeprecatedBoolFlagadded toflags.gowith unit test covering both-unset, new-set, old-set, and both-set casesadd_command.go,add_wizard_command.go,deploy_command.go,trial_command.go,update_command.go) useaddSecurityScannerFlagfor registration instead of duplicatedcmd.Flags().Bool+MarkDeprecatedpairsadd_command.go,add_wizard_command.go,deploy_command.go,update_command.gouseresolveDeprecatedBoolFlaginstead of the manual OR patterntrial_command.go'sforce-delete-host-repo-before/delete-host-repo-beforepair andupdate_command.go'sdisable-release-bump/no-release-bumppair also migrated to useresolveDeprecatedBoolFlagwhere a resolution site existsTestNewUpdateCommand_HasDisableSecurityScannerFlagtoTestNewUpdateCommand_DeprecatesDisableSecurityScannerFlagfor naming consistency with sibling testsgo test ./pkg/cli/...Code Region:
pkg/cli/flags.go,pkg/cli/add_command.go:131-133,222-224,pkg/cli/add_wizard_command.go:76-78,134-136,pkg/cli/deploy_command.go:102-104,152-154,pkg/cli/trial_command.go:118-131,pkg/cli/update_command.go:86-88,177-180In pkg/cli/flags.go, add: func resolveDeprecatedBoolFlag(cmd *cobra.Command, newFlag, oldFlag string) bool { newVal, _ := cmd.Flags().GetBool(newFlag) oldVal, _ := cmd.Flags().GetBool(oldFlag) return newVal || oldVal } Add a doc comment explaining it resolves a new flag against its deprecated legacy alias, returning true if either is set. Then, in each of pkg/cli/add_command.go, pkg/cli/add_wizard_command.go, pkg/cli/deploy_command.go, and pkg/cli/update_command.go, replace the existing 3-line pattern: disableSecurityScanner, _ := cmd.Flags().GetBool("no-security-scanner") disableSecurityScannerLegacy, _ := cmd.Flags().GetBool("disable-security-scanner") disableSecurityScanner = disableSecurityScanner || disableSecurityScannerLegacy with: disableSecurityScanner := resolveDeprecatedBoolFlag(cmd, "no-security-scanner", "disable-security-scanner") Also replace the flag-registration blocks: cmd.Flags().Bool("no-security-scanner", false, "Skip security scanning of workflow markdown content") cmd.Flags().Bool("disable-security-scanner", false, "Skip security scanning of workflow markdown content") _ = cmd.Flags().MarkDeprecated("disable-security-scanner", "use --no-security-scanner instead") in add_command.go, add_wizard_command.go, deploy_command.go, trial_command.go, and update_command.go with a single call: addSecurityScannerFlag(cmd) In trial_command.go, also consider applying resolveDeprecatedBoolFlag if/when a resolution site for force-delete-host-repo-before is added (currently only registered, not read back — verify current usage before changing behavior). In update_command.go, apply resolveDeprecatedBoolFlag to the disable-release-bump/no-release-bump pair if a matching resolution site exists. Rename the test TestNewUpdateCommand_HasDisableSecurityScannerFlag in pkg/cli/update_command_test.go to TestNewUpdateCommand_DeprecatesDisableSecurityScannerFlag to match the naming convention in add_command_test.go, add_wizard_command_test.go, deploy_command_test.go, and trial_command_test.go. Run go test ./pkg/cli/... and make fmt after the change, and ensure all existing flag-deprecation tests still pass unmodified in behavior (only the renamed test name should differ).Task 3: Add regression test for deprecated flag resolution helper edge cases
Priority: Low
Estimated Effort: Small
Focus Area: CLI Flag Boilerplate Duplication / Testing
Description: Add a dedicated
flags_test.go(or extend if it exists) coveringresolveDeprecatedBoolFlagbehavior in isolation: neither flag set (false), only new flag set (true), only legacy flag set (true), both set (true). This guards the new shared helper against regressions independently of the 5 commands that consume it.Acceptance Criteria:
pkg/cli/flags_test.gocontains a table-driven test forresolveDeprecatedBoolFlagcovering all 4 truth-table combinations*cobra.Commandwith both bool flags registered, setting them viacmd.Flags().Set(...)go test ./pkg/cli/... -run TestResolveDeprecatedBoolFlagpassesCode Region:
pkg/cli/flags_test.go📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions (This Week)
addSecurityScannerFlaghelper) — Priority: MediumShort-term Actions (This Month)
pkg/clideprecated-flag pairs (force-delete-host-repo-before,disable-release-bump) for the same consolidation — Priority: Mediumpkg/clipackage doc noting that new deprecated boolean flags should useresolveDeprecatedBoolFlag— Priority: LowLong-term Actions (This Quarter)
pkg/linters) that flags any newcmd.Flags().Bool(...)+MarkDeprecatedpair not routed through the shared helper, to prevent regression — Priority: Low📈 Success Metrics
resolveDeprecatedBoolFlag)Next Steps
Generated by Repository Quality Improvement Agent
Next analysis: 2026-07-29 — Focus area selected by diversity algorithm
All reactions