Skip to content

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

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

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

Conversation

@rhuss

@rhuss rhuss commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Add --output json/yaml to sandbox get, status, and sandbox create so automation and MCP tool wrappers can consume structured data instead of parsing ANSI-colored human output.

Related Issue

Closes #1964

Changes

  • sandbox get --output json/yaml: New sandbox_detail_to_json converter enriches the existing sandbox_to_json with policy source, revision, and active policy content from GetSandboxConfigResponse. Uses sandbox_policy_to_json_value for direct proto-to-JSON conversion.
  • status --output json/yaml: New status_to_json converter emits gateway, server, status, and conditional fields (auth, version, error, http_status). Refactored gateway_status to build data before output routing.
  • sandbox create --output json/yaml: Emits sandbox metadata after Ready phase. Human chrome (header, spinner) suppressed from stdout; progress message on stderr. Uploads and port forwarding still execute before output. Clap rejects --output combined with --editor or trailing commands.
  • No-gateway path: status --output json with no configured gateway emits {"status": "not_configured"} instead of human text.
  • All three commands reuse the existing OutputFormat enum and print_output_single helper.
  • Default output (no --output flag) is byte-identical to current behavior (verified by diffing raw ANSI output).
  • Docs updated for sandbox get, sandbox create, and status in manage-sandboxes.mdx and manage-gateways.mdx.

Testing

  • cargo clippy clean, cargo fmt clean
  • 188 unit tests pass (cargo test --lib)
  • 5 new unit tests for sandbox_detail_to_json and status_to_json converters
  • Integration test call sites updated for new function signatures
  • Smoke-tested against live local gateway: sandbox get --output json, status --output json/yaml, default output byte-identical regression check
  • Deep review (5 agents + CodeRabbit + Copilot): all Critical/Important findings fixed

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

… 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 requested review from a team, derekwaynecarr, maxamillion and mrunalp as code owners June 24, 2026 16:32
@copy-pr-bot

copy-pr-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

All contributors have signed the DCO ✍️ ✅
Posted by the DCO Assistant Lite bot.

@rhuss

rhuss commented Jun 24, 2026

Copy link
Copy Markdown
Author

I have read the DCO document and I hereby sign the DCO.

@rhuss

rhuss commented Jun 24, 2026

Copy link
Copy Markdown
Author

recheck

@johntmyers johntmyers self-assigned this Jun 24, 2026
println!(" {} {}", "HTTP:".dimmed(), hs);
}
if let Some(ref e) = error {
println!(" {} {}", "gRPC error:".dimmed(), e);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This isn't byte-for-byte identical I don't think. If http_health_check() returns None then we used to show Error: ... but now it should hit this arm and will show gRPC error:

Comment on lines +3505 to +3508
let policy_json = config.policy.as_ref().map_or_else(
|| serde_json::Value::Null,
|p| openshell_policy::sandbox_policy_to_json_value(p).unwrap_or(serde_json::Value::Null),
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a reason this does not propagate the conversion error? Other parts do, do we really want to return a null policy if conversion fails?

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