Skip to content

refactor: unify CLI flags into shared CommonFlags struct#2556

Draft
justinvreeland wants to merge 6 commits into
chainguard-dev:mainfrom
justinvreeland:jvreeland/unify-common-flags
Draft

refactor: unify CLI flags into shared CommonFlags struct#2556
justinvreeland wants to merge 6 commits into
chainguard-dev:mainfrom
justinvreeland:jvreeland/unify-common-flags

Conversation

@justinvreeland

Copy link
Copy Markdown
Member

Summary

  • Extract ~20 shared flags from build/test/compile into a CommonFlags struct with a single addCommonFlags registration function
  • Embed CommonFlags in BuildFlags, TestFlags, and new CompileFlags (replacing bare local vars in compile)
  • Add applyCommonConfig helper to project_config_apply.go and simplify existing ApplyToBuildFlags/ApplyToTestFlags
  • Add ApplyToCompileFlags and wire project config into the compile command's RunE
  • Add compile project config tests

Design decisions

  • addCommonFlags reads pre-set struct field values as pflag defaults — callers set fields like Remove and CacheDir before calling, no post-registration hacks
  • --rm defaults: true (build/test), false (compile) — matches existing behavior
  • --cache-dir defaults: ./melange-cache/ (build/compile), "" (test) — matches existing behavior
  • arch stays per-command: []string in build/test, string in compile
  • Compile uses build: + global: config sections (no new YAML section needed)

🤖 Generated with Claude Code

@justinvreeland justinvreeland force-pushed the jvreeland/unify-common-flags branch 4 times, most recently from bccdd34 to 74d17f2 Compare June 3, 2026 18:08
Add ProjectConfig, GlobalConfig, BuildSectionConfig, and TestSectionConfig
types for the .melange.yaml project-level config file. LoadProjectConfig
uses yaml.v3 with KnownFields(true) to catch typos. FindProjectConfig
auto-detects the file in cwd. Context helpers store/retrieve the config.
ApplyToBuildFlags and ApplyToTestFlags methods merge config values into
CLI flag structs using pflag.Changed() for precedence: CLI flags override
config file values. Build/test sections override global section. Typed
helpers for string, bool, slice, and duration fields.
Add --config-file persistent flag to the root melange command. In
PersistentPreRunE, auto-detect .melange.yaml in cwd (or use explicit
path), load it, and store on the command context for subcommands.
Wire up ProjectConfigFromContext in buildCmd().RunE and test().RunE to
apply config file defaults before flag processing. Config values only
take effect when the corresponding CLI flag was not explicitly set.
Seven test cases: valid loading, unknown field rejection, CLI override
precedence, config overrides defaults, build section overrides global,
nil config no-op, and test flag application. Two YAML fixtures in
testdata/.
@justinvreeland justinvreeland force-pushed the jvreeland/unify-common-flags branch 3 times, most recently from b134ccb to 2114a76 Compare June 3, 2026 22:49
Extract ~20 shared flags from build/test/compile into a CommonFlags struct
with a single addCommonFlags registration function. Embed CommonFlags in
BuildFlags, TestFlags, and new CompileFlags. Add applyCommonConfig helper
to project_config_apply.go and wire project config into compile command.
@justinvreeland justinvreeland force-pushed the jvreeland/unify-common-flags branch from 2114a76 to a18f3b7 Compare June 3, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant