Skip to content

Commit

Permalink
feat: CommandList now uses dict and list formats
Browse files Browse the repository at this point in the history
  • Loading branch information
amydevs committed Mar 4, 2024
1 parent 6faa6a2 commit 6ff85b3
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/identities/CommandList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = [];
const stream = await pkClient.rpcClient.methods.gestaltsGestaltList({
Expand Down Expand Up @@ -82,32 +81,41 @@ 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}`,
);
process.stdout.write(
binUtils.outputFormatter({
type: 'list',
data: nodeIds.concat(identities),
}) + '\n',
);
count++;
}
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
}),
);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down

0 comments on commit 6ff85b3

Please sign in to comment.