Skip to content

fix(cli): support json profile output#3448

Merged
jakedoublev merged 7 commits intomainfrom
otdfctl-json-unsupported-paths
May 7, 2026
Merged

fix(cli): support json profile output#3448
jakedoublev merged 7 commits intomainfrom
otdfctl-json-unsupported-paths

Conversation

@jakedoublev
Copy link
Copy Markdown
Contributor

@jakedoublev jakedoublev commented May 7, 2026

Summary

  • add structured JSON output for profile list/get
  • make generic message exits emit JSON when --json is active
  • preserve JSON mode for legacy package-level CLI error helpers

Inspired by: https://trevinsays.com/p/10-principles-for-agent-native-clis

Summary by CodeRabbit

  • New Features

    • Added JSON output support for profile list and profile get commands via --json flag
    • Profile commands now return structured data including store location, endpoint, default status, and authentication details
  • Tests

    • Added end-to-end test coverage for JSON output functionality across profile commands, including error scenarios

Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
@jakedoublev jakedoublev requested a review from a team as a code owner May 7, 2026 19:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

Warning

Rate limit exceeded

@jakedoublev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 15 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6e2fbddd-e410-4737-a26e-436f919aa841

📥 Commits

Reviewing files that changed from the base of the PR and between f1ce05d and 8495cf2.

📒 Files selected for processing (5)
  • otdfctl/cmd/profile.go
  • otdfctl/e2e/kas-keys.bats
  • otdfctl/e2e/profile.bats
  • otdfctl/pkg/cli/cli.go
  • otdfctl/pkg/cli/printer.go
📝 Walkthrough

Walkthrough

This PR extends the otdfctl CLI's profile subcommands to emit structured JSON output alongside human-readable formatting. It introduces default printer state management, refactors error exit handlers to use the new infrastructure, implements JSON payload generation for profile list and get operations, and adds comprehensive E2E test coverage.

Changes

JSON Output for Profile Commands

Layer / File(s) Summary
Printer Infrastructure
otdfctl/pkg/cli/printer.go
Package-level defaultJSONOutput atomic boolean stores the default JSON preference across printer instances; defaultPrinter() constructor initializes new printers from this global state; Printer.setJSON now persists changes to the default.
Error Handling Refactoring
otdfctl/pkg/cli/errors.go
Non-method exit helpers (ExitWithError, ExitWithNotFoundError, ExitWithWarning) now use defaultPrinter() instead of hardcoded printer instances; ExitWithMessage selects stdout vs stderr based on exit code and trims message whitespace for JSON; new statusForExitCode() maps exit codes to "SUCCESS" or "ERROR" status strings.
Profile Command Output DTOs
otdfctl/cmd/profile.go
New output structs: profileListOutput (store + profiles), profileSummary (name + is_default), and profileGetOutput (profile, endpoint, defaults, auth fields).
Profile List and Get JSON
otdfctl/cmd/profile.go
profile list builds and emits a structured JSON payload containing store and per-profile name/default flags alongside the human-readable listing; profile get computes defaults, conditionally populates auth fields for client credentials, and returns both tabular and structured JSON responses.
E2E Test Coverage
otdfctl/e2e/profile.bats
Three new tests: profile list --json validates filesystem entries and default flags; profile get --json validates profile metadata and output_format field; profile get <missing> --json validates JSON error response with status and profile name in message.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The profiles now speak in JSON, how neat,
List and get commands are now complete!
With default states and error flows so tight,
E2E tests confirm the output's right! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change—adding JSON output support for profile commands—and is concise and specific.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch otdfctl-json-unsupported-paths

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the size/m label May 7, 2026
@jakedoublev jakedoublev changed the title fix(otdfctl): support json profile output fix(cli): support json profile output May 7, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the otdfctl CLI by introducing structured JSON output for profile-related commands. By enabling JSON support for both successful data retrieval and error messages, the CLI becomes more suitable for programmatic consumption and integration into automated workflows. The changes include updates to the printer logic, command implementations, and comprehensive end-to-end tests to ensure reliability.

Highlights

  • JSON Output Support: Added structured JSON output capabilities for 'profile list' and 'profile get' commands in the otdfctl CLI.
  • Generic Message Handling: Updated generic message exits to automatically emit JSON when the --json flag is active, ensuring consistent CLI behavior.
  • Legacy Error Support: Refactored legacy package-level CLI error helpers to preserve JSON mode settings.
  • End-to-End Testing: Added new BATS test cases to verify JSON output for profile listing, retrieval, and error scenarios.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


The CLI output is now clean, With JSON for every machine. No more parsing the text, Automation is next, And the data is clearly seen.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 191.140241ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 100.977047ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 417.140609ms
Throughput 239.73 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.470253896s
Average Latency 433.528417ms
Throughput 115.02 requests/second

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements JSON output support for the profile list and profile get commands. It introduces structured output models, updates the CLI's exit and printing logic to handle JSON formatting based on a global state, and adds comprehensive E2E tests. Review feedback suggests optimizing logic by reusing evaluated boolean variables and adhering to CLI conventions by directing error output to os.Stderr.

Comment thread otdfctl/cmd/profile.go Outdated
Comment thread otdfctl/cmd/profile.go Outdated
Comment thread otdfctl/pkg/cli/errors.go
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 170.305698ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 90.298622ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 434.6877ms
Throughput 230.05 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 41.975933779s
Average Latency 417.846186ms
Throughput 119.12 requests/second

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@otdfctl/pkg/cli/printer.go`:
- Around line 35-39: The method setJSON on Printer should not mutate the
package-level defaultJSONOutput global; remove the defaultJSONOutput.Store(json)
call from Printer.setJSON and instead set defaultJSONOutput only when creating a
new Printer (e.g., in newPrinter) so the global default is established at
construction time and not toggled by later SetJSONOutput(false) calls; update
newPrinter to honor an initial json flag and call defaultJSONOutput.Store(json)
there, leaving Printer.setJSON to only adjust the receiver's p.json and
p.enabled fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 99895017-3d3a-4322-896c-c6d4b17096bf

📥 Commits

Reviewing files that changed from the base of the PR and between b4f083b and f1ce05d.

📒 Files selected for processing (4)
  • otdfctl/cmd/profile.go
  • otdfctl/e2e/profile.bats
  • otdfctl/pkg/cli/errors.go
  • otdfctl/pkg/cli/printer.go

Comment thread otdfctl/pkg/cli/printer.go
Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 176.289609ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 89.983997ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 460.66731ms
Throughput 217.08 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.557031868s
Average Latency 444.324282ms
Throughput 112.22 requests/second

Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 143.090046ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 70.546716ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 335.677803ms
Throughput 297.90 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 32.96366899s
Average Latency 328.264409ms
Throughput 151.68 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 171.513362ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 92.221632ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 436.2992ms
Throughput 229.20 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 42.318509079s
Average Latency 420.824235ms
Throughput 118.15 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

@jakedoublev jakedoublev added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit 61f194c May 7, 2026
39 checks passed
@jakedoublev jakedoublev deleted the otdfctl-json-unsupported-paths branch May 7, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants