diff --git a/src/identities/CommandList.ts b/src/identities/CommandList.ts index 7d7c7e43..7d7407ea 100644 --- a/src/identities/CommandList.ts +++ b/src/identities/CommandList.ts @@ -42,7 +42,6 @@ class CommandList extends CommandPolykey { }, logger: this.logger.getChild(PolykeyClient.name), }); - let output: any; const gestalts = await binUtils.retryAuthentication(async (auth) => { const gestalts: Array = []; const stream = await pkClient.rpcClient.methods.gestaltsGestaltList({ @@ -82,32 +81,39 @@ class CommandList extends CommandPolykey { } return gestalts; }, auth); - output = gestalts; - if (options.format !== 'json') { + if (options.format === 'json') { + process.stdout.write( + binUtils.outputFormatter({ + type: options.format === 'json' ? 'json' : 'list', + data: gestalts, + }), + ); + } else { // Convert to a human-readable list. - output = []; let count = 1; for (const gestalt of gestalts) { - output.push(`gestalt ${count}`); - output.push(`permissions: ${gestalt.permissions ?? 'None'}`); + process.stdout.write( + binUtils.outputFormatter({ + type: 'dict', + data: { + gestalt: count, + permissions: gestalt.permissions, + }, + }), + ); // Listing nodes - for (const node of gestalt.nodes) { - output.push(`${node.nodeId}`); - } + const nodeIds = gestalt.nodes.map((node) => node.nodeId); // Listing identities - for (const identity of gestalt.identities) { - output.push(`${identity.providerId}:${identity.identityId}`); - } - output.push(''); + const identities = gestalt.identities.map( + (identity) => `${identity.providerId}:${identity.identityId}`, + ); + binUtils.outputFormatter({ + type: 'list', + data: nodeIds.concat(identities), + }); count++; } } - process.stdout.write( - binUtils.outputFormatter({ - type: options.format === 'json' ? 'json' : 'list', - data: output, - }), - ); } finally { if (pkClient! != null) await pkClient.stop(); }