Skip to content

feat(cli): add --output json/yaml to sandbox get, status, and sandbox create#1

Open
rhuss wants to merge 1 commit into
mainfrom
feat/cli-structured-output
Open

feat(cli): add --output json/yaml to sandbox get, status, and sandbox create#1
rhuss wants to merge 1 commit into
mainfrom
feat/cli-structured-output

Conversation

@rhuss

@rhuss rhuss commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

Add --output json/yaml support to three CLI commands that previously only had human-readable output:

  • sandbox get: Structured sandbox detail with policy source, revision, and active policy content
  • status: Gateway connection state with conditional fields (auth, version, error, http_status)
  • sandbox create: Sandbox metadata emitted after Ready phase, human chrome suppressed from stdout

All three commands reuse the existing OutputFormat enum and print_output_single helper. Default behavior (no --output flag) is byte-identical to current output.

Test plan

  • 182 unit tests pass (cargo test --lib)
  • 5 new unit tests for sandbox_detail_to_json and status_to_json converters
  • cargo clippy clean, cargo fmt clean
  • Smoke-tested against live gateway: sandbox get --output json, status --output json/yaml, default output regression check (byte-identical)
  • Deep review (5 agents + CodeRabbit): 4 Critical/Important findings found and fixed

Closes NVIDIA#1964

Assisted-By: 🤖 Claude Code

Summary by CodeRabbit

  • New Features
    • Added --output/-o (default: table) for gateway status, sandbox create, and sandbox get to enable machine-readable JSON/YAML.
    • gateway status now returns structured output (e.g. {"status":"not_configured"}) when no gateway is configured.
    • sandbox get: --policy-only is mutually exclusive with --output; sandbox create uses structured output during provisioning (skipping the interactive session flow).
  • Documentation
    • Updated gateway/sandbox docs with --output json/--output yaml automation examples.
  • Tests
    • Updated integration tests to reflect the new output-format behavior.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@rhuss, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 43 minutes and 49 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9fe1599-867a-4c67-8030-c9440cf71d47

📥 Commits

Reviewing files that changed from the base of the PR and between b88a214 and f067c05.

📒 Files selected for processing (6)
  • crates/openshell-cli/src/main.rs
  • crates/openshell-cli/src/run.rs
  • crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs
  • crates/openshell-cli/tests/sandbox_name_fallback_integration.rs
  • docs/sandboxes/manage-gateways.mdx
  • docs/sandboxes/manage-sandboxes.mdx
📝 Walkthrough

Walkthrough

Adds --output/-o to status, sandbox create, and sandbox get. Non-table output now returns structured JSON for gateway status and sandbox details, while table output keeps the existing human-readable flow. Tests and docs were updated to match the new command shape and examples.

Changes

Structured Output Support

Layer / File(s) Summary
CLI args and dispatch
crates/openshell-cli/src/main.rs
Adds output-format parsing for status, sandbox create, and sandbox get; makes policy_only conflict with output; forwards the selected format into runtime calls; and updates the status fallback plus parsing test.
Gateway status JSON output
crates/openshell-cli/src/run.rs
Updates gateway_status to accept an output format, combines gRPC health and HTTP /healthz checks, builds JSON status payloads, and returns early when structured output is printed. Adds status_to_json and unit tests for status fields.
Sandbox create structured output
crates/openshell-cli/src/run.rs, crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs
Updates sandbox_create to accept an output format, suppress interactive chrome in structured mode, track the latest sandbox state across provisioning updates, and print a single sandbox JSON object when ready. Updates lifecycle integration tests to pass table.
Sandbox get structured output
crates/openshell-cli/src/run.rs, crates/openshell-cli/tests/sandbox_name_fallback_integration.rs
Updates sandbox_get to accept an output format, emits structured sandbox details for non-policy_only calls, and adds sandbox_detail_to_json with policy_source, revision, and policy JSON fields. Adjusts sandbox config serialization, updates sandbox get integration tests, and adds unit coverage for the JSON shape.
Output flag docs
docs/sandboxes/manage-gateways.mdx, docs/sandboxes/manage-sandboxes.mdx
Adds machine-readable output examples and guidance for openshell status, openshell sandbox create, and openshell sandbox get.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through flags and found a cheer,
JSON and YAML now appear.
status, create, and get alike,
Speak in neat shapes with a single strike.
A tidy burrow, crisp and bright,
Output formats done just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main CLI change: adding --output support to sandbox get, status, and sandbox create.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 feat/cli-structured-output

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.

@rhuss rhuss force-pushed the feat/cli-structured-output branch from 16cc09b to 56049ac Compare June 24, 2026 13:18

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🧹 Nitpick comments (1)
crates/openshell-cli/src/main.rs (1)

536-540: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add parse tests for the new --output contracts.

This file adds new CLI surface for status, sandbox create, and sandbox get, but the visible test change at Line 3483 only relaxes the Status variant shape. Please add focused clap tests for default table, -o json/-o yaml, and sandbox get --policy-only conflicting with --output, mirroring the existing list/provider coverage below.

Also applies to: 1343-1365, 3483-3483

🤖 Prompt for 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.

