@nycpickleball/cli 1.0.0 → 1.1.1
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/dist/index.js +127 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -280,6 +280,133 @@ function registerLeagueCommands(program2) {
|
|
|
280
280
|
dieWith(e);
|
|
281
281
|
}
|
|
282
282
|
});
|
|
283
|
+
const week = league.command("week").description("Manage league weeks");
|
|
284
|
+
week.command("list <slug>").description("List all weeks for a league").action(async function(slug) {
|
|
285
|
+
const { client } = resolveConfig(rootOpts(this));
|
|
286
|
+
try {
|
|
287
|
+
const res = await client.get(`/api/league/${encodeURIComponent(slug)}/weeks`);
|
|
288
|
+
printTable(
|
|
289
|
+
res.data.map((w) => ({
|
|
290
|
+
week: w.label ?? `W${w.weekNumber}`,
|
|
291
|
+
date: w.scheduledDate.slice(0, 10),
|
|
292
|
+
games: w._count?.games ?? 0
|
|
293
|
+
})),
|
|
294
|
+
[
|
|
295
|
+
{ key: "week", label: "WEEK" },
|
|
296
|
+
{ key: "date", label: "DATE" },
|
|
297
|
+
{ key: "games", label: "GAMES" }
|
|
298
|
+
]
|
|
299
|
+
);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
dieWith(e);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
week.command("add <slug>").description("Add a single week to a league").requiredOption("--number <n>", "Week number (1, 2, 3, ...)", intOpt).requiredOption("--date <date>", "Scheduled date (YYYY-MM-DD)").option("--label <label>", "Optional display label (default: W<number>)").action(async function(slug, options) {
|
|
305
|
+
const { client } = resolveConfig(rootOpts(this));
|
|
306
|
+
try {
|
|
307
|
+
const res = await client.post(
|
|
308
|
+
`/api/league/${encodeURIComponent(slug)}/weeks`,
|
|
309
|
+
{
|
|
310
|
+
weekNumber: options.number,
|
|
311
|
+
scheduledDate: options.date,
|
|
312
|
+
label: options.label
|
|
313
|
+
}
|
|
314
|
+
);
|
|
315
|
+
printJson(res);
|
|
316
|
+
} catch (e) {
|
|
317
|
+
dieWith(e);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
week.command("init <slug>").description(
|
|
321
|
+
"Bulk-create weeks from a comma-separated list of dates (date for W1, W2, ...)"
|
|
322
|
+
).requiredOption(
|
|
323
|
+
"--dates <dates>",
|
|
324
|
+
"Comma-separated YYYY-MM-DD dates in order (W1 first)"
|
|
325
|
+
).action(async function(slug, options) {
|
|
326
|
+
const { client } = resolveConfig(rootOpts(this));
|
|
327
|
+
const dates = options.dates.split(",").map((d) => d.trim()).filter(Boolean);
|
|
328
|
+
const results = [];
|
|
329
|
+
for (let i = 0; i < dates.length; i++) {
|
|
330
|
+
const weekNumber = i + 1;
|
|
331
|
+
try {
|
|
332
|
+
await client.post(
|
|
333
|
+
`/api/league/${encodeURIComponent(slug)}/weeks`,
|
|
334
|
+
{
|
|
335
|
+
weekNumber,
|
|
336
|
+
scheduledDate: dates[i]
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
results.push({
|
|
340
|
+
week: `W${weekNumber}`,
|
|
341
|
+
status: `created (${dates[i]})`
|
|
342
|
+
});
|
|
343
|
+
} catch (e) {
|
|
344
|
+
results.push({
|
|
345
|
+
week: `W${weekNumber}`,
|
|
346
|
+
status: `error: ${e instanceof Error ? e.message : String(e)}`
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
printTable(results, [
|
|
351
|
+
{ key: "week", label: "WEEK" },
|
|
352
|
+
{ key: "status", label: "STATUS" }
|
|
353
|
+
]);
|
|
354
|
+
});
|
|
355
|
+
week.command("delete <slug> <weekNumber>").description("Delete a week (and its games)").action(async function(slug, weekNumber) {
|
|
356
|
+
const { client } = resolveConfig(rootOpts(this));
|
|
357
|
+
try {
|
|
358
|
+
const res = await client.delete(
|
|
359
|
+
`/api/league/${encodeURIComponent(slug)}/weeks/${encodeURIComponent(weekNumber)}`
|
|
360
|
+
);
|
|
361
|
+
printJson(res);
|
|
362
|
+
} catch (e) {
|
|
363
|
+
dieWith(e);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
const game = league.command("game").description("Record game scores");
|
|
367
|
+
game.command("record <slug> <weekNumber>").description("Record a single game's score").requiredOption("--court <name>", "Court name (e.g. 'Court 1')").requiredOption("--game <n>", "Game number (1-5)", intOpt).option("--team1 <score>", "Team 1 score", intOpt).option("--team2 <score>", "Team 2 score", intOpt).action(async function(slug, weekNumber, options) {
|
|
368
|
+
const { client } = resolveConfig(rootOpts(this));
|
|
369
|
+
try {
|
|
370
|
+
const res = await client.post(
|
|
371
|
+
`/api/league/${encodeURIComponent(slug)}/weeks/${encodeURIComponent(weekNumber)}/games`,
|
|
372
|
+
{
|
|
373
|
+
courtName: options.court,
|
|
374
|
+
gameNumber: options.game,
|
|
375
|
+
team1Score: options.team1 ?? null,
|
|
376
|
+
team2Score: options.team2 ?? null
|
|
377
|
+
}
|
|
378
|
+
);
|
|
379
|
+
printJson(res);
|
|
380
|
+
} catch (e) {
|
|
381
|
+
dieWith(e);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
game.command("import <slug> <weekNumber>").description("Bulk-record game scores from a JSON file").requiredOption(
|
|
385
|
+
"--file <path>",
|
|
386
|
+
"Path to JSON with shape { games: [{ courtName, gameNumber, team1Score, team2Score }] }"
|
|
387
|
+
).action(async function(slug, weekNumber, options) {
|
|
388
|
+
const { client } = resolveConfig(rootOpts(this));
|
|
389
|
+
let parsed;
|
|
390
|
+
try {
|
|
391
|
+
const text = readFileSync(options.file, "utf8");
|
|
392
|
+
parsed = JSON.parse(text);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
dieWith(
|
|
395
|
+
new Error(
|
|
396
|
+
`Could not read or parse ${options.file}: ${e.message}`
|
|
397
|
+
)
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
const res = await client.post(
|
|
402
|
+
`/api/league/${encodeURIComponent(slug)}/weeks/${encodeURIComponent(weekNumber)}/games`,
|
|
403
|
+
parsed
|
|
404
|
+
);
|
|
405
|
+
printJson(res);
|
|
406
|
+
} catch (e) {
|
|
407
|
+
dieWith(e);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
283
410
|
}
|
|
284
411
|
|
|
285
412
|
// src/index.ts
|