Skip to content

fix: Load config from --config flag before vault path resolution#68

Merged
arimxyer merged 3 commits intomainfrom
fix/issue-65-config-flag-loading
Jan 24, 2026
Merged

fix: Load config from --config flag before vault path resolution#68
arimxyer merged 3 commits intomainfrom
fix/issue-65-config-flag-loading

Conversation

@arimxyer
Copy link
Copy Markdown
Owner

Summary

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.

Root cause: Config loading happened in cobra.OnInitialize() which executes before Cobra parses command-line flags. This meant cfgFile was always empty when initConfig() ran.

Fix: Move initConfig() call from cobra.OnInitialize to PersistentPreRunE (checkFirstRun), which runs after flags are parsed.

Changes

  • Remove cobra.OnInitialize(initConfig) from init()
  • Call initConfig() at the start of checkFirstRun() (PersistentPreRunE)
  • Pass custom vault path from config to DetectFirstRun()
  • Add RunCmdWithEnv test helper for isolated environment testing
  • Add integration test verifying --config flag works without default vault

Test plan

  • All existing tests pass
  • New integration test TestIntegration_ConfigFlagWithoutDefaultVault passes
  • Verified init, add, get, list, and doctor commands work with --config flag when no default vault exists

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

arimxyer and others added 2 commits January 24, 2026 01:12
…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>
@arimxyer arimxyer merged commit f01d769 into main Jan 24, 2026
14 checks passed
@arimxyer arimxyer deleted the fix/issue-65-config-flag-loading branch January 24, 2026 06:54
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.

requires dummy vault in default path in order to specify vault_path via config

1 participant