@ncukondo/gcal-cli 0.2.1 → 0.2.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/dist/index.js +156 -45
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,25 +6,43 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
function __accessProp(key) {
|
|
10
|
+
return this[key];
|
|
11
|
+
}
|
|
12
|
+
var __toESMCache_node;
|
|
13
|
+
var __toESMCache_esm;
|
|
9
14
|
var __toESM = (mod, isNodeMode, target) => {
|
|
15
|
+
var canCache = mod != null && typeof mod === "object";
|
|
16
|
+
if (canCache) {
|
|
17
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
18
|
+
var cached = cache.get(mod);
|
|
19
|
+
if (cached)
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
10
22
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
11
23
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
12
24
|
for (let key of __getOwnPropNames(mod))
|
|
13
25
|
if (!__hasOwnProp.call(to, key))
|
|
14
26
|
__defProp(to, key, {
|
|
15
|
-
get: (
|
|
27
|
+
get: __accessProp.bind(mod, key),
|
|
16
28
|
enumerable: true
|
|
17
29
|
});
|
|
30
|
+
if (canCache)
|
|
31
|
+
cache.set(mod, to);
|
|
18
32
|
return to;
|
|
19
33
|
};
|
|
20
34
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
35
|
+
var __returnValue = (v) => v;
|
|
36
|
+
function __exportSetter(name, newValue) {
|
|
37
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
38
|
+
}
|
|
21
39
|
var __export = (target, all) => {
|
|
22
40
|
for (var name in all)
|
|
23
41
|
__defProp(target, name, {
|
|
24
42
|
get: all[name],
|
|
25
43
|
enumerable: true,
|
|
26
44
|
configurable: true,
|
|
27
|
-
set: (
|
|
45
|
+
set: __exportSetter.bind(all, name)
|
|
28
46
|
});
|
|
29
47
|
};
|
|
30
48
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
@@ -587718,7 +587736,7 @@ function errorCodeToExitCode(code) {
|
|
|
587718
587736
|
// package.json
|
|
587719
587737
|
var package_default = {
|
|
587720
587738
|
name: "@ncukondo/gcal-cli",
|
|
587721
|
-
version: "0.2.
|
|
587739
|
+
version: "0.2.3",
|
|
587722
587740
|
type: "module",
|
|
587723
587741
|
exports: {
|
|
587724
587742
|
".": "./dist/index.js"
|
|
@@ -587989,7 +588007,8 @@ async function getAuthenticatedClient(fs, fetchFn = globalThis.fetch) {
|
|
|
587989
588007
|
}
|
|
587990
588008
|
var OAUTH_SCOPES = [
|
|
587991
588009
|
"https://www.googleapis.com/auth/calendar.readonly",
|
|
587992
|
-
"https://www.googleapis.com/auth/calendar.events"
|
|
588010
|
+
"https://www.googleapis.com/auth/calendar.events",
|
|
588011
|
+
"email"
|
|
587993
588012
|
];
|
|
587994
588013
|
async function startOAuthFlow(credentials, fs, fetchFn = globalThis.fetch) {
|
|
587995
588014
|
return new Promise((resolve) => {
|
|
@@ -588145,15 +588164,20 @@ async function handleAuthStatus(opts) {
|
|
|
588145
588164
|
}
|
|
588146
588165
|
const email2 = await fetchUserEmail(currentTokens.access_token, fetchFn);
|
|
588147
588166
|
const expiresAt = new Date(currentTokens.expiry_date);
|
|
588167
|
+
const reAuthHint = "Run `gcal auth --logout` then `gcal auth` to re-authenticate with updated permissions.";
|
|
588148
588168
|
if (format === "json") {
|
|
588149
588169
|
write(formatJsonSuccess({
|
|
588150
588170
|
authenticated: true,
|
|
588151
588171
|
email: email2,
|
|
588152
|
-
expires_at: expiresAt.toISOString()
|
|
588172
|
+
expires_at: expiresAt.toISOString(),
|
|
588173
|
+
...email2 == null ? { hint: reAuthHint } : {}
|
|
588153
588174
|
}));
|
|
588154
588175
|
} else {
|
|
588155
588176
|
write(`Authenticated as: ${email2 ?? "unknown"}`);
|
|
588156
588177
|
write(`Token expires: ${expiresAt.toISOString()}`);
|
|
588178
|
+
if (email2 == null) {
|
|
588179
|
+
write(reAuthHint);
|
|
588180
|
+
}
|
|
588157
588181
|
}
|
|
588158
588182
|
return { exitCode: ExitCode.SUCCESS };
|
|
588159
588183
|
}
|
|
@@ -588400,7 +588424,6 @@ function applyFilters(events, options) {
|
|
|
588400
588424
|
const afterTransparency = filterByTransparency(events, options.transparency);
|
|
588401
588425
|
return filterByStatus(afterTransparency, options);
|
|
588402
588426
|
}
|
|
588403
|
-
|
|
588404
588427
|
// node_modules/date-fns/locale/en-US/_lib/formatDistance.mjs
|
|
588405
588428
|
var formatDistanceLocale = {
|
|
588406
588429
|
lessThanXSeconds: {
|
|
@@ -590573,7 +590596,7 @@ function parseDateTimeInZone(dateStr, timezone) {
|
|
|
590573
590596
|
// src/commands/search.ts
|
|
590574
590597
|
var DEFAULT_SEARCH_DAYS = 30;
|
|
590575
590598
|
async function handleSearch(opts) {
|
|
590576
|
-
const { api: api2, query, format:
|
|
590599
|
+
const { api: api2, query, format: format4, calendars, timezone, write } = opts;
|
|
590577
590600
|
const writeErr = opts.writeErr ?? (() => {});
|
|
590578
590601
|
const now = new Date;
|
|
590579
590602
|
const days = opts.days ?? DEFAULT_SEARCH_DAYS;
|
|
@@ -590619,7 +590642,7 @@ async function handleSearch(opts) {
|
|
|
590619
590642
|
if (opts.includeTentative !== undefined)
|
|
590620
590643
|
filterOpts.includeTentative = opts.includeTentative;
|
|
590621
590644
|
const filtered = applyFilters(allEvents, filterOpts);
|
|
590622
|
-
if (
|
|
590645
|
+
if (format4 === "json") {
|
|
590623
590646
|
write(formatJsonSuccess({
|
|
590624
590647
|
query,
|
|
590625
590648
|
events: filtered,
|
|
@@ -590650,10 +590673,10 @@ function createSearchCommand() {
|
|
|
590650
590673
|
|
|
590651
590674
|
// src/commands/show.ts
|
|
590652
590675
|
async function handleShow(opts) {
|
|
590653
|
-
const { api: api2, eventId, calendarId, calendarName, format:
|
|
590676
|
+
const { api: api2, eventId, calendarId, calendarName, format: format4, timezone, write } = opts;
|
|
590654
590677
|
try {
|
|
590655
590678
|
const event = await getEvent(api2, calendarId, calendarName, eventId, timezone);
|
|
590656
|
-
if (
|
|
590679
|
+
if (format4 === "json") {
|
|
590657
590680
|
write(formatJsonSuccess({ event }));
|
|
590658
590681
|
} else {
|
|
590659
590682
|
write(formatEventDetailText(event));
|
|
@@ -590661,7 +590684,7 @@ async function handleShow(opts) {
|
|
|
590661
590684
|
return { exitCode: ExitCode.SUCCESS };
|
|
590662
590685
|
} catch (error) {
|
|
590663
590686
|
if (error instanceof ApiError) {
|
|
590664
|
-
if (
|
|
590687
|
+
if (format4 === "json") {
|
|
590665
590688
|
write(formatJsonError(error.code, error.message));
|
|
590666
590689
|
} else {
|
|
590667
590690
|
write(`Error: ${error.message}`);
|
|
@@ -591727,19 +591750,19 @@ function resolveDateRange(input, timezone, now = () => new Date) {
|
|
|
591727
591750
|
}
|
|
591728
591751
|
if (input.from) {
|
|
591729
591752
|
const fromDate = parseDateTimeInZone(input.from, timezone);
|
|
591730
|
-
const
|
|
591753
|
+
const toDate4 = input.to ? addDays(parseDateTimeInZone(input.to, timezone), 1) : addDays(fromDate, 7);
|
|
591731
591754
|
return {
|
|
591732
591755
|
timeMin: formatDateTimeInZone(fromDate, timezone),
|
|
591733
|
-
timeMax: formatDateTimeInZone(
|
|
591756
|
+
timeMax: formatDateTimeInZone(toDate4, timezone)
|
|
591734
591757
|
};
|
|
591735
591758
|
}
|
|
591736
591759
|
if (input.to) {
|
|
591737
591760
|
const todayStr2 = todayInZone(now(), timezone);
|
|
591738
591761
|
const fromDate = parseDateTimeInZone(todayStr2, timezone);
|
|
591739
|
-
const
|
|
591762
|
+
const toDate4 = addDays(parseDateTimeInZone(input.to, timezone), 1);
|
|
591740
591763
|
return {
|
|
591741
591764
|
timeMin: formatDateTimeInZone(fromDate, timezone),
|
|
591742
|
-
timeMax: formatDateTimeInZone(
|
|
591765
|
+
timeMax: formatDateTimeInZone(toDate4, timezone),
|
|
591743
591766
|
warning: "--from not specified, defaulting to today"
|
|
591744
591767
|
};
|
|
591745
591768
|
}
|
|
@@ -591852,7 +591875,7 @@ function createListCommand() {
|
|
|
591852
591875
|
|
|
591853
591876
|
// src/commands/update.ts
|
|
591854
591877
|
async function handleUpdate(opts) {
|
|
591855
|
-
const { api: api2, eventId, calendarId, calendarName, format:
|
|
591878
|
+
const { api: api2, eventId, calendarId, calendarName, format: format4, timezone, write } = opts;
|
|
591856
591879
|
const hasUpdate = opts.title !== undefined || opts.start !== undefined || opts.end !== undefined || opts.description !== undefined || opts.busy !== undefined || opts.free !== undefined;
|
|
591857
591880
|
if (!hasUpdate) {
|
|
591858
591881
|
throw new ApiError("INVALID_ARGS", "at least one update option must be provided");
|
|
@@ -591896,7 +591919,7 @@ async function handleUpdate(opts) {
|
|
|
591896
591919
|
changes.start = withTime.start;
|
|
591897
591920
|
if (withTime.end !== undefined)
|
|
591898
591921
|
changes.end = withTime.end;
|
|
591899
|
-
if (
|
|
591922
|
+
if (format4 === "json") {
|
|
591900
591923
|
write(formatJsonSuccess({
|
|
591901
591924
|
dry_run: true,
|
|
591902
591925
|
action: "update",
|
|
@@ -591921,7 +591944,7 @@ async function handleUpdate(opts) {
|
|
|
591921
591944
|
return { exitCode: ExitCode.SUCCESS };
|
|
591922
591945
|
}
|
|
591923
591946
|
const updated = await updateEvent(api2, calendarId, calendarName, eventId, input);
|
|
591924
|
-
if (
|
|
591947
|
+
if (format4 === "json") {
|
|
591925
591948
|
write(formatJsonSuccess({ event: updated }));
|
|
591926
591949
|
} else {
|
|
591927
591950
|
write(formatEventDetailText(updated));
|
|
@@ -591945,6 +591968,38 @@ function createUpdateCommand() {
|
|
|
591945
591968
|
return cmd;
|
|
591946
591969
|
}
|
|
591947
591970
|
|
|
591971
|
+
// src/lib/date-utils.ts
|
|
591972
|
+
var DATE_ONLY_RE2 = /^\d{4}-\d{2}-\d{2}$/;
|
|
591973
|
+
function isDateOnly(input) {
|
|
591974
|
+
if (!DATE_ONLY_RE2.test(input))
|
|
591975
|
+
return false;
|
|
591976
|
+
const [y, m, d] = input.split("-").map(Number);
|
|
591977
|
+
const date3 = new Date(Date.UTC(y, m - 1, d));
|
|
591978
|
+
return date3.getUTCFullYear() === y && date3.getUTCMonth() === m - 1 && date3.getUTCDate() === d;
|
|
591979
|
+
}
|
|
591980
|
+
function addDaysToDateString(dateStr, days) {
|
|
591981
|
+
const [y, m, d] = dateStr.split("-").map(Number);
|
|
591982
|
+
const date3 = new Date(Date.UTC(y, m - 1, d + days));
|
|
591983
|
+
return date3.toISOString().slice(0, 10);
|
|
591984
|
+
}
|
|
591985
|
+
|
|
591986
|
+
// src/lib/duration.ts
|
|
591987
|
+
var DURATION_RE = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?$/;
|
|
591988
|
+
function parseDuration(input) {
|
|
591989
|
+
const match2 = DURATION_RE.exec(input);
|
|
591990
|
+
if (!match2 || input === "") {
|
|
591991
|
+
throw new Error(`Invalid duration: "${input}". Use formats like 30m, 1h, 2d, 1h30m.`);
|
|
591992
|
+
}
|
|
591993
|
+
const days = Number(match2[1] || 0);
|
|
591994
|
+
const hours = Number(match2[2] || 0);
|
|
591995
|
+
const minutes = Number(match2[3] || 0);
|
|
591996
|
+
const ms = ((days * 24 + hours) * 60 + minutes) * 60 * 1000;
|
|
591997
|
+
if (ms === 0) {
|
|
591998
|
+
throw new Error("Duration must be greater than zero.");
|
|
591999
|
+
}
|
|
592000
|
+
return ms;
|
|
592001
|
+
}
|
|
592002
|
+
|
|
591948
592003
|
// src/commands/add.ts
|
|
591949
592004
|
async function handleAdd(options, deps) {
|
|
591950
592005
|
if (!options.title) {
|
|
@@ -591955,10 +592010,18 @@ async function handleAdd(options, deps) {
|
|
|
591955
592010
|
deps.write(formatJsonError("INVALID_ARGS", "--start is required"));
|
|
591956
592011
|
return { exitCode: ExitCode.ARGUMENT };
|
|
591957
592012
|
}
|
|
591958
|
-
if (
|
|
591959
|
-
deps.write(formatJsonError("INVALID_ARGS", "--end
|
|
592013
|
+
if (options.end && options.duration) {
|
|
592014
|
+
deps.write(formatJsonError("INVALID_ARGS", "--end and --duration cannot be used together"));
|
|
591960
592015
|
return { exitCode: ExitCode.ARGUMENT };
|
|
591961
592016
|
}
|
|
592017
|
+
const allDay = isDateOnly(options.start);
|
|
592018
|
+
if (options.end) {
|
|
592019
|
+
const endIsDateOnly = isDateOnly(options.end);
|
|
592020
|
+
if (allDay !== endIsDateOnly) {
|
|
592021
|
+
deps.write(formatJsonError("INVALID_ARGS", "--start and --end must be the same type (both date-only or both datetime)"));
|
|
592022
|
+
return { exitCode: ExitCode.ARGUMENT };
|
|
592023
|
+
}
|
|
592024
|
+
}
|
|
591962
592025
|
const config2 = deps.loadConfig();
|
|
591963
592026
|
const timezone = resolveTimezone(options.timezone, config2.timezone);
|
|
591964
592027
|
const calendars = selectCalendars(options.calendar ? [options.calendar] : undefined, config2);
|
|
@@ -591970,20 +592033,54 @@ async function handleAdd(options, deps) {
|
|
|
591970
592033
|
transparency = "transparent";
|
|
591971
592034
|
let start;
|
|
591972
592035
|
let end;
|
|
591973
|
-
if (
|
|
591974
|
-
start = options.start
|
|
591975
|
-
|
|
592036
|
+
if (allDay) {
|
|
592037
|
+
start = options.start;
|
|
592038
|
+
if (options.end) {
|
|
592039
|
+
end = addDaysToDateString(options.end, 1);
|
|
592040
|
+
} else if (options.duration) {
|
|
592041
|
+
let durationMs;
|
|
592042
|
+
try {
|
|
592043
|
+
durationMs = parseDuration(options.duration);
|
|
592044
|
+
} catch {
|
|
592045
|
+
deps.write(formatJsonError("INVALID_ARGS", `Invalid duration: "${options.duration}". Use formats like 30m, 1h, 2d, 1h30m.`));
|
|
592046
|
+
return { exitCode: ExitCode.ARGUMENT };
|
|
592047
|
+
}
|
|
592048
|
+
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
592049
|
+
if (durationMs % MS_PER_DAY !== 0) {
|
|
592050
|
+
deps.write(formatJsonError("INVALID_ARGS", "All-day events require day-unit duration (e.g. 1d, 2d). Sub-day durations like hours or minutes are not allowed."));
|
|
592051
|
+
return { exitCode: ExitCode.ARGUMENT };
|
|
592052
|
+
}
|
|
592053
|
+
const days = durationMs / MS_PER_DAY;
|
|
592054
|
+
end = addDaysToDateString(options.start, days);
|
|
592055
|
+
} else {
|
|
592056
|
+
end = addDaysToDateString(options.start, 1);
|
|
592057
|
+
}
|
|
591976
592058
|
} else {
|
|
591977
592059
|
const startDate = parseDateTimeInZone(options.start, timezone);
|
|
591978
|
-
const endDate = parseDateTimeInZone(options.end, timezone);
|
|
591979
592060
|
start = formatDateTimeInZone(startDate, timezone);
|
|
591980
|
-
|
|
592061
|
+
if (options.end) {
|
|
592062
|
+
const endDate = parseDateTimeInZone(options.end, timezone);
|
|
592063
|
+
end = formatDateTimeInZone(endDate, timezone);
|
|
592064
|
+
} else if (options.duration) {
|
|
592065
|
+
let durationMs;
|
|
592066
|
+
try {
|
|
592067
|
+
durationMs = parseDuration(options.duration);
|
|
592068
|
+
} catch {
|
|
592069
|
+
deps.write(formatJsonError("INVALID_ARGS", `Invalid duration: "${options.duration}". Use formats like 30m, 1h, 2d, 1h30m.`));
|
|
592070
|
+
return { exitCode: ExitCode.ARGUMENT };
|
|
592071
|
+
}
|
|
592072
|
+
const endDate = new Date(startDate.getTime() + durationMs);
|
|
592073
|
+
end = formatDateTimeInZone(endDate, timezone);
|
|
592074
|
+
} else {
|
|
592075
|
+
const endDate = new Date(startDate.getTime() + 60 * 60 * 1000);
|
|
592076
|
+
end = formatDateTimeInZone(endDate, timezone);
|
|
592077
|
+
}
|
|
591981
592078
|
}
|
|
591982
592079
|
const input = {
|
|
591983
592080
|
title: options.title,
|
|
591984
592081
|
start,
|
|
591985
592082
|
end,
|
|
591986
|
-
allDay
|
|
592083
|
+
allDay,
|
|
591987
592084
|
timeZone: timezone,
|
|
591988
592085
|
transparency
|
|
591989
592086
|
};
|
|
@@ -592003,29 +592100,43 @@ ${detail}`);
|
|
|
592003
592100
|
}
|
|
592004
592101
|
function createAddCommand() {
|
|
592005
592102
|
const cmd = new Command("add").description("Create a new event");
|
|
592006
|
-
cmd.
|
|
592007
|
-
cmd.
|
|
592008
|
-
cmd.option("-e, --end <datetime>", "End datetime (
|
|
592009
|
-
cmd.option("--
|
|
592103
|
+
cmd.requiredOption("-t, --title <title>", "Event title");
|
|
592104
|
+
cmd.requiredOption("-s, --start <datetime>", "Start date or datetime. Date-only (YYYY-MM-DD) creates all-day event. Datetime (YYYY-MM-DDTHH:MM) creates timed event.");
|
|
592105
|
+
cmd.option("-e, --end <datetime>", "End date or datetime. Optional. Default: same day (all-day) or +1h (timed). All-day end is inclusive.");
|
|
592106
|
+
cmd.option("--duration <duration>", "Duration instead of --end (e.g. 30m, 1h, 2d, 1h30m). Mutually exclusive with --end.");
|
|
592010
592107
|
cmd.option("-d, --description <text>", "Event description");
|
|
592011
592108
|
cmd.option("--busy", "Mark as busy (default)");
|
|
592012
592109
|
cmd.option("--free", "Mark as free (transparent)");
|
|
592110
|
+
const endOpt = cmd.options.find((o) => o.long === "--end");
|
|
592111
|
+
const durationOpt = cmd.options.find((o) => o.long === "--duration");
|
|
592112
|
+
endOpt.conflicts(["duration"]);
|
|
592113
|
+
durationOpt.conflicts(["end"]);
|
|
592013
592114
|
const busyOpt = cmd.options.find((o) => o.long === "--busy");
|
|
592014
592115
|
const freeOpt = cmd.options.find((o) => o.long === "--free");
|
|
592015
592116
|
busyOpt.conflicts(["free"]);
|
|
592016
592117
|
freeOpt.conflicts(["busy"]);
|
|
592118
|
+
cmd.addHelpText("after", `
|
|
592119
|
+
Examples:
|
|
592120
|
+
gcal add -t "Holiday" -s "2026-01-24" # All-day, 1 day
|
|
592121
|
+
gcal add -t "Vacation" -s "2026-01-24" -e "2026-01-26" # All-day, 3 days (inclusive)
|
|
592122
|
+
gcal add -t "Camp" -s "2026-01-24" --duration 2d # All-day, 2 days
|
|
592123
|
+
gcal add -t "Meeting" -s "2026-01-24T10:00" # Timed, 1h default
|
|
592124
|
+
gcal add -t "Meeting" -s "2026-01-24T10:00" -e "2026-01-24T11:30" # Timed, explicit end
|
|
592125
|
+
gcal add -t "Standup" -s "2026-01-24T10:00" --duration 30m # Timed, 30 min
|
|
592126
|
+
gcal add -t "Focus" -s "2026-01-24T09:00" --duration 2h --free # Timed, free
|
|
592127
|
+
`);
|
|
592017
592128
|
return cmd;
|
|
592018
592129
|
}
|
|
592019
592130
|
|
|
592020
592131
|
// src/commands/delete.ts
|
|
592021
592132
|
async function handleDelete(opts) {
|
|
592022
|
-
const { api: api2, eventId, calendarId, format:
|
|
592133
|
+
const { api: api2, eventId, calendarId, format: format4, quiet, dryRun = false, write } = opts;
|
|
592023
592134
|
if (!eventId) {
|
|
592024
592135
|
write(formatJsonError("INVALID_ARGS", "event-id is required"));
|
|
592025
592136
|
return { exitCode: ExitCode.ARGUMENT };
|
|
592026
592137
|
}
|
|
592027
592138
|
if (dryRun) {
|
|
592028
|
-
if (
|
|
592139
|
+
if (format4 === "json") {
|
|
592029
592140
|
write(formatJsonSuccess({
|
|
592030
592141
|
dry_run: true,
|
|
592031
592142
|
action: "delete",
|
|
@@ -592040,7 +592151,7 @@ async function handleDelete(opts) {
|
|
|
592040
592151
|
try {
|
|
592041
592152
|
await deleteEvent(api2, calendarId, eventId);
|
|
592042
592153
|
if (!quiet) {
|
|
592043
|
-
if (
|
|
592154
|
+
if (format4 === "json") {
|
|
592044
592155
|
write(formatJsonSuccess({ deleted_id: eventId, message: "Event deleted" }));
|
|
592045
592156
|
} else {
|
|
592046
592157
|
write("Event deleted");
|
|
@@ -592049,7 +592160,7 @@ async function handleDelete(opts) {
|
|
|
592049
592160
|
return { exitCode: ExitCode.SUCCESS };
|
|
592050
592161
|
} catch (error) {
|
|
592051
592162
|
if (error instanceof ApiError) {
|
|
592052
|
-
if (
|
|
592163
|
+
if (format4 === "json") {
|
|
592053
592164
|
write(formatJsonError(error.code, error.message));
|
|
592054
592165
|
} else {
|
|
592055
592166
|
write(`Error: ${error.message}`);
|
|
@@ -592075,13 +592186,13 @@ function mergeCalendarsWithConfig(apiCalendars, configCalendars) {
|
|
|
592075
592186
|
});
|
|
592076
592187
|
}
|
|
592077
592188
|
async function handleCalendars(opts) {
|
|
592078
|
-
const { api: api2, format:
|
|
592189
|
+
const { api: api2, format: format4, quiet, write, configCalendars } = opts;
|
|
592079
592190
|
let apiCalendars;
|
|
592080
592191
|
try {
|
|
592081
592192
|
apiCalendars = await listCalendars(api2);
|
|
592082
592193
|
} catch (error) {
|
|
592083
592194
|
if (error instanceof ApiError) {
|
|
592084
|
-
if (
|
|
592195
|
+
if (format4 === "json") {
|
|
592085
592196
|
write(formatJsonError(error.code, error.message));
|
|
592086
592197
|
} else {
|
|
592087
592198
|
write(error.message);
|
|
@@ -592096,7 +592207,7 @@ async function handleCalendars(opts) {
|
|
|
592096
592207
|
`));
|
|
592097
592208
|
return { exitCode: ExitCode.SUCCESS };
|
|
592098
592209
|
}
|
|
592099
|
-
if (
|
|
592210
|
+
if (format4 === "json") {
|
|
592100
592211
|
write(formatJsonSuccess({ calendars }));
|
|
592101
592212
|
} else {
|
|
592102
592213
|
write(formatCalendarListText(calendars));
|
|
@@ -592113,12 +592224,12 @@ function resolveTimezone2(cliTimezone) {
|
|
|
592113
592224
|
return cliTimezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
592114
592225
|
}
|
|
592115
592226
|
async function handleInit(opts) {
|
|
592116
|
-
const { fs, format:
|
|
592227
|
+
const { fs, format: format4, quiet, write, force, all, local, requestAuth } = opts;
|
|
592117
592228
|
const configPath = local ? `${process.cwd()}/gcal-cli.toml` : getDefaultConfigPath();
|
|
592118
592229
|
if (!force && fs.existsSync(configPath)) {
|
|
592119
592230
|
const msg = `Config file already exists: ${configPath}
|
|
592120
592231
|
Use --force to overwrite.`;
|
|
592121
|
-
if (
|
|
592232
|
+
if (format4 === "json") {
|
|
592122
592233
|
write(formatJsonError("CONFIG_ERROR", msg));
|
|
592123
592234
|
} else {
|
|
592124
592235
|
write(msg);
|
|
@@ -592134,7 +592245,7 @@ Use --force to overwrite.`;
|
|
|
592134
592245
|
calendars = await opts.listCalendars();
|
|
592135
592246
|
} else if (isAuthRequiredError(error)) {
|
|
592136
592247
|
const msg = "Not authenticated. Run `gcal auth` to authenticate.";
|
|
592137
|
-
if (
|
|
592248
|
+
if (format4 === "json") {
|
|
592138
592249
|
write(formatJsonError("AUTH_REQUIRED", msg));
|
|
592139
592250
|
} else {
|
|
592140
592251
|
write(msg);
|
|
@@ -592146,7 +592257,7 @@ Use --force to overwrite.`;
|
|
|
592146
592257
|
}
|
|
592147
592258
|
if (calendars.length === 0) {
|
|
592148
592259
|
const msg = "No calendars found in Google Calendar.";
|
|
592149
|
-
if (
|
|
592260
|
+
if (format4 === "json") {
|
|
592150
592261
|
write(formatJsonError("API_ERROR", msg));
|
|
592151
592262
|
} else {
|
|
592152
592263
|
write(msg);
|
|
@@ -592168,7 +592279,7 @@ Use --force to overwrite.`;
|
|
|
592168
592279
|
write(configPath);
|
|
592169
592280
|
return { exitCode: ExitCode.SUCCESS };
|
|
592170
592281
|
}
|
|
592171
|
-
if (
|
|
592282
|
+
if (format4 === "json") {
|
|
592172
592283
|
write(formatJsonSuccess({
|
|
592173
592284
|
path: configPath,
|
|
592174
592285
|
timezone,
|
|
@@ -592287,10 +592398,10 @@ function getErrorCode2(error) {
|
|
|
592287
592398
|
}
|
|
592288
592399
|
return "API_ERROR";
|
|
592289
592400
|
}
|
|
592290
|
-
function handleError2(error,
|
|
592401
|
+
function handleError2(error, format4) {
|
|
592291
592402
|
const errorCode = getErrorCode2(error);
|
|
592292
592403
|
const message2 = error instanceof Error ? error.message : String(error);
|
|
592293
|
-
if (
|
|
592404
|
+
if (format4 === "json") {
|
|
592294
592405
|
process.stderr.write(formatJsonError(errorCode, message2));
|
|
592295
592406
|
} else {
|
|
592296
592407
|
process.stderr.write(`Error: ${message2}
|
|
@@ -592545,7 +592656,7 @@ ${url}`);
|
|
|
592545
592656
|
title: addOpts.title,
|
|
592546
592657
|
start: addOpts.start,
|
|
592547
592658
|
end: addOpts.end,
|
|
592548
|
-
|
|
592659
|
+
duration: addOpts.duration,
|
|
592549
592660
|
description: addOpts.description,
|
|
592550
592661
|
busy: addOpts.busy,
|
|
592551
592662
|
free: addOpts.free,
|