Improve jsonpointer CLI: support positional pointer argument - #81
Open
stefankoegl wants to merge 4 commits into
Open
stefankoegl wants to merge 4 commits into
stefankoegl wants to merge 4 commits into
Conversation
`jsonpointer -f ptr.txt a.json b.json` failed because argparse assigned a.json to the optional positional POINTER, which was in a mutually exclusive group with -f. Move POINTER out of the group and treat it as the first file whenever the pointer is given via -f or the new -p/--pointer option. The existing `jsonpointer /a a.json b.json` usage keeps working unchanged. Fixes #43, backwards compatible alternative to #44. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019xLCiTJTbWQ9Nt7UHq2yiU
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Multi-file invocations without a pointer can incorrectly exit successfully after processing arguments incorrectly.
Review effort: Balanced
Findings: None
What changed in this PR
Adds positional JSON pointer support while retaining -p and -f input methods.
Changes:
- Adds flexible pointer and file argument parsing.
- Improves CLI error handling and tests.
- Updates command-line documentation and examples.
| File | Description |
|---|---|
bin/jsonpointer |
Implements positional pointer parsing and deferred file opening. |
tests.py |
Adds CLI integration tests. |
doc/commandline.rst |
Documents the expanded CLI syntax. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
When the pointer was omitted, e.g. `jsonpointer a.json b.json`, the first file was taken as the pointer, every file failed to resolve and the command still exited with status 0. Validate the pointer before processing any files and exit with a usage error if it is not a valid JSON pointer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019xLCiTJTbWQ9Nt7UHq2yiU
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
This PR enhances the jsonpointer command-line utility to accept the JSON pointer as a positional argument, in addition to the existing
-f(file) and-p(option) methods. This makes the CLI more intuitive and user-friendly.Key Changes
Flexible pointer specification: The JSON pointer can now be provided in three ways:
jsonpointer /a file.json-poption:jsonpointer -p /a file.json-foption reading from file:jsonpointer -f ptr.txt file.jsonImproved argument parsing:
required=True)-p/--pointeroption for explicit pointer specificationFILEargument fromFileType('r')tostrto allow flexible file handlingparse_pointer()function to intelligently determine which argument is the pointer and which are filesBetter error handling:
-pand-fare mutually exclusiveparser.error()Comprehensive test coverage: Added
CommandLineTestsclass with 6 test cases covering:-f) with single and multiple files-p) with multiple filesUpdated documentation: Clarified usage examples and help text to reflect the new positional argument capability
Implementation Details
The key logic change is in
parse_pointer()which now:-por-foptions are providedPOINTERpositional argument as the first filePOINTERas the actual pointerhttps://claude.ai/code/session_019xLCiTJTbWQ9Nt7UHq2yiU