@metaphorli/pingcode-cli 0.3.2 → 0.3.3
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/README.md +72 -9
- package/package.json +2 -2
- package/scripts/commands/auth.js +221 -24
- package/scripts/commands/comment.js +556 -0
- package/scripts/commands/context.js +15 -111
- package/scripts/commands/idea.js +1121 -0
- package/scripts/commands/product.js +236 -0
- package/scripts/commands/shared.js +107 -2
- package/scripts/commands/workitem.js +24 -179
- package/scripts/core.js +17 -0
- package/scripts/pingcode.js +3 -0
- package/skills/pingcode/SKILL.md +23 -8
- package/skills/pingcode/references/auth.md +55 -1
- package/skills/pingcode/references/comment.md +52 -0
- package/skills/pingcode/references/ctx.md +3 -3
- package/skills/pingcode/references/idea.md +70 -0
- package/skills/pingcode/references/product.md +48 -0
- package/skills/pingcode/references/workitem.md +2 -4
|
@@ -204,71 +204,11 @@ function printHelp(subcommand) {
|
|
|
204
204
|
|
|
205
205
|
// ── Parser ─────────────────────────────────────────────────────────
|
|
206
206
|
|
|
207
|
-
const BOOLEAN_FLAGS = new Set([
|
|
208
|
-
'--no-workspace-cache', '--no-token-cache',
|
|
209
|
-
'--dry-run', '--refresh',
|
|
210
|
-
]);
|
|
211
|
-
|
|
212
|
-
const STRING_FLAGS = {
|
|
213
|
-
'--base-url': 'base_url',
|
|
214
|
-
'--client-id': 'client_id',
|
|
215
|
-
'--client-secret': 'client_secret',
|
|
216
|
-
'--token': 'token',
|
|
217
|
-
'--workspace-cache': 'workspace_cache',
|
|
218
|
-
'--grant-type': 'grant_type',
|
|
219
|
-
};
|
|
220
|
-
|
|
221
207
|
function parseContextArgs(tokens) {
|
|
222
|
-
const opts =
|
|
223
|
-
base_url: process.env.PINGCODE_BASE_URL || core.DEFAULT_BASE_URL,
|
|
224
|
-
client_id: process.env.PINGCODE_CLIENT_ID || null,
|
|
225
|
-
client_secret: process.env.PINGCODE_CLIENT_SECRET || null,
|
|
226
|
-
token: process.env.PINGCODE_ACCESS_TOKEN || null,
|
|
227
|
-
workspace_cache: process.env.PINGCODE_WORKSPACE_CACHE || core.DEFAULT_WORKSPACE_CACHE,
|
|
228
|
-
no_workspace_cache: false,
|
|
229
|
-
no_token_cache: false,
|
|
230
|
-
dry_run: false,
|
|
231
|
-
refresh: false,
|
|
232
|
-
grant_type: 'auto',
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const positionals = [];
|
|
236
|
-
let helpRequested = false;
|
|
208
|
+
const { opts, remaining } = shared.parseGlobalOptions(tokens, ['--refresh']);
|
|
237
209
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (arg === '--help' || arg === '-h') {
|
|
241
|
-
helpRequested = true;
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (BOOLEAN_FLAGS.has(arg)) {
|
|
245
|
-
const key = arg.replace(/^--/, '').replace(/-/g, '_');
|
|
246
|
-
opts[key] = true;
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
if (arg.startsWith('--')) {
|
|
250
|
-
const eqIndex = arg.indexOf('=');
|
|
251
|
-
let flag, value;
|
|
252
|
-
if (eqIndex !== -1) {
|
|
253
|
-
flag = arg.slice(0, eqIndex);
|
|
254
|
-
value = arg.slice(eqIndex + 1);
|
|
255
|
-
} else {
|
|
256
|
-
flag = arg;
|
|
257
|
-
if (i + 1 < tokens.length) {
|
|
258
|
-
value = tokens[i + 1];
|
|
259
|
-
i += 1;
|
|
260
|
-
} else {
|
|
261
|
-
throw new core.PingCodeError(`Flag ${flag} requires a value`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (!(flag in STRING_FLAGS)) {
|
|
265
|
-
throw new core.PingCodeError(`Unknown option: ${flag}`);
|
|
266
|
-
}
|
|
267
|
-
opts[STRING_FLAGS[flag]] = value;
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
positionals.push(arg);
|
|
271
|
-
}
|
|
210
|
+
const helpRequested = remaining.includes('--help') || remaining.includes('-h');
|
|
211
|
+
const positionals = remaining.filter(a => !a.startsWith('-'));
|
|
272
212
|
|
|
273
213
|
return {
|
|
274
214
|
subcommand: positionals[0] || null,
|
|
@@ -280,21 +220,7 @@ function parseContextArgs(tokens) {
|
|
|
280
220
|
|
|
281
221
|
// ── Client ─────────────────────────────────────────────────────────
|
|
282
222
|
|
|
283
|
-
|
|
284
|
-
const tokenCache = opts.no_token_cache
|
|
285
|
-
? null
|
|
286
|
-
: (process.env.PINGCODE_TOKEN_CACHE || core.DEFAULT_TOKEN_CACHE);
|
|
287
|
-
const workspaceCache = opts.no_workspace_cache ? null : opts.workspace_cache;
|
|
288
|
-
return new core.PingCodeClient({
|
|
289
|
-
base_url: opts.base_url,
|
|
290
|
-
client_id: opts.client_id,
|
|
291
|
-
client_secret: opts.client_secret,
|
|
292
|
-
token: opts.token,
|
|
293
|
-
token_cache: tokenCache,
|
|
294
|
-
workspace_cache: workspaceCache,
|
|
295
|
-
grant_type: opts.grant_type,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
223
|
+
const createClient = shared.clientFromOpts;
|
|
298
224
|
|
|
299
225
|
// ── Dictionary counts (copied from config.js; not exported from core) ──
|
|
300
226
|
|
|
@@ -482,41 +408,20 @@ async function handleList(opts) {
|
|
|
482
408
|
const client = createClient(opts);
|
|
483
409
|
const cache = client.workspaceCache;
|
|
484
410
|
|
|
485
|
-
|
|
486
|
-
console.log('Preferences:');
|
|
487
|
-
const prefs = cache.preferences || {};
|
|
488
|
-
const prefKeys = Object.keys(prefs).sort();
|
|
489
|
-
if (prefKeys.length === 0) {
|
|
490
|
-
console.log(' (none)');
|
|
491
|
-
} else {
|
|
492
|
-
for (const key of prefKeys) {
|
|
493
|
-
console.log(` ${key}: ${prefs[key]}`);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
411
|
+
const preferences = cache.preferences || {};
|
|
496
412
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const countKeys = Object.keys(counts).sort();
|
|
502
|
-
for (const key of countKeys) {
|
|
503
|
-
const label = key.replace(/_/g, ' ');
|
|
504
|
-
console.log(` ${label}: ${counts[key]} items`);
|
|
505
|
-
}
|
|
413
|
+
core.printJson({
|
|
414
|
+
preferences,
|
|
415
|
+
dictionaries: countDictionaryEntries(cache),
|
|
416
|
+
});
|
|
506
417
|
}
|
|
507
418
|
|
|
508
|
-
// ── Subcommand name mapping ────────────────────────────────────────
|
|
509
|
-
|
|
510
|
-
const SUBCOMMAND_ALIASES = {
|
|
511
|
-
'set-current-user': 'set-current-user',
|
|
512
|
-
'set-current-project': 'set-current-project',
|
|
513
|
-
'set-current-sprint': 'set-current-sprint',
|
|
514
|
-
init: 'init',
|
|
515
|
-
list: 'list',
|
|
516
|
-
};
|
|
517
|
-
|
|
518
419
|
// ── Run ────────────────────────────────────────────────────────────
|
|
519
420
|
|
|
421
|
+
const VALID_SUBCOMMANDS = new Set([
|
|
422
|
+
'init', 'set-current-user', 'set-current-project', 'set-current-sprint', 'list',
|
|
423
|
+
]);
|
|
424
|
+
|
|
520
425
|
async function run(argv) {
|
|
521
426
|
const tokens = argv || [];
|
|
522
427
|
|
|
@@ -536,10 +441,9 @@ async function run(argv) {
|
|
|
536
441
|
|
|
537
442
|
const subcommand = parsed.subcommand;
|
|
538
443
|
|
|
539
|
-
if (!subcommand || !(subcommand
|
|
444
|
+
if (!subcommand || !VALID_SUBCOMMANDS.has(subcommand)) {
|
|
540
445
|
throw new core.PingCodeError(
|
|
541
|
-
`Unknown context subcommand: ${subcommand || '(none)'}.
|
|
542
|
-
'Valid subcommands: init, set-current-user, set-current-project, set-current-sprint, list.',
|
|
446
|
+
`Unknown context subcommand: ${subcommand || '(none)'}. Use context --help for usage.`
|
|
543
447
|
);
|
|
544
448
|
}
|
|
545
449
|
|