Skip to content

Commit

Permalink
wip: changing list formatted commands
Browse files Browse the repository at this point in the history
  • Loading branch information
amydevs committed Nov 15, 2023
1 parent 6114036 commit ff9345e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
16 changes: 10 additions & 6 deletions src/identities/CommandAuthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ class CommandAuthenticate extends CommandPolykey {
this.logger.info(
`Authenticated digital identity provider ${providerId}`,
);
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [message.response.identityId],
}),
);
let output: string | Uint8Array;
if (options.format === 'json') {
output = binUtils.outputFormatter({
type: 'json',
data: { identityId: message.response.identityId },
});
} else {
output = `${message.response.identityId}\n`;
}
process.stdout.write(output);
} else {
never();
}
Expand Down
10 changes: 6 additions & 4 deletions src/identities/CommandClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ class CommandClaim extends CommandPolykey {
}),
auth,
);
const output = [`Claim Id: ${claimMessage.claimId}`];
const data: { claimId: string; url?: string } = {
claimId: claimMessage.claimId,
};
if (claimMessage.url) {
output.push(`Url: ${claimMessage.url}`);
data.url = claimMessage.url;
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
type: options.format === 'json' ? 'json' : 'dict',
data,
}),
);
} finally {
Expand Down
23 changes: 13 additions & 10 deletions src/identities/CommandInvite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ class CommandClaim extends CommandPolykey {
}),
auth,
);
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [
`Successfully sent Gestalt Invite notification to Keynode with ID ${nodesUtils.encodeNodeId(
nodeId,
)}`,
],
}),
);
const message = `Successfully sent Gestalt Invite notification to Keynode with ID ${nodesUtils.encodeNodeId(
nodeId,
)}`;
let output: string | Uint8Array;
if (options.format === 'json') {
output = binUtils.outputFormatter({
type: 'json',
data: { message },
});
} else {
output = `${message}\n`;
}
process.stdout.write(output);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/identities/claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('claim', () => {
},
);
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toEqual(['Claim Id: 0', 'Url: test.com']);
expect(JSON.parse(stdout)).toEqual({ claimId: '0', url: 'test.com' });
// Check for claim on the provider
const claim = await testProvider.getClaim(
testToken.identityId,
Expand Down

0 comments on commit ff9345e

Please sign in to comment.