Skip to content

feat(ls & ps): add --json flag for machine readable output#160

Merged
tjzegmott merged 1 commit into
mainfrom
feat---json-flag
Jul 7, 2026
Merged

feat(ls & ps): add --json flag for machine readable output#160
tjzegmott merged 1 commit into
mainfrom
feat---json-flag

Conversation

@tjzegmott

Copy link
Copy Markdown
Contributor

fixes #159

Copilot AI review requested due to automatic review settings July 7, 2026 14:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 --json flag to ls and ps commands 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 ls and ps with 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 thread dtcli/ls.py
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 thread dtcli/ps.py
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 thread dtcli/ps.py
Comment on lines +105 to +112
result = {
"dataset": dataset,
"scope": scope,
"files": files,
"policies": policies,
}
print(json.dumps(result, indent=2))
return None
Comment thread tests/test_cli.py
Comment on lines +590 to +592
json_start = result.output.find("{")
json_output = result.output[json_start:]
# Parse the output as JSON
Comment thread tests/test_cli.py
Comment on lines +611 to +613
json_start = result.output.find("{")
json_output = result.output[json_start:]
# Parse the output as JSON
Comment thread tests/test_cli.py
Comment on lines +634 to +636
json_start = result.output.find("{")
json_output = result.output[json_start:]
# Parse the output as JSON
Comment thread tests/test_cli.py
Comment on lines +657 to +659
json_start = result.output.find("{")
json_output = result.output[json_start:]
# Parse the output as JSON
Comment thread docs/list.md
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 thread docs/ps.md
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-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.60759% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.77%. Comparing base (7c01e86) to head (c4742a0).

Files with missing lines Patch % Lines
dtcli/ps.py 46.66% 8 Missing ⚠️
dtcli/ls.py 85.71% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 66.78% (+1.1%) from 65.69% — feat---json-flag into main

3 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 66.78% (+1.1%) from 65.69% — feat---json-flag into main

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 66.78% (+1.1%) from 65.69% — feat---json-flag into main

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 66.78% (+1.1%) from 65.69% — feat---json-flag into main

@tjzegmott tjzegmott merged commit 75dac4d into main Jul 7, 2026
7 checks passed
@tjzegmott tjzegmott deleted the feat---json-flag branch July 7, 2026 14:50
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.

Add --json flag for machine-readable output on ls and ps commands

4 participants