fix: Load config from --config flag before vault path resolution#68
Merged
fix: Load config from --config flag before vault path resolution#68
Conversation
Fixes #65 The --config flag was not being respected because cobra.OnInitialize() ran before flags were parsed. This caused pass-cli to require a vault at the default location even when a custom vault_path was specified in a config file passed via --config. Changes: - Move initConfig() call from cobra.OnInitialize to PersistentPreRunE - Pass custom vault path from config to DetectFirstRun() - Add RunCmdWithEnv test helper for isolated environment testing - Add integration test for --config flag behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
…st isolation - Add early return in checkFirstRun for version and help commands to avoid unnecessary config loading and potential errors from malformed config files - Update RunCmdWithEnv to only inherit PATH, requiring callers to explicitly provide HOME for proper test isolation - Add documentation clarifying the test helper's isolation behavior Co-Authored-By: Claude <noreply@anthropic.com>
On macOS, keychain access is tied to the user session and requires specific environment variables (HOME, USER, TMPDIR) to be set correctly. Overriding HOME to a fake directory breaks keychain access and causes the init command to hang waiting for authorization. Changes: - Update RunCmdWithEnv to pass through essential macOS env vars - Update config_flag_test to not override HOME on macOS - Add runtime import for GOOS detection This fixes the CI timeout on macOS for TestIntegration_ConfigFlagWithoutDefaultVault. Co-Authored-By: Claude <noreply@anthropic.com>
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
Fixes #65
The
--configflag was not being respected becausecobra.OnInitialize()ran before flags were parsed. This caused pass-cli to require a vault at the default location even when a customvault_pathwas specified in a config file passed via--config.Root cause: Config loading happened in
cobra.OnInitialize()which executes before Cobra parses command-line flags. This meantcfgFilewas always empty wheninitConfig()ran.Fix: Move
initConfig()call fromcobra.OnInitializetoPersistentPreRunE(checkFirstRun), which runs after flags are parsed.Changes
cobra.OnInitialize(initConfig)frominit()initConfig()at the start ofcheckFirstRun()(PersistentPreRunE)DetectFirstRun()RunCmdWithEnvtest helper for isolated environment testing--configflag works without default vaultTest plan
TestIntegration_ConfigFlagWithoutDefaultVaultpasses--configflag when no default vault exists🤖 Generated with Claude Code