Skip to content

Commit 986f63b

Browse files
committed
wip: changing list formatted commands
1 parent b7669bc commit 986f63b

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/identities/CommandAuthenticate.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,16 @@ class CommandAuthenticate extends CommandPolykey {
8383
this.logger.info(
8484
`Authenticated digital identity provider ${providerId}`,
8585
);
86-
process.stdout.write(
87-
binUtils.outputFormatter({
88-
type: options.format === 'json' ? 'json' : 'list',
89-
data: [message.response.identityId],
90-
}),
91-
);
86+
let output: string | Uint8Array;
87+
if (options.format === 'json') {
88+
output = binUtils.outputFormatter({
89+
type: 'json',
90+
data: { identityId: message.response.identityId },
91+
});
92+
} else {
93+
output = `${message.response.identityId}\n`;
94+
}
95+
process.stdout.write(output);
9296
} else {
9397
never();
9498
}

src/identities/CommandClaim.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ class CommandClaim extends CommandPolykey {
6060
}),
6161
auth,
6262
);
63-
const output = [`Claim Id: ${claimMessage.claimId}`];
63+
const data: { claimId: string; url?: string } = {
64+
claimId: claimMessage.claimId,
65+
};
6466
if (claimMessage.url) {
65-
output.push(`Url: ${claimMessage.url}`);
67+
data.url = claimMessage.url;
6668
}
6769
process.stdout.write(
6870
binUtils.outputFormatter({
69-
type: options.format === 'json' ? 'json' : 'list',
70-
data: output,
71+
type: options.format === 'json' ? 'json' : 'dict',
72+
data,
7173
}),
7274
);
7375
} finally {

src/identities/CommandInvite.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,19 @@ class CommandClaim extends CommandPolykey {
5959
}),
6060
auth,
6161
);
62-
process.stdout.write(
63-
binUtils.outputFormatter({
64-
type: options.format === 'json' ? 'json' : 'list',
65-
data: [
66-
`Successfully sent Gestalt Invite notification to Keynode with ID ${nodesUtils.encodeNodeId(
67-
nodeId,
68-
)}`,
69-
],
70-
}),
71-
);
62+
const message = `Successfully sent Gestalt Invite notification to Keynode with ID ${nodesUtils.encodeNodeId(
63+
nodeId,
64+
)}`;
65+
let output: string | Uint8Array;
66+
if (options.format === 'json') {
67+
output = binUtils.outputFormatter({
68+
type: 'json',
69+
data: { message },
70+
});
71+
} else {
72+
output = `${message}\n`;
73+
}
74+
process.stdout.write(output);
7275
} finally {
7376
if (pkClient! != null) await pkClient.stop();
7477
}

tests/identities/claim.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('claim', () => {
9494
},
9595
);
9696
expect(exitCode).toBe(0);
97-
expect(JSON.parse(stdout)).toEqual(['Claim Id: 0', 'Url: test.com']);
97+
expect(JSON.parse(stdout)).toEqual({ claimId: '0', url: 'test.com' });
9898
// Check for claim on the provider
9999
const claim = await testProvider.getClaim(
100100
testToken.identityId,

0 commit comments

Comments
 (0)