@ncukondo/gcal-cli 0.1.4 → 0.1.7
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 +102 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -587718,7 +587718,7 @@ function errorCodeToExitCode(code) {
|
|
|
587718
587718
|
// package.json
|
|
587719
587719
|
var package_default = {
|
|
587720
587720
|
name: "@ncukondo/gcal-cli",
|
|
587721
|
-
version: "0.1.
|
|
587721
|
+
version: "0.1.7",
|
|
587722
587722
|
type: "module",
|
|
587723
587723
|
exports: {
|
|
587724
587724
|
".": "./dist/index.js"
|
|
@@ -591822,6 +591822,43 @@ async function handleUpdate(opts) {
|
|
|
591822
591822
|
withTime.allDay = false;
|
|
591823
591823
|
input.timeZone = timezone;
|
|
591824
591824
|
}
|
|
591825
|
+
if (opts.dryRun) {
|
|
591826
|
+
const changes = {};
|
|
591827
|
+
if (input.title !== undefined)
|
|
591828
|
+
changes.title = input.title;
|
|
591829
|
+
if (input.description !== undefined)
|
|
591830
|
+
changes.description = input.description;
|
|
591831
|
+
if (input.transparency !== undefined)
|
|
591832
|
+
changes.transparency = input.transparency;
|
|
591833
|
+
const withTime = input;
|
|
591834
|
+
if (withTime.start !== undefined)
|
|
591835
|
+
changes.start = withTime.start;
|
|
591836
|
+
if (withTime.end !== undefined)
|
|
591837
|
+
changes.end = withTime.end;
|
|
591838
|
+
if (format3 === "json") {
|
|
591839
|
+
write(formatJsonSuccess({
|
|
591840
|
+
dry_run: true,
|
|
591841
|
+
action: "update",
|
|
591842
|
+
event_id: eventId,
|
|
591843
|
+
changes
|
|
591844
|
+
}));
|
|
591845
|
+
} else {
|
|
591846
|
+
const lines = [`DRY RUN: Would update event "${eventId}":`];
|
|
591847
|
+
if (changes.title !== undefined)
|
|
591848
|
+
lines.push(` title: "${changes.title}"`);
|
|
591849
|
+
if (changes.start !== undefined)
|
|
591850
|
+
lines.push(` start: "${changes.start}"`);
|
|
591851
|
+
if (changes.end !== undefined)
|
|
591852
|
+
lines.push(` end: "${changes.end}"`);
|
|
591853
|
+
if (changes.description !== undefined)
|
|
591854
|
+
lines.push(` description: "${changes.description}"`);
|
|
591855
|
+
if (changes.transparency !== undefined)
|
|
591856
|
+
lines.push(` transparency: ${changes.transparency}`);
|
|
591857
|
+
write(lines.join(`
|
|
591858
|
+
`));
|
|
591859
|
+
}
|
|
591860
|
+
return { exitCode: ExitCode.SUCCESS };
|
|
591861
|
+
}
|
|
591825
591862
|
const updated = await updateEvent(api2, calendarId, calendarName, eventId, input);
|
|
591826
591863
|
if (format3 === "json") {
|
|
591827
591864
|
write(formatJsonSuccess({ event: updated }));
|
|
@@ -591832,12 +591869,14 @@ async function handleUpdate(opts) {
|
|
|
591832
591869
|
}
|
|
591833
591870
|
function createUpdateCommand() {
|
|
591834
591871
|
const cmd = new Command("update").description("Update an existing event").argument("<event-id>", "Event ID to update");
|
|
591872
|
+
cmd.option("-c, --calendar <id>", "Calendar ID");
|
|
591835
591873
|
cmd.option("-t, --title <title>", "New title");
|
|
591836
591874
|
cmd.option("-s, --start <datetime>", "New start datetime");
|
|
591837
591875
|
cmd.option("-e, --end <datetime>", "New end datetime");
|
|
591838
591876
|
cmd.option("-d, --description <text>", "New description");
|
|
591839
591877
|
cmd.option("--busy", "Mark as busy");
|
|
591840
591878
|
cmd.option("--free", "Mark as free");
|
|
591879
|
+
cmd.option("--dry-run", "Preview without executing");
|
|
591841
591880
|
const busyOpt = cmd.options.find((o) => o.long === "--busy");
|
|
591842
591881
|
const freeOpt = cmd.options.find((o) => o.long === "--free");
|
|
591843
591882
|
busyOpt.conflicts(["free"]);
|
|
@@ -591919,11 +591958,24 @@ function createAddCommand() {
|
|
|
591919
591958
|
|
|
591920
591959
|
// src/commands/delete.ts
|
|
591921
591960
|
async function handleDelete(opts) {
|
|
591922
|
-
const { api: api2, eventId, calendarId, format: format3, quiet, write } = opts;
|
|
591961
|
+
const { api: api2, eventId, calendarId, format: format3, quiet, dryRun = false, write } = opts;
|
|
591923
591962
|
if (!eventId) {
|
|
591924
591963
|
write(formatJsonError("INVALID_ARGS", "event-id is required"));
|
|
591925
591964
|
return { exitCode: ExitCode.ARGUMENT };
|
|
591926
591965
|
}
|
|
591966
|
+
if (dryRun) {
|
|
591967
|
+
if (format3 === "json") {
|
|
591968
|
+
write(formatJsonSuccess({
|
|
591969
|
+
dry_run: true,
|
|
591970
|
+
action: "delete",
|
|
591971
|
+
event_id: eventId,
|
|
591972
|
+
calendar_id: calendarId
|
|
591973
|
+
}));
|
|
591974
|
+
} else {
|
|
591975
|
+
write(`DRY RUN: Would delete event "${eventId}" from calendar "${calendarId}"`);
|
|
591976
|
+
}
|
|
591977
|
+
return { exitCode: ExitCode.SUCCESS };
|
|
591978
|
+
}
|
|
591927
591979
|
try {
|
|
591928
591980
|
await deleteEvent(api2, calendarId, eventId);
|
|
591929
591981
|
if (!quiet) {
|
|
@@ -591947,7 +591999,7 @@ async function handleDelete(opts) {
|
|
|
591947
591999
|
}
|
|
591948
592000
|
}
|
|
591949
592001
|
function createDeleteCommand() {
|
|
591950
|
-
return new Command("delete").description("Delete a calendar event").argument("<event-id>", "Event ID").option("-c, --calendar <id>", "Calendar ID to query");
|
|
592002
|
+
return new Command("delete").description("Delete a calendar event").argument("<event-id>", "Event ID").option("-c, --calendar <id>", "Calendar ID to query").option("--dry-run", "Preview without executing");
|
|
591951
592003
|
}
|
|
591952
592004
|
|
|
591953
592005
|
// src/commands/calendars.ts
|
|
@@ -592186,6 +592238,30 @@ function handleError2(error, format3) {
|
|
|
592186
592238
|
process.exit(errorCodeToExitCode(errorCode));
|
|
592187
592239
|
}
|
|
592188
592240
|
|
|
592241
|
+
// src/lib/resolve-calendar.ts
|
|
592242
|
+
async function resolveEventCalendar(api2, eventId, calendars) {
|
|
592243
|
+
const results = await Promise.all(calendars.map(async (cal) => {
|
|
592244
|
+
try {
|
|
592245
|
+
await getEvent(api2, cal.id, cal.name, eventId);
|
|
592246
|
+
return { id: cal.id, name: cal.name };
|
|
592247
|
+
} catch (error) {
|
|
592248
|
+
if (error instanceof ApiError && error.code === "NOT_FOUND") {
|
|
592249
|
+
return null;
|
|
592250
|
+
}
|
|
592251
|
+
throw error;
|
|
592252
|
+
}
|
|
592253
|
+
}));
|
|
592254
|
+
const found = results.filter((r) => r !== null);
|
|
592255
|
+
if (found.length === 0) {
|
|
592256
|
+
throw new ApiError("NOT_FOUND", `Event "${eventId}" not found in any enabled calendar`);
|
|
592257
|
+
}
|
|
592258
|
+
if (found.length > 1) {
|
|
592259
|
+
const calList = found.map((c) => `${c.name} (${c.id})`).join(", ");
|
|
592260
|
+
throw new ApiError("INVALID_ARGS", `Event "${eventId}" found in multiple calendars: ${calList}. Specify -c <calendar-id>.`);
|
|
592261
|
+
}
|
|
592262
|
+
return found[0];
|
|
592263
|
+
}
|
|
592264
|
+
|
|
592189
592265
|
// src/commands/index.ts
|
|
592190
592266
|
function registerCommands(program2) {
|
|
592191
592267
|
const authCmd = createAuthCommand();
|
|
@@ -592319,8 +592395,9 @@ ${url}`);
|
|
|
592319
592395
|
const found = config2.calendars.find((c) => c.id === calendarId);
|
|
592320
592396
|
cal = found ? { id: found.id, name: found.name } : { id: calendarId, name: calendarId };
|
|
592321
592397
|
} else {
|
|
592322
|
-
const
|
|
592323
|
-
|
|
592398
|
+
const calendars = selectCalendars(undefined, config2);
|
|
592399
|
+
const resolved = await resolveEventCalendar(api2, showCmd.args[0], calendars);
|
|
592400
|
+
cal = resolved;
|
|
592324
592401
|
}
|
|
592325
592402
|
const timezone = resolveTimezone(globalOpts.timezone, config2.timezone);
|
|
592326
592403
|
const result = await handleShow({
|
|
@@ -592348,14 +592425,22 @@ ${url}`);
|
|
|
592348
592425
|
const auth = await getAuthenticatedClient(fsAdapter);
|
|
592349
592426
|
const calendarApi = import_googleapis2.google.calendar({ version: "v3", auth });
|
|
592350
592427
|
const api2 = createGoogleCalendarApi(calendarApi);
|
|
592351
|
-
|
|
592352
|
-
|
|
592428
|
+
let resolvedCalendarId;
|
|
592429
|
+
if (deleteOpts.calendar || globalOpts.calendar.length > 0) {
|
|
592430
|
+
const calendars = selectCalendars(deleteOpts.calendar ? [deleteOpts.calendar] : globalOpts.calendar, config2);
|
|
592431
|
+
resolvedCalendarId = calendars[0]?.id ?? "primary";
|
|
592432
|
+
} else {
|
|
592433
|
+
const calendars = selectCalendars(undefined, config2);
|
|
592434
|
+
const resolved = await resolveEventCalendar(api2, eventId, calendars);
|
|
592435
|
+
resolvedCalendarId = resolved.id;
|
|
592436
|
+
}
|
|
592353
592437
|
const result = await handleDelete({
|
|
592354
592438
|
api: api2,
|
|
592355
592439
|
eventId,
|
|
592356
592440
|
calendarId: resolvedCalendarId,
|
|
592357
592441
|
format: globalOpts.format,
|
|
592358
592442
|
quiet: globalOpts.quiet,
|
|
592443
|
+
dryRun: deleteOpts.dryRun ?? false,
|
|
592359
592444
|
write: (msg) => process.stdout.write(msg + `
|
|
592360
592445
|
`)
|
|
592361
592446
|
});
|
|
@@ -592459,8 +592544,16 @@ ${authUrl}`);
|
|
|
592459
592544
|
const calendar = import_googleapis2.google.calendar({ version: "v3", auth: oauth2Client });
|
|
592460
592545
|
const api2 = createGoogleCalendarApi(calendar);
|
|
592461
592546
|
const timezone = resolveTimezone(globalOpts.timezone, config2.timezone);
|
|
592462
|
-
const
|
|
592463
|
-
|
|
592547
|
+
const updateOpsCalendar = updateOpts.calendar;
|
|
592548
|
+
let cal;
|
|
592549
|
+
if (updateOpsCalendar || globalOpts.calendar.length > 0) {
|
|
592550
|
+
const calendars = selectCalendars(updateOpsCalendar ? [updateOpsCalendar] : globalOpts.calendar, config2);
|
|
592551
|
+
cal = calendars[0];
|
|
592552
|
+
} else {
|
|
592553
|
+
const calendars = selectCalendars(undefined, config2);
|
|
592554
|
+
const resolved = await resolveEventCalendar(api2, eventId, calendars);
|
|
592555
|
+
cal = resolved;
|
|
592556
|
+
}
|
|
592464
592557
|
const result = await handleUpdate({
|
|
592465
592558
|
api: api2,
|
|
592466
592559
|
eventId,
|