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 Feb 26, 2024
1 parent 5855f03 commit 2a08f93
Show file tree
Hide file tree
Showing 4 changed files with 33 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 @@ -86,12 +86,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
5 changes: 4 additions & 1 deletion tests/identities/claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ 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 2a08f93

Please sign in to comment.