feat(ls & ps): add --json flag for machine readable output#160
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a --json output mode to the datatrail ls and datatrail ps CLI commands to support machine-readable consumption (per Issue #159), and updates tests/docs accordingly.
Changes:
- Add
--jsonflag tolsandpscommands and emit JSON to stdout. - Update CLI help tests to be resilient to help-text changes and add new JSON-output tests.
- Extend user docs for
lsandpswith JSON examples and scripting guidance.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
dtcli/ls.py |
Adds --json flag and JSON emission for ls. |
dtcli/ps.py |
Adds --json flag and JSON emission for ps (including JSON-formatted errors in some paths). |
tests/test_cli.py |
Updates help assertions and adds tests validating JSON output shapes. |
docs/list.md |
Documents --json for ls and adds scripting examples. |
docs/ps.md |
Documents --json for ps and adds scripting examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+79
to
+84
| # Output JSON if requested. | ||
| if output_json: | ||
| print(json.dumps(results, indent=2)) | ||
| if "error" in results: | ||
| ctx.exit(1) | ||
| return |
Comment on lines
+79
to
+88
| if output_json: | ||
| import json | ||
|
|
||
| print( | ||
| json.dumps( | ||
| {"error": {"files": str(files), "policies": str(policies)}}, | ||
| indent=2, | ||
| ) | ||
| ) | ||
| ctx.exit(1) |
Comment on lines
+105
to
+112
| result = { | ||
| "dataset": dataset, | ||
| "scope": scope, | ||
| "files": files, | ||
| "policies": policies, | ||
| } | ||
| print(json.dumps(result, indent=2)) | ||
| return None |
Comment on lines
+590
to
+592
| json_start = result.output.find("{") | ||
| json_output = result.output[json_start:] | ||
| # Parse the output as JSON |
Comment on lines
+611
to
+613
| json_start = result.output.find("{") | ||
| json_output = result.output[json_start:] | ||
| # Parse the output as JSON |
Comment on lines
+634
to
+636
| json_start = result.output.find("{") | ||
| json_output = result.output[json_start:] | ||
| # Parse the output as JSON |
Comment on lines
+657
to
+659
| json_start = result.output.find("{") | ||
| json_output = result.output[json_start:] | ||
| # Parse the output as JSON |
Comment on lines
+149
to
+152
| # Get all scopes | ||
| result = subprocess.run(["datatrail", "ls", "--json"], capture_output=True, text=True) | ||
| data = json.loads(result.stdout) | ||
| scopes = data["scopes"] |
Comment on lines
+136
to
+143
| # Get dataset information | ||
| result = subprocess.run( | ||
| ["datatrail", "ps", "kko.event.baseband.raw", "308892599", "--json"], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| data = json.loads(result.stdout) | ||
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #160 +/- ##
==========================================
+ Coverage 65.68% 66.77% +1.09%
==========================================
Files 15 15
Lines 1399 1472 +73
==========================================
+ Hits 919 983 +64
- Misses 480 489 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3 similar comments
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.
fixes #159