cli: add table output to all get commands add --json flag #3156
Open
juan-malbeclabs wants to merge 8 commits intomainfrom
Open
cli: add table output to all get commands add --json flag #3156juan-malbeclabs wants to merge 8 commits intomainfrom
get commands add --json flag #3156juan-malbeclabs wants to merge 8 commits intomainfrom
Conversation
--json flag and table output to all get commandsget commands add --json flag
smartcontract/cli/src/device/get.rs
Outdated
| dz_prefixes: device.dz_prefixes.to_string(), | ||
| metrics_publisher: device.metrics_publisher_pk.to_string(), | ||
| mgmt_vrf: device.mgmt_vrf, | ||
| interfaces: format!("{:?}", device.interfaces), |
Contributor
There was a problem hiding this comment.
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")] |
Contributor
There was a problem hiding this comment.
Should we remove this?
The table column header will change from "Allocated Resources" to "resource".
Contributor
There was a problem hiding this comment.
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}"))); |
Contributor
There was a problem hiding this comment.
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
martinsander00
approved these changes
Mar 3, 2026
elitegreg
approved these changes
Mar 3, 2026
17dde1b to
5132acf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
getcommands insmartcontract/cli/(13 files) to use a typed display struct with#[derive(Tabled, Serialize)]and render output as a formatted table by default--jsonflag to everygetcommand for machine-readable JSON output, enabling scripting and integration use casesmulticastgroup getJSON output now serializes a combined object withinfo,allowlist, andusersarraysassert_eq!on exact formatted strings toassert!(output_str.contains(...)), and added JSON output test casesgetcommands to use--jsonandjson.Unmarshalfor reliable structured parsingDiff Breakdown
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)
smartcontract/cli/src/multicastgroup/get.rs— most complex refactor: splits intoMulticastGroupDisplay,MulticastAllowlistDisplay,MulticastUserDisplay; JSON output wraps all three in a combined objectsmartcontract/cli/src/user/get.rs— addsUserDisplaystruct covering multi-lookup fields (tenant, device, multicast groups, accesspass); skips default pubkey for unset tenantsmartcontract/cli/src/device/get.rs— addsDeviceDisplaywith all device fields includinginterfacesserialized via{:?}smartcontract/cli/src/link/get.rs— addsLinkDisplay; delay/jitter/delay_override formatted asXmsstringssmartcontract/cli/src/accesspass/get.rs— addsAccessPassDisplay;typefield renamedaccesspass_typewith#[tabled(rename)]and#[serde(rename)]smartcontract/cli/src/contributor/get.rs— addsContributorDisplaystruct withjsonflage2e/internal/devnet/devnet.go—GetDevicePubkeyOnchainswitched from text-line scanning to--json+json.Unmarshale2e/contributor_auth_test.go— replaced manual line-splitting loops for pubkey extraction with--jsonparsingTesting Verification
cargo test -p doublezero_cli)cargo clippy -- -D warningspasses cleanmake rust-fmtappliede2eandqabuild tags (go build -tags e2e ./e2e/...)