@gpdoc/cli 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/gpdoc.js +25 -1
- package/package.json +1 -1
package/bin/gpdoc.js
CHANGED
|
@@ -105,6 +105,29 @@ function printResult(result, json) {
|
|
|
105
105
|
else process.stdout.write(`${Object.entries(result).map(([key, value]) => `${key}: ${value}`).join('\n')}\n`);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
// @spec CLI-029
|
|
109
|
+
function renderWhoami(status) {
|
|
110
|
+
const { identity, pending, ...fields } = status;
|
|
111
|
+
const lines = Object.entries(fields).map(([key, value]) => `${key}: ${value}`);
|
|
112
|
+
if (identity && typeof identity === 'object') {
|
|
113
|
+
const orderedClaims = ['email', 'name', 'nickname', 'sub'];
|
|
114
|
+
const claimEntries = [
|
|
115
|
+
...orderedClaims.filter((key) => typeof identity[key] === 'string').map((key) => [key, identity[key]]),
|
|
116
|
+
...Object.entries(identity).filter(([key, value]) => !orderedClaims.includes(key) && typeof value === 'string'),
|
|
117
|
+
];
|
|
118
|
+
if (claimEntries.length) {
|
|
119
|
+
lines.push('identity:');
|
|
120
|
+
lines.push(...claimEntries.map(([key, value]) => ` ${key}: ${value}`));
|
|
121
|
+
} else {
|
|
122
|
+
lines.push('identity: unavailable');
|
|
123
|
+
}
|
|
124
|
+
} else if (identity === null) {
|
|
125
|
+
lines.push('identity: null');
|
|
126
|
+
}
|
|
127
|
+
if (pending) lines.push('pending: true');
|
|
128
|
+
return lines.join('\n');
|
|
129
|
+
}
|
|
130
|
+
|
|
108
131
|
function printError(error, json) {
|
|
109
132
|
const result = { error: error.code || 'ERROR', message: error.message || String(error) };
|
|
110
133
|
if (json) process.stderr.write(`${JSON.stringify(result)}\n`);
|
|
@@ -218,7 +241,8 @@ export async function run(argv, runtime = {}) {
|
|
|
218
241
|
return;
|
|
219
242
|
}
|
|
220
243
|
if (parsed.command === 'whoami') {
|
|
221
|
-
|
|
244
|
+
const status = await auth.status();
|
|
245
|
+
printResult(parsed.options.json ? status : renderWhoami(status), parsed.options.json);
|
|
222
246
|
return;
|
|
223
247
|
}
|
|
224
248
|
|