feat: make --config-file take precedence over environment variables #438
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
Fixes #436 - When
--config-fileis explicitly specified, environment variables are now ignored to provide true configuration isolation.Problem
Previously, environment variables always took precedence over config files, even when
--config-filewas explicitly specified. This made it impossible to achieve true configuration isolation for testing and violated the principle of "explicit wins" in CLI design.Old behavior (problematic):
Solution
New behavior:
When
--config-fileis explicitly provided, environment variables are completely ignored for credential resolution.Changes
config_pathwas explicitly providedcreate_cloud_client()andcreate_enterprise_client()skip env var checks whenconfig_pathisSome()ApiCommandParamswasn't preservingconfig_path, causing it to be lostTesting
New Tests
test_config_file_overrides_env_vars: Verifies env vars are ignored when--config-fileis specifiedtest_env_vars_work_without_config_file: Verifies env vars still work without--config-fileTest Results
Benefits
--config-filewithout worrying about env varskubectl --kubeconfig,git --config, etc.--config-fileis explicitly usedExample
Before (env vars override config file):
After (config file wins when explicit):
Without --config-file (env vars still work):
Closes #436