fix(cli): format nested values as YAML and add --json flag to get#32
Merged
fix(cli): format nested values as YAML and add --json flag to get#32
Conversation
…mand Nested dict/list values were printed as Python repr() which is unreadable and not parseable. Now outputs YAML by default and JSON with --json flag for piping to jq etc.
bdc9957 to
634f720
Compare
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
vaultctl geton structured entries (dicts, lists) outputs Pythonrepr()format — single quotes, no indentation, not parseable byjqor other tools. Example:This makes credentialStore entries with 50+ nested credentials completely unreadable.
Solution
1. Human-readable output: YAML formatting
Added
_format_value()helper (cli.py:35-46) that formats nested values:yaml.dump(default_flow_style=False)str()The
getcommand now calls_format_value(value[f])instead of directly printingvalue[f], so nested structures render as readable YAML with proper indentation.2. Machine-readable output:
--jsonflagNew
--jsonflag on thegetcommand outputs the value as JSON:Works with
--fieldtoo:Uses
json.dumps(indent=2, ensure_ascii=False)for readable JSON that pipes cleanly tojq.Files changed
src/vaultctl/cli.py:_format_value()helper (lines 35-46)--json/output_jsonoption togetcommandvalue[f]to_format_value(value[f])--fieldaccessTest plan
vaultctl get <dict-key>shows readable YAML (not Python repr)vaultctl get <dict-key> --json | jq .parses correctlyvaultctl get <string-key>unchanged (plain string output)vaultctl get <dict-key> --field usernameunchanged