From 2a08f93e725c310fcd314a9514f92caeac76f9ca Mon Sep 17 00:00:00 2001 From: Amy Yan Date: Fri, 10 Nov 2023 14:36:03 +1100 Subject: [PATCH] wip: changing list formatted commands --- src/identities/CommandAuthenticate.ts | 16 ++++++++++------ src/identities/CommandClaim.ts | 10 ++++++---- src/identities/CommandInvite.ts | 23 +++++++++++++---------- tests/identities/claim.test.ts | 5 ++++- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/identities/CommandAuthenticate.ts b/src/identities/CommandAuthenticate.ts index d9327c1e..5819f06c 100644 --- a/src/identities/CommandAuthenticate.ts +++ b/src/identities/CommandAuthenticate.ts @@ -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(); } diff --git a/src/identities/CommandClaim.ts b/src/identities/CommandClaim.ts index 0c70f0ca..5f2679fc 100644 --- a/src/identities/CommandClaim.ts +++ b/src/identities/CommandClaim.ts @@ -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 { diff --git a/src/identities/CommandInvite.ts b/src/identities/CommandInvite.ts index 0f1d9272..ee00f56a 100644 --- a/src/identities/CommandInvite.ts +++ b/src/identities/CommandInvite.ts @@ -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(); } diff --git a/tests/identities/claim.test.ts b/tests/identities/claim.test.ts index 11c6f9b3..c35c658b 100644 --- a/tests/identities/claim.test.ts +++ b/tests/identities/claim.test.ts @@ -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,