Skip to content

cli: add table output to all get commands add --json flag #3156

Open
juan-malbeclabs wants to merge 8 commits intomainfrom
jo/get_json
Open

cli: add table output to all get commands add --json flag #3156
juan-malbeclabs wants to merge 8 commits intomainfrom
jo/get_json

Conversation

@juan-malbeclabs
Copy link
Contributor

@juan-malbeclabs juan-malbeclabs commented Mar 3, 2026

Summary of Changes

  • Refactored all get commands in smartcontract/cli/ (13 files) to use a typed display struct with #[derive(Tabled, Serialize)] and render output as a formatted table by default
  • Added --json flag to every get command for machine-readable JSON output, enabling scripting and integration use cases
  • multicastgroup get JSON output now serializes a combined object with info, allowlist, and users arrays
  • Updated all CLI unit tests from fragile assert_eq! on exact formatted strings to assert!(output_str.contains(...)), and added JSON output test cases
  • Updated E2E tests that previously parsed text output from get commands to use --json and json.Unmarshal for reliable structured parsing

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 13 +857 / -414 +443
Tests 6 +62 / -49 +13
Docs 1 +1 / -0 +1

Predominantly CLI core logic refactoring; E2E test updates are a small but important follow-on to consume the new structured output.

Key files (click to expand)

Testing Verification

  • All 213 CLI unit tests pass (cargo test -p doublezero_cli)
  • cargo clippy -- -D warnings passes clean
  • make rust-fmt applied
  • E2E builds verified clean with both e2e and qa build tags (go build -tags e2e ./e2e/...)

@juan-malbeclabs juan-malbeclabs changed the title cli: add --json flag and table output to all get commands cli: add table output to all get commands add --json flag Mar 3, 2026
@juan-malbeclabs juan-malbeclabs enabled auto-merge (squash) March 3, 2026 13:52
dz_prefixes: device.dz_prefixes.to_string(),
metrics_publisher: device.metrics_publisher_pk.to_string(),
mgmt_vrf: device.mgmt_vrf,
interfaces: format!("{:?}", device.interfaces),
Copy link
Contributor

Choose a reason for hiding this comment

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

We can choose to leave it like this but the way it works rn is the JSON output will contain a debug string like "[]" rather than an actual JSON array.

"interfaces": "[]" instead of "interfaces": []

#[derive(Tabled)]
#[derive(Tabled, Serialize)]
pub struct ResourceDisplay {
#[tabled(rename = "Allocated Resources")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove this?

The table column header will change from "Allocated Resources" to "resource".

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a preference

assert!(output_str.contains("connections: 3"));
assert!(output_str.contains("status: connected"));
assert!(output_str.contains(&format!("owner: {}", accesspass.owner)));
assert!(output_str.contains(&format!("{accesspass_pubkey}")));
Copy link
Contributor

Choose a reason for hiding this comment

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

Not super critical but tests could pass for wrong reasons and miss regressions. Could we:

  • For JSON mode tests: deserialize and check specific field values
  • For table mode tests: at minimum check contains("connections") paired with the value

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.

3 participants