In `@crates/openshell-cli/src/main.rs` around lines 536 - 540, Add focused clap
parse tests for the new output flags on the existing command structs, since the
current test update only loosens the Status variant shape. In the test module
covering Status, SandboxCreate, and SandboxGet, verify the default
OutputFormat::Table for status, the -o json and -o yaml parses, and that
SandboxGet with --policy-only rejects --output as a conflict. Reuse the same
style and helpers already used for the list/provider CLI coverage so the new
contracts are exercised consistently.
🤖 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 `@crates/openshell-cli/src/main.rs`:
- Around line 2095-2103: The gateway status fallback is too broad because
resolve_gateway can fail for reasons other than no active gateway, so
non-configuration errors are being collapsed into not_configured. Update the
gateway_status flow in main to only use the JSON fallback when resolve_gateway
indicates the no-active-gateway case, and let unknown gateway or missing
metadata errors propagate normally through the existing gateway status path.
Keep the fix localized around resolve_gateway, apply_auth, and
run::gateway_status so structured callers still receive real resolution
failures.

In `@crates/openshell-cli/src/run.rs`:
- Around line 3503-3512: The policy serialization flow in run.rs currently
swallows failures by turning any `serialize_sandbox_policy(...)` or YAML-to-JSON
parse error into `serde_json::Value::Null`, which makes an existing policy look
like “no policy configured.” Update the logic around `config.policy`,
`serialize_sandbox_policy`, and the `obj.insert("policy", ...)` path so the JSON
value is constructed before `print_output_single(...)` and any conversion
failure is returned as an error instead of defaulting to null, matching the
behavior of the `--policy-only` path.
- Around line 2302-2304: The structured_output early return in run should not
bypass the --editor and trailing command paths. Update the logic around
print_output_single so that openshell sandbox create with --output json plus
--editor or a trailing command either errors out before this branch or continues
into the existing session/command execution flow. Use the structured_output flag
and the surrounding editor/trailing-command handling in run to locate and fix
the control flow.

In `@docs/sandboxes/manage-sandboxes.mdx`:
- Around line 23-27: The sandbox creation docs currently advertise only JSON
output, but `sandbox create` also supports YAML. Update the
`manage-sandboxes.mdx` usage guidance for `sandbox create` to match the wording
used for `sandbox status` and `sandbox get`, and mention both `--output json`
and `--output yaml` so the CLI surface is discoverable and consistent.

---

Nitpick comments:
In `@crates/openshell-cli/src/main.rs`:
- Around line 536-540: Add focused clap parse tests for the new output flags on
the existing command structs, since the current test update only loosens the
Status variant shape. In the test module covering Status, SandboxCreate, and
SandboxGet, verify the default OutputFormat::Table for status, the -o json and
-o yaml parses, and that SandboxGet with --policy-only rejects --output as a
conflict. Reuse the same style and helpers already used for the list/provider
CLI coverage so the new contracts are exercised consistently.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c2e30fc-362a-4990-9c76-e7d21c170bf9

📥 Commits

Reviewing files that changed from the base of the PR and between 2c54589 and 56049ac.

📒 Files selected for processing (6)
  • crates/openshell-cli/src/main.rs
  • crates/openshell-cli/src/run.rs
  • crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs
  • crates/openshell-cli/tests/sandbox_name_fallback_integration.rs
  • docs/sandboxes/manage-gateways.mdx
  • docs/sandboxes/manage-sandboxes.mdx

Comment thread crates/openshell-cli/src/main.rs
Comment thread crates/openshell-cli/src/run.rs
Comment thread crates/openshell-cli/src/run.rs Outdated
Comment thread docs/sandboxes/manage-sandboxes.mdx Outdated

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 structured --output json|yaml support to key OpenShell CLI flows to enable scripting/automation while preserving existing human-readable output by default.

Changes:

  • Added --output flag handling for openshell status, openshell sandbox get, and openshell sandbox create.
  • Implemented JSON/YAML converters for gateway status and sandbox detail (including policy metadata/content).
  • Updated docs and integration tests to reflect new CLI flag surface and signatures.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/sandboxes/manage-sandboxes.mdx Documents `--output json
docs/sandboxes/manage-gateways.mdx Documents `--output json
crates/openshell-cli/tests/sandbox_name_fallback_integration.rs Updates test helpers/calls to pass the new output parameter for sandbox get.
crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs Updates sandbox create integration tests for the new output parameter.
crates/openshell-cli/src/run.rs Implements structured output for status/sandbox commands and adds JSON conversion helpers.
crates/openshell-cli/src/main.rs Wires new --output flags into clap command definitions and dispatch to run::* functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/openshell-cli/src/run.rs
Comment thread crates/openshell-cli/src/run.rs
Comment thread crates/openshell-cli/src/run.rs Outdated
@rhuss rhuss force-pushed the feat/cli-structured-output branch 5 times, most recently from 9aa0ec4 to b88a214 Compare June 25, 2026 05:38
… create

Add structured output support to three commands that previously only
supported human-readable table output:

- `sandbox get --output json/yaml`: emits sandbox detail including
  policy source, revision, and active policy content via a new
  `sandbox_detail_to_json` converter.

- `status --output json/yaml`: emits gateway connection state via a new
  `status_to_json` converter with conditional fields (auth, version,
  error, http_status) matching the human output.

- `sandbox create --output json/yaml`: emits sandbox metadata after the
  sandbox reaches Ready phase, suppressing spinners and ANSI chrome
  from stdout. Uploads and port forwarding still execute before output.
  Clap rejects `--output` combined with `--editor` or trailing commands.

All three commands reuse the existing `OutputFormat` enum and
`print_output_single` helper. Default output (no --output flag) is
byte-identical to current behavior. Unit tests cover both converters.

Closes NVIDIA#1964

Assisted-By: 🤖 Claude Code
Signed-off-by: Roland Huß <rhuss@redhat.com>
@rhuss rhuss force-pushed the feat/cli-structured-output branch from b88a214 to f067c05 Compare June 25, 2026 05:54
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.

Extend --output json to sandbox list, sandbox create, and status commands

2 participants