Refactor pc config to support key-based configuration and commands#90
Merged
Conversation
…mands Replaces the per-setting subcommands (get-api-key, set-api-key, set-color, set-environment) with a generic, registry-driven interface modeled after `gh config` and `aws configure`. A new keyDescriptor in registry.go holds each setting's getter, setter, validator, side-effect hook, short/long descriptions, and sensitivity flag. Adding a new key is supported through a registry entry rather than a command file. Adds `pc config get|set|unset|list|describe <key>`, with --json and --reveal flag support for sensitive values like API keys. The four legacy commands are maintained as hidden, deprecated aliases to maintain functionality for existing users.
`pc config unset` now invokes the onChange hook when clearing a key changes its value, fixing a bug where `unset environment` on staging silently resets to production without clearing the staging-tied OAuth session, API key, or target org/project. `pc config set` now passes the canonical stored value to onChange via a post-set getStr() read, rather than the raw user input. Hooks like environment's now see "production" instead of "prod" when the input is normalized during setStr.
Extract business logic from cobra Run blocks into run* functions that accept a ConfigService interface, enabling unit testing without touching the real viper config store. Add --json output to set and unset commands for machine-readable use. Add a Hidden field to keyDescriptor to suppress internal keys (environment) from list output and tab completion while keeping them accessible by name.
… onChange: add specific fields to keyDescriptor for validateStr, persistStr, and onChange. make sure config set|unset call validateStr, onChange, and then persistStr to avoid onChange failing after persistence has already occurred
…ually checked in ValidateStr
…t reading from viper and bypassing any configured env setting
… state.AuthedUser appropriately if configuring an API key
- Output the normalized stored value rather than the raw user input in pc config set --json (e.g. true instead of on for color aliases) - Include onChange side-effect messages in JSON output for both set and unset so environment changes (logout, key/target clear) are visible to machine consumers, not silently dropped - Treat an unreadable OAuth token record as no active session in the environment onChange hook rather than blocking the operation entirely, unblocking users who authenticate via API key
… settings if present, update tests and documentation
…than any environment variable overrides
…e them in output When PINECONE_API_KEY or PINECONE_ENVIRONMENT is active, config set and unset now write the stored preference without running onChange side effects (auth logout, credential clears), since the env var controls the runtime value regardless of what is in the config file. Config output (get, list, describe) now exposes env_var_name and env_var_override on all keys with an env var binding so users can see when a setting is being overridden and by which variable.
Collaborator
Author
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
1 issue from previous review remains unresolved.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d96200e. Configure here.
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.

Problem
The
pc configcommand exposed configuration through a flat set of verb-noun subcommands —get-api-key,set-api-key,set-color,set-environment— with one Cobra command file per setting. The pattern had a few problems:listequivalent.gh,aws,npm,stripe) handle config, raising the learning curve for new users.This becomes more painful as the set of configurable values grows.
Solution
Refactor
pc configto a generic, registry-driven interface modeled aftergh config. A singlekeyDescriptorininternal/pkg/cli/command/config/registry.goholds each setting's getter, validator, persister, optionalonChangeside-effect hook, short and long descriptions, sensitivity flag, valid values, and env var binding. Theget/set/unset/list/describecommands are generic and dispatch through the registry — adding a new config key is now a single registry entry, no new command file required.New commands
Registry-driven extensibility
Each setting is one entry in
configRegistry. Adding a new key — say, a default output format — would look like:No new command file. No changes to
root.go's skip-auth list. It just works acrossget,set,unset,list, anddescribe.Side-effect hooks
Both
environmentandapi-keycarryonChangehooks:environmentclears OAuth state, the API key, and the target org/project when it changes, then returns human-readable info lines surfaced to the user (and in--jsonoutput).api-keyreconcilesstate.AuthedUser.AuthContextwhen a key is set or cleared — switching toAuthDefaultAPIKey, falling back through service-account or OAuth, or clearing toAuthNone.Hooks fire from both
setandunset. They are skipped when an env var is actively overriding the key — writing the config file doesn't change the runtime value in that case, so auth side effects would be incorrect.Env var override visibility
Keys with an env var binding (
PINECONE_API_KEY,PINECONE_ENVIRONMENT) now surface override state in all read commands.get,list, anddescribereport the env var name and whether it's currently overriding the stored value.describe --jsonincludesenv_var_nameandenv_var_overridefields;long_descriptionis omitted from JSON output (it's help text for human display only).Flags
--jsononget,set,unset,list,describefor machine-readable output. Forsetandunset, JSON output includes anyonChangeside-effect messages so machine consumers can observe auth state changes.--revealonget,list,describeto unmask sensitive values (defaults to masking head/tail forapi-key).--allonlistto include hidden keys (e.g.environment).Color aliases
coloracceptstrue/false,on/off, and1/0— all normalized totrue/falseon write.Backwards compatibility
The four legacy commands (
get-api-key,set-api-key,set-color,set-environment) are preserved as hidden, deprecated aliases. They continue to function and print Cobra's standard deprecation notice pointing at the new equivalent:Existing scripts and docs keep working; new users land on the new pattern.
Type of Change
The legacy commands are kept as hidden aliases, so this is non-breaking for existing users. Docs referencing
pc config set-api-keyetc. should be updated to usepc config set api-key <value>going forward.Test Plan
just test-unitpassespc config list— confirms all keys render with descriptions and env var columnspc config list --all— confirms hidden keys (environment) appearpc config get api-key— confirms<not set>placeholder for empty valuespc config get api-key --reveal— confirms full value shown when revealedpc config set environment staging— confirms OAuth/API key/target wipe firespc config unset environment(from staging) — confirms same wipe firespc config set environment prod— confirms canonicalproductionis stored and reportedpc config set color on/off/1/0— confirms aliases normalize correctlypc config set api-key <value>— confirmsAuthContextflips toAuthDefaultAPIKeypc config unset api-key— confirmsAuthContextfalls back correctlypc config describe api-key/environment/color— confirms ENV VAR rows present for bound keys, long description rendered below tablePINECONE_API_KEY=x pc config get api-key— confirmsENV VAR OVERRIDE: trueshownPINECONE_ENVIRONMENT=staging pc config set environment staging— confirms config file updated, no auth side effects firedpc config set api-key <value> --json/pc config set environment staging --json— confirms structured output includes onChange messagespc config describe api-key --json— confirmslong_descriptionabsent from JSON outputpc config get-api-key/set-api-key/set-color/set-environment— confirms each still works and prints deprecation notice--jsononget,list,describe— confirms structured output