Skip to content

refactor(flag): align pkg/common/flag with KHI coding rules - #1324

Open
kyasbal wants to merge 1 commit into
mainfrom
push-tvrwumxnztmn
Open

kyasbal wants to merge 1 commit into
mainfrom
push-tvrwumxnztmn

Conversation

@kyasbal

@kyasbal kyasbal commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Aligns pkg/common/flag with KHI Go coding and testing conventions without changing exported APIs:

  • Consolidates duplicated String/Bool/Int/Float64 registration logic into a shared generic registerFlag[T] helper with formatUsageWithEnvKey, isProvidedFromCommandLineArgs, and lookupEnvValue (os.LookupEnv).
  • Replaces strconv.ParseInt(envValue, 10, 64) + int(...) with strconv.Atoi to prevent silent 64-to-32-bit overflow truncation on 32-bit targets, and wraps integer/float environment variable parse errors with %w and contextual flag/env metadata.
  • Switches DumpAll to strings.Builder, updates Reset to clear slices to nil, and clarifies package and function GoDoc comments (including non-concurrency of package-global state and existing Bool/Reset/Parse contracts).
  • Fixes ambient FOO isolation and a coincidental pass in TestBool, updates setCommandlineArguments to use flag.ContinueOnError and t.Cleanup, and adds focused tests for Parsed, Reset, DumpAll, PrintDefaults, and env-var parse errors (85.8% → 100.0% statement coverage).

Verification

  • make pre-push — PASS (0 mustfix, 0 advisory, 0 skipped)
  • make qa-all-advisory CODEQUALITY_SIMILARITY=true — PASS (0 mustfix, 0 advisory, 0 skipped; 17/17 mutants killed, 0 similarity advisories)
  • go test -race -count=1 -cover ./pkg/common/flag/... ./pkg/parameters/... ./pkg/core/init/default/... — PASS (pkg/common/flag: 100.0% statement coverage)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the pkg/common/flag package to reduce code duplication and improve performance. It introduces a generic registerFlag helper function to unify the registration of different flag types (String, Bool, Int, Float64) and optimizes DumpAll using strings.Builder. Additionally, it expands test coverage significantly by adding comprehensive unit tests for Parsed, Reset, DumpAll, PrintDefaults, and environment variable parsing errors. I have no further feedback to provide as the changes are clean and well-tested.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Go Quality Report (origin/main) — ✅ PASS

Metric Result
Changed Scope 1 prod file(s), 1 test file(s), 32 unit(s)
Patch Coverage 100.0% (43/43 lines)
Mutation Score 100.0% (17/17 killed, 0 survived)
Function Similarity OK (4 new unit(s), 0 matches across 3194 corpus units)

Commit: 9936524d2338 · Cloud Build Logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant