refactor: unify CLI flags into shared CommonFlags struct#2556
Draft
justinvreeland wants to merge 6 commits into
Draft
refactor: unify CLI flags into shared CommonFlags struct#2556justinvreeland wants to merge 6 commits into
justinvreeland wants to merge 6 commits into
Conversation
bccdd34 to
74d17f2
Compare
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/.
b134ccb to
2114a76
Compare
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.
2114a76 to
a18f3b7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CommonFlagsstruct with a singleaddCommonFlagsregistration functionCommonFlagsinBuildFlags,TestFlags, and newCompileFlags(replacing bare local vars in compile)applyCommonConfighelper toproject_config_apply.goand simplify existingApplyToBuildFlags/ApplyToTestFlagsApplyToCompileFlagsand wire project config into the compile command'sRunEDesign decisions
addCommonFlagsreads pre-set struct field values as pflag defaults — callers set fields likeRemoveandCacheDirbefore calling, no post-registration hacks--rmdefaults:true(build/test),false(compile) — matches existing behavior--cache-dirdefaults:./melange-cache/(build/compile),""(test) — matches existing behaviorarchstays per-command:[]stringin build/test,stringin compilebuild:+global:config sections (no new YAML section needed)🤖 Generated with Claude Code