You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ProductEntity and derived params become stale when --product overrides TOML/env via second getopt.Parse() #742
In lib/param_parsing/parameters.go, populateParams calls setupProductParam (~line 189) to set ProductEntity, default MirrorURL, and default CustomBinaryPath based on the resolved params.Product. However, a second getopt.Parse() is called later (~line 241) to enforce "CLI always wins" semantics.
If a user specifies --product on the CLI and a different product value appears in a TOML config file, the sequence is:
First getopt.Parse() – CLI value is applied (e.g. opentofu).
getParamsTOML() – TOML overrides with a different value (e.g. terraform).
GetParamsFromEnvironment() – env-based product may apply.
setupProductParam() – resolves ProductEntity, MirrorURL, CustomBinaryPath from the current (TOML/env) value of params.Product.
Second getopt.Parse() – re-applies the CLI value, so params.Product becomes opentofu again…
…but ProductEntity, MirrorURL, and CustomBinaryPath still reflect terraform from step 4.
This means the product-derived defaults are inconsistent with params.Product after the second parse, which can lead to the wrong binary path and mirror URL being used.
Steps to Reproduce:
Create a ~/.tfswitch.toml containing product = "terraform".
Run tfswitch --product opentofu.
Observe that the effective mirror URL and binary path may still resolve to Terraform's defaults instead of OpenTofu's.
Possible Fix: Call setupProductParam(¶ms) after the second getopt.Parse(), or guard it so it only resets defaults that haven't been explicitly set.
Context: Identified during review of PR #739 (commit 7ba67d7). Not introduced by that PR — this is a latent issue in the existing parameter-resolution flow.
The stale ProductEntity behavior sounds like precedence is being applied in more than one place. A cleaner fix would centralize product resolution after CLI/env/TOML parsing, then derive all product-specific params from that final value once. The regression test should cover TOML default, env override, and --product override together so the second getopt.Parse() path cannot reintroduce stale derived fields.
Activity
fix: Handle correct resetup of product entity when product entity is …
hiSandog commentedon Jul 3, 2026
The stale
ProductEntitybehavior sounds like precedence is being applied in more than one place. A cleaner fix would centralize product resolution after CLI/env/TOML parsing, then derive all product-specific params from that final value once. The regression test should cover TOML default, env override, and--productoverride together so the secondgetopt.Parse()path cannot reintroduce stale derived fields.