From 3ba7ca79fab3d11187ab59eba43f59b3f112b2c0 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 20 Nov 2024 12:49:23 -0500 Subject: [PATCH] chore(agoric-cli): Condense `agoric wallet show` output (#10519) ## Description Render empty purses/usedInvitations/offers on one line rather than three: ```diff { "purses": [ ["board0074",0] ], - "usedInvitations": [ - - ], - "offers": [ - - ] + "usedInvitations": [], + "offers": [] } ``` ### Security Considerations n/a ### Scaling Considerations n/a ### Documentation Considerations n/a ### Testing Considerations n/a ### Upgrade Considerations We don't guarantee stability of the output AFAIK, and I'm not aware of anything that depends upon it. --- packages/agoric-cli/src/lib/format.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/agoric-cli/src/lib/format.js b/packages/agoric-cli/src/lib/format.js index e5e1a277d3c..d5e9d8836bb 100644 --- a/packages/agoric-cli/src/lib/format.js +++ b/packages/agoric-cli/src/lib/format.js @@ -100,14 +100,15 @@ export const purseBalanceTuples = (purses, assets) => { */ export const fmtRecordOfLines = record => { const { stringify } = JSON; + /** @type {Array<[string, string[]]>} */ const groups = Object.entries(record).map(([key, items]) => [ key, items.map(item => ` ${stringify(item)}`), ]); - const lineEntries = groups.map( - // @ts-expect-error ??? - ([key, lines]) => ` ${stringify(key)}: [\n${lines.join(',\n')}\n ]`, - ); + const lineEntries = groups.map(([key, lines]) => { + const linesStr = lines.length === 0 ? `[]` : `[\n${lines.join(',\n')}\n ]`; + return ` ${stringify(key)}: ${linesStr}`; + }); return `{\n${lineEntries.join(',\n')}\n}`; };