@apet97/clockify-cli-115 6.0.0 → 7.0.0
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 +167 -21
- package/dist/client.js +30 -7
- package/dist/commands/api.js +44 -76
- package/dist/commands/approvals.js +2 -5
- package/dist/commands/auth.js +229 -0
- package/dist/commands/batch.js +226 -0
- package/dist/commands/clients.js +11 -65
- package/dist/commands/doctor.js +65 -66
- package/dist/commands/expenses.js +21 -24
- package/dist/commands/helpers.js +46 -2
- package/dist/commands/leaf-command.js +7 -0
- package/dist/commands/manifest.js +63 -0
- package/dist/commands/operations.js +271 -0
- package/dist/commands/projects.js +10 -23
- package/dist/commands/reports.js +22 -7
- package/dist/commands/shared-report-body.js +3 -81
- package/dist/commands/sharedReports.js +1 -21
- package/dist/commands/skill.js +85 -0
- package/dist/commands/status.js +18 -12
- package/dist/commands/stop.js +3 -12
- package/dist/commands/tags.js +5 -7
- package/dist/commands/tasks.js +19 -120
- package/dist/commands/users.js +4 -14
- package/dist/commands/webhook-delivery.js +331 -0
- package/dist/commands/webhooks.js +31 -97
- package/dist/completions.js +2 -1
- package/dist/config.js +166 -63
- package/dist/credentials.js +164 -0
- package/dist/failure.js +4 -9
- package/dist/flags.js +14 -4
- package/dist/generated/version.js +1 -1
- package/dist/index.js +38 -14
- package/dist/interrupts.js +28 -0
- package/dist/output.js +137 -48
- package/dist/receipt.js +2 -10
- package/dist/stdin.js +6 -0
- package/dist/stdout.js +38 -0
- package/dist/write-outcome.js +1 -1
- package/package.json +5 -3
- package/plugin/.claude-plugin/plugin.json +16 -0
- package/plugin/skills/clockify-cli/SKILL.md +88 -0
- package/plugin/skills/clockify-mcp/SKILL.md +48 -0
- package/plugin/skills/clockify-sdk/SKILL.md +85 -0
- package/dist/error-codes.js +0 -300
package/dist/commands/doctor.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requireHeaderValue, requireRoute } from "../client.js";
|
|
2
2
|
import { globalFlags, resolveFlags } from "../flags.js";
|
|
3
|
-
import { printObject, printRecords } from "../output.js";
|
|
3
|
+
import { fixedColumns, printObject, printRecords } from "../output.js";
|
|
4
4
|
import { rootProgram } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
6
|
const DEFAULT_CLOCKIFY_BASE_URL = "https://api.clockify.me/api/v1";
|
|
7
|
+
const RECEIPT_KEYS = ["ok", "readiness", "checks", "next"];
|
|
8
|
+
const CHECK_KEYS = ["check", "ok", "status", "source", "value", "recovery"];
|
|
9
|
+
const INSTALL_NODE = "Install Node.js 22.13 or newer";
|
|
7
10
|
export const registerDoctorCommand = (program, services) => {
|
|
8
11
|
leafCommand(program, "doctor", "read")
|
|
9
12
|
.description("Check local CLI configuration without contacting Clockify.")
|
|
@@ -13,10 +16,12 @@ export const registerDoctorCommand = (program, services) => {
|
|
|
13
16
|
.action(async function () {
|
|
14
17
|
const root = rootProgram(this);
|
|
15
18
|
const flags = globalFlags(root);
|
|
16
|
-
const
|
|
19
|
+
const { mode } = resolveFlags(root);
|
|
20
|
+
const asReceipt = mode === "json" || mode === "ndjson";
|
|
21
|
+
const output = fixedColumns(asReceipt ? RECEIPT_KEYS : CHECK_KEYS, resolveFlags(root));
|
|
17
22
|
const config = services.loadConfig(flags);
|
|
18
|
-
const receipt = await buildDoctorReceipt(config, flags, process.env);
|
|
19
|
-
if (
|
|
23
|
+
const receipt = await buildDoctorReceipt(config, flags, process.env, services);
|
|
24
|
+
if (asReceipt) {
|
|
20
25
|
printObject(receipt, output);
|
|
21
26
|
return;
|
|
22
27
|
}
|
|
@@ -28,32 +33,61 @@ export const registerDoctorCommand = (program, services) => {
|
|
|
28
33
|
value: c.value ?? "",
|
|
29
34
|
recovery: c.recovery ?? "",
|
|
30
35
|
})), output);
|
|
31
|
-
|
|
36
|
+
if (mode === "csv")
|
|
37
|
+
return;
|
|
38
|
+
const { fields: _fields, ...summary } = output;
|
|
39
|
+
printObject({ ok: receipt.ok, readiness: receipt.readiness }, summary);
|
|
32
40
|
for (const step of receipt.next)
|
|
33
41
|
console.log(step);
|
|
34
42
|
});
|
|
35
43
|
};
|
|
36
|
-
const offline = () => { throw new Error("Doctor is offline"); };
|
|
37
44
|
async function acceptsBaseUrl(baseUrl) {
|
|
38
45
|
try {
|
|
39
|
-
await
|
|
46
|
+
await requireRoute({ baseUrl });
|
|
40
47
|
return true;
|
|
41
48
|
}
|
|
42
49
|
catch {
|
|
43
50
|
return false;
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
|
-
|
|
53
|
+
const messageOf = (err) => (err instanceof Error ? err.message : String(err));
|
|
54
|
+
function presentKey(key, source, value) {
|
|
55
|
+
try {
|
|
56
|
+
requireHeaderValue(key);
|
|
57
|
+
return { ok: true, status: "present", source, value };
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return { ok: false, status: "present", source, value, recovery: messageOf(err) };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function checkApiKey(config, services) {
|
|
64
|
+
if (isPresent(config.apiKey))
|
|
65
|
+
return presentKey(config.apiKey, "env", "configured (redacted)");
|
|
66
|
+
if (config.profile === undefined) {
|
|
67
|
+
return { ok: false, status: "missing", recovery: "Set CLOCKIFY_API_KEY in the process environment, or run `clk115 auth login`." };
|
|
68
|
+
}
|
|
69
|
+
const { storedApiKey, systemCredentialStore } = await import("../credentials.js");
|
|
70
|
+
const login = `Run \`clk115 auth login --profile ${config.profile}\`.`;
|
|
71
|
+
try {
|
|
72
|
+
const key = await storedApiKey(config, services.credentials ?? systemCredentialStore);
|
|
73
|
+
if (key !== undefined)
|
|
74
|
+
return presentKey(key, "profile", `profile ${config.profile} (redacted)`);
|
|
75
|
+
return { ok: false, status: "missing", source: "profile", recovery: login };
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return { ok: false, status: "missing", source: "profile", recovery: `${messageOf(err)} ${login}` };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function buildDoctorReceipt(config, flags, env, services) {
|
|
47
82
|
const [nodeMajor = 0, nodeMinor = 0] = process.versions.node
|
|
48
83
|
.split(".")
|
|
49
84
|
.map((part) => Number.parseInt(part, 10) || 0);
|
|
50
85
|
const nodeOk = nodeMajor > 22 || (nodeMajor === 22 && nodeMinor >= 13);
|
|
51
|
-
const apiKeySource = sourceFor("apiKey", config, flags, env);
|
|
52
86
|
const workspaceSource = sourceFor("workspaceId", config, flags, env);
|
|
53
87
|
const baseUrlSource = sourceFor("baseUrl", config, flags, env) ?? "default";
|
|
54
88
|
const regionSource = sourceFor("region", config, flags, env) ?? "default";
|
|
55
89
|
const subdomainSource = sourceFor("subdomain", config, flags, env) ?? "default";
|
|
56
|
-
const
|
|
90
|
+
const apiKey = await checkApiKey(config, services);
|
|
57
91
|
const workspaceOk = isPresent(config.workspaceId);
|
|
58
92
|
const baseUrl = config.baseUrl === undefined
|
|
59
93
|
? DEFAULT_CLOCKIFY_BASE_URL
|
|
@@ -65,11 +99,11 @@ async function buildDoctorReceipt(config, flags, env) {
|
|
|
65
99
|
let baseUrlOk = true;
|
|
66
100
|
if (config.region !== undefined || config.subdomain !== undefined || config.baseUrl !== undefined) {
|
|
67
101
|
try {
|
|
68
|
-
await
|
|
102
|
+
await requireRoute(config);
|
|
69
103
|
}
|
|
70
104
|
catch (err) {
|
|
71
105
|
if (config.region !== undefined || config.subdomain !== undefined) {
|
|
72
|
-
routingError =
|
|
106
|
+
routingError = messageOf(err);
|
|
73
107
|
if (config.subdomain)
|
|
74
108
|
routingError = routingError.replace(JSON.stringify(config.subdomain), '"<redacted>"');
|
|
75
109
|
}
|
|
@@ -80,7 +114,7 @@ async function buildDoctorReceipt(config, flags, env) {
|
|
|
80
114
|
const subdomainOk = regionOk;
|
|
81
115
|
const readinessState = !nodeOk
|
|
82
116
|
? { kind: "runtime_unsupported", ok: false }
|
|
83
|
-
:
|
|
117
|
+
: apiKey.ok && workspaceOk && regionOk && baseUrlOk
|
|
84
118
|
? { kind: "ready_for_status", ok: true }
|
|
85
119
|
: { kind: "configuration_incomplete", ok: false };
|
|
86
120
|
return {
|
|
@@ -91,17 +125,9 @@ async function buildDoctorReceipt(config, flags, env) {
|
|
|
91
125
|
ok: nodeOk,
|
|
92
126
|
status: nodeOk ? "supported" : "unsupported",
|
|
93
127
|
value: process.versions.node,
|
|
94
|
-
...(nodeOk ? {} : { recovery:
|
|
95
|
-
},
|
|
96
|
-
apiKey: {
|
|
97
|
-
ok: apiKeyOk,
|
|
98
|
-
status: apiKeyOk ? "present" : "missing",
|
|
99
|
-
...(apiKeySource !== undefined ? { source: apiKeySource } : {}),
|
|
100
|
-
...(apiKeyOk ? { value: "configured (redacted)" } : {}),
|
|
101
|
-
...(apiKeyOk
|
|
102
|
-
? {}
|
|
103
|
-
: { recovery: "Set CLOCKIFY_API_KEY in the process environment." }),
|
|
128
|
+
...(nodeOk ? {} : { recovery: `${INSTALL_NODE} before using @apet97/clockify-cli-115.` }),
|
|
104
129
|
},
|
|
130
|
+
apiKey,
|
|
105
131
|
workspaceId: {
|
|
106
132
|
ok: workspaceOk,
|
|
107
133
|
status: workspaceOk ? "present" : "missing",
|
|
@@ -143,15 +169,15 @@ async function buildDoctorReceipt(config, flags, env) {
|
|
|
143
169
|
: {}),
|
|
144
170
|
},
|
|
145
171
|
},
|
|
146
|
-
next: nextSteps({ nodeOk,
|
|
172
|
+
next: nextSteps({ nodeOk, apiKey, workspaceOk, hasBaseUrlOverride: isPresent(config.baseUrl) }),
|
|
147
173
|
};
|
|
148
174
|
}
|
|
149
175
|
function nextSteps(input) {
|
|
150
176
|
const steps = [];
|
|
151
177
|
if (!input.nodeOk)
|
|
152
|
-
steps.push(
|
|
153
|
-
if (!input.
|
|
154
|
-
steps.push(
|
|
178
|
+
steps.push(`${INSTALL_NODE}.`);
|
|
179
|
+
if (!input.apiKey.ok && input.apiKey.recovery !== undefined)
|
|
180
|
+
steps.push(input.apiKey.recovery);
|
|
155
181
|
if (!input.workspaceOk)
|
|
156
182
|
steps.push("Set CLOCKIFY_WORKSPACE_ID or pass --workspace.");
|
|
157
183
|
if (input.hasBaseUrlOverride) {
|
|
@@ -163,46 +189,19 @@ function nextSteps(input) {
|
|
|
163
189
|
}
|
|
164
190
|
return steps;
|
|
165
191
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return "flag";
|
|
175
|
-
if (isPresent(env.CLOCKIFY_WORKSPACE_ID))
|
|
176
|
-
return "env";
|
|
177
|
-
if (isPresent(config.workspaceId))
|
|
178
|
-
return "rc";
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
if (field === "baseUrl") {
|
|
182
|
-
if (isPresent(flags.baseUrl))
|
|
183
|
-
return "flag";
|
|
184
|
-
if (isPresent(env.CLOCKIFY_BASE_URL))
|
|
185
|
-
return "env";
|
|
186
|
-
if (isPresent(config.baseUrl))
|
|
187
|
-
return "rc";
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
if (field === "region") {
|
|
191
|
-
if (isPresent(flags.region))
|
|
192
|
-
return "flag";
|
|
193
|
-
if (isPresent(env.CLOCKIFY_REGION))
|
|
194
|
-
return "env";
|
|
195
|
-
if (isPresent(config.region))
|
|
196
|
-
return "rc";
|
|
192
|
+
const SOURCES = {
|
|
193
|
+
workspaceId: { flag: "workspace", env: "CLOCKIFY_WORKSPACE_ID" },
|
|
194
|
+
baseUrl: { flag: "baseUrl", env: "CLOCKIFY_BASE_URL" },
|
|
195
|
+
region: { flag: "region", env: "CLOCKIFY_REGION" },
|
|
196
|
+
subdomain: { flag: "subdomain", env: "CLOCKIFY_SUBDOMAIN" },
|
|
197
|
+
};
|
|
198
|
+
function sourceFor(field, config, flags, processEnv) {
|
|
199
|
+
if (!isPresent(config[field]))
|
|
197
200
|
return undefined;
|
|
198
|
-
}
|
|
199
|
-
if (isPresent(flags
|
|
201
|
+
const { flag, env } = SOURCES[field];
|
|
202
|
+
if (isPresent(flags[flag]))
|
|
200
203
|
return "flag";
|
|
201
|
-
|
|
202
|
-
return "env";
|
|
203
|
-
if (isPresent(config.subdomain))
|
|
204
|
-
return "rc";
|
|
205
|
-
return undefined;
|
|
204
|
+
return flags.profile === undefined && isPresent(processEnv[env]) ? "env" : "rc";
|
|
206
205
|
}
|
|
207
206
|
function isPresent(value) {
|
|
208
207
|
return typeof value === "string" && value.trim().length > 0;
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
import { listExpensesFiltered } from "clockify-sdk-ts-115/expense-list";
|
|
2
2
|
import { expenseAmountToWire } from "clockify-sdk-ts-115/money";
|
|
3
|
+
import { expenseChangeFields } from "clockify-sdk-ts-115/updates";
|
|
3
4
|
import { InvalidArgumentError } from "commander";
|
|
4
5
|
import { UsageError } from "../failure.js";
|
|
5
|
-
import {
|
|
6
|
+
import { resolveFlags } from "../flags.js";
|
|
7
|
+
import { pickFields, printObject, printRecords, printWarning, warnUnknownFields } from "../output.js";
|
|
6
8
|
import { printReceipt } from "../receipt.js";
|
|
7
9
|
import { dispatchedWrite } from "../write-outcome.js";
|
|
8
|
-
import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, requireCurrentUserId, resolveContext, } from "./helpers.js";
|
|
10
|
+
import { clampPageSize, parseFloatArg, parseIntArg, printScan, promoteDateBoundary, requireCurrentUserId, resolveContext, rootProgram, } from "./helpers.js";
|
|
9
11
|
import { leafCommand } from "./leaf-command.js";
|
|
10
|
-
const EXPENSE_CHANGE_FIELDS = {
|
|
11
|
-
amount: "AMOUNT",
|
|
12
|
-
date: "DATE",
|
|
13
|
-
projectId: "PROJECT",
|
|
14
|
-
taskId: "TASK",
|
|
15
|
-
categoryId: "CATEGORY",
|
|
16
|
-
notes: "NOTES",
|
|
17
|
-
billable: "BILLABLE",
|
|
18
|
-
};
|
|
19
|
-
function expenseChangeFields(fields) {
|
|
20
|
-
return Object.entries(EXPENSE_CHANGE_FIELDS)
|
|
21
|
-
.filter(([key]) => fields[key] !== undefined)
|
|
22
|
-
.map(([, value]) => value);
|
|
23
|
-
}
|
|
24
12
|
function parseExpenseAmount(value) {
|
|
25
13
|
const amount = parseFloatArg(value);
|
|
26
14
|
try {
|
|
@@ -46,9 +34,13 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
46
34
|
.option("--max-pages <n>", "Maximum pages to scan (default 100, max 1000).", parseIntArg, 100)
|
|
47
35
|
.option("--offset <n>", "Matching rows to skip on the first page when resuming.", (value) => value === "0" ? 0 : parseIntArg(value), 0)
|
|
48
36
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
37
|
+
.option("--require-complete", "Print the rows, then exit 1 when more may be available.", false)
|
|
49
38
|
.option("--start <date>", "Inclusive start bound (YYYY-MM-DD or RFC3339 with explicit Z/offset).")
|
|
50
39
|
.option("--end <date>", "Inclusive end bound (YYYY-MM-DD or RFC3339 with explicit Z/offset).")
|
|
51
40
|
.action(async function (opts) {
|
|
41
|
+
if (opts.withMeta && resolveFlags(rootProgram(this)).mode === "csv") {
|
|
42
|
+
throw new UsageError("--with-meta needs --output json or ndjson.");
|
|
43
|
+
}
|
|
52
44
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
53
45
|
let requested = false;
|
|
54
46
|
const result = await listExpensesFiltered((request) => {
|
|
@@ -91,6 +83,7 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
91
83
|
for (const warning of result.warnings)
|
|
92
84
|
printWarning(warning, output);
|
|
93
85
|
const { meta } = result;
|
|
86
|
+
let gap;
|
|
94
87
|
if (meta.hasMore) {
|
|
95
88
|
const continuation = meta.nextPage === undefined
|
|
96
89
|
? "Reached the last supported page."
|
|
@@ -98,15 +91,19 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
98
91
|
const reason = rows.length === meta.limit
|
|
99
92
|
? `Returned the requested --limit of ${meta.limit} expenses. More rows may be available.`
|
|
100
93
|
: "The --max-pages cap stopped the scan before all pages were examined. Matches may be missing.";
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (opts.withMeta && output.mode === "json") {
|
|
104
|
-
printObject({ items: rows, meta }, output);
|
|
105
|
-
return;
|
|
94
|
+
gap = `${reason} ${continuation}`;
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
96
|
+
printScan(() => {
|
|
97
|
+
if (opts.withMeta && output.mode === "json") {
|
|
98
|
+
const { fields, ...shape } = output;
|
|
99
|
+
warnUnknownFields(rows, output);
|
|
100
|
+
printObject({ items: rows.map((row) => pickFields(row, fields)), meta }, shape);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
printRecords(rows, output);
|
|
104
|
+
if (opts.withMeta && output.mode === "ndjson")
|
|
105
|
+
console.log(JSON.stringify({ meta }));
|
|
106
|
+
}, gap, opts.requireComplete, output);
|
|
110
107
|
});
|
|
111
108
|
leafCommand(expenses, "create", "write")
|
|
112
109
|
.requiredOption("--amount <n>", "Amount.", parseExpenseAmount)
|
package/dist/commands/helpers.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
3
|
import { InvalidArgumentError } from "commander";
|
|
3
4
|
import { requireWorkspaceId } from "../config.js";
|
|
4
5
|
import { UsageError } from "../failure.js";
|
|
5
6
|
import { globalFlags, resolveFlags } from "../flags.js";
|
|
7
|
+
import { printWarning } from "../output.js";
|
|
8
|
+
import { readStdin } from "../stdin.js";
|
|
6
9
|
function parseStrictNumber(value) {
|
|
7
10
|
const trimmed = value.trim();
|
|
8
11
|
if (trimmed === "" || /^[+-]?0[xXoObB]/.test(trimmed)) {
|
|
@@ -52,6 +55,40 @@ export function splitList(value) {
|
|
|
52
55
|
.map((s) => s.trim())
|
|
53
56
|
.filter((s) => s.length > 0);
|
|
54
57
|
}
|
|
58
|
+
export function collect(value, previous) {
|
|
59
|
+
return [...previous, value];
|
|
60
|
+
}
|
|
61
|
+
export function parsePair(value, flag) {
|
|
62
|
+
const index = value.indexOf("=");
|
|
63
|
+
if (index <= 0) {
|
|
64
|
+
throw new UsageError(`${flag} expected key=value, received "${value}".`);
|
|
65
|
+
}
|
|
66
|
+
const key = value.slice(0, index).trim();
|
|
67
|
+
if (!key) {
|
|
68
|
+
throw new UsageError(`${flag} expected a non-empty key in "${value}".`);
|
|
69
|
+
}
|
|
70
|
+
return [key, value.slice(index + 1)];
|
|
71
|
+
}
|
|
72
|
+
export async function readTextInput(value, flag) {
|
|
73
|
+
if (value === undefined || (value !== "-" && !value.startsWith("@")))
|
|
74
|
+
return value;
|
|
75
|
+
try {
|
|
76
|
+
return value === "-" ? await readStdin() : readFileSync(value.slice(1), "utf8");
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
80
|
+
throw new UsageError(`${flag} ${JSON.stringify(value)} could not be read: ${detail}; provide a readable JSON file path or pipe the body on stdin`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function parseJson(text, flag, alternative) {
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(text);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
89
|
+
throw new UsageError(`${flag} is not valid JSON (${detail}); provide valid JSON${alternative === undefined ? "." : `, or ${alternative}.`}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
55
92
|
const BARE_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
56
93
|
const RFC3339_TIMESTAMP_PATTERN = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/;
|
|
57
94
|
function hasValidCalendarDate(yearText, monthText, dayText) {
|
|
@@ -111,6 +148,13 @@ export function promoteDateBoundary(value, flag, edge) {
|
|
|
111
148
|
}
|
|
112
149
|
return validValue;
|
|
113
150
|
}
|
|
151
|
+
export function printScan(print, gap, requireComplete, output) {
|
|
152
|
+
if (gap !== undefined && !requireComplete)
|
|
153
|
+
printWarning(gap, output);
|
|
154
|
+
print();
|
|
155
|
+
if (gap !== undefined && requireComplete)
|
|
156
|
+
throw new Error(gap);
|
|
157
|
+
}
|
|
114
158
|
export function rootProgram(cmd) {
|
|
115
159
|
let current = cmd;
|
|
116
160
|
while (current.parent != null) {
|
|
@@ -125,8 +169,8 @@ export async function resolveBaseContext(cmd, services, resolvedOutput) {
|
|
|
125
169
|
const client = await services.buildClient(config, cmd);
|
|
126
170
|
return { client, config, output };
|
|
127
171
|
}
|
|
128
|
-
export async function resolveContext(cmd, services) {
|
|
129
|
-
const { client, config, output } = await resolveBaseContext(cmd, services);
|
|
172
|
+
export async function resolveContext(cmd, services, resolvedOutput) {
|
|
173
|
+
const { client, config, output } = await resolveBaseContext(cmd, services, resolvedOutput);
|
|
130
174
|
return { client, workspaceId: requireWorkspaceId(config), output };
|
|
131
175
|
}
|
|
132
176
|
export async function requireCurrentUserId(client, hint) {
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
const commandRisks = new WeakMap();
|
|
2
|
+
const declaredMutations = new WeakMap();
|
|
3
|
+
export function declareMutation(command, mutates) {
|
|
4
|
+
declaredMutations.set(command, mutates);
|
|
5
|
+
}
|
|
2
6
|
export function isMutationCommand(command) {
|
|
7
|
+
const declared = declaredMutations.get(command);
|
|
8
|
+
if (declared !== undefined)
|
|
9
|
+
return declared;
|
|
3
10
|
if (command.name() === "api") {
|
|
4
11
|
const method = command.args[0]?.toUpperCase();
|
|
5
12
|
return method !== undefined && ["POST", "PUT", "PATCH", "DELETE"].includes(method);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { resolveFlags } from "../flags.js";
|
|
2
|
+
import { PACKAGE_VERSION } from "../generated/version.js";
|
|
3
|
+
import { fixedColumns, printObject, printRecords } from "../output.js";
|
|
4
|
+
import { collectClassifiedLeaves, leafCommand } from "./leaf-command.js";
|
|
5
|
+
function describeOption({ flags, long, description, mandatory, defaultValue, argChoices, variadic, required, optional }) {
|
|
6
|
+
const parameter = required ? "required" : optional ? "optional" : "none";
|
|
7
|
+
return {
|
|
8
|
+
name: long ?? flags,
|
|
9
|
+
flags,
|
|
10
|
+
description,
|
|
11
|
+
required: mandatory,
|
|
12
|
+
value: parameter,
|
|
13
|
+
...(variadic && { variadic }),
|
|
14
|
+
...(argChoices && { choices: argChoices }),
|
|
15
|
+
...(defaultValue !== undefined && { default: defaultValue }),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function describeArgument(argument) {
|
|
19
|
+
return {
|
|
20
|
+
name: argument.name(),
|
|
21
|
+
description: argument.description,
|
|
22
|
+
required: argument.required,
|
|
23
|
+
...(argument.variadic && { variadic: true }),
|
|
24
|
+
...(argument.argChoices && { choices: argument.argChoices }),
|
|
25
|
+
...(argument.defaultValue !== undefined && { default: argument.defaultValue }),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function commandManifest(program) {
|
|
29
|
+
return {
|
|
30
|
+
name: program.name(),
|
|
31
|
+
version: PACKAGE_VERSION,
|
|
32
|
+
exitCodes: {
|
|
33
|
+
0: "success",
|
|
34
|
+
1: "runtime or API error",
|
|
35
|
+
2: "usage error; nothing was changed",
|
|
36
|
+
129: "interrupted (SIGHUP)",
|
|
37
|
+
130: "interrupted (SIGINT)",
|
|
38
|
+
143: "interrupted (SIGTERM)",
|
|
39
|
+
},
|
|
40
|
+
globalOptions: program.options.map(describeOption),
|
|
41
|
+
commands: collectClassifiedLeaves(program).map(({ path, risk, command }) => ({
|
|
42
|
+
command: path.join(" "),
|
|
43
|
+
risk,
|
|
44
|
+
description: command.description(),
|
|
45
|
+
arguments: command.registeredArguments.map(describeArgument),
|
|
46
|
+
options: command.options.map(describeOption),
|
|
47
|
+
})),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export const registerCommandsCommand = (program) => {
|
|
51
|
+
leafCommand(program, "commands", "read")
|
|
52
|
+
.description("List every command with its arguments, options and risk, for scripts and agents.")
|
|
53
|
+
.addHelpText("after", "\nExamples:\n" + " $ clk115 commands\n" + " $ clk115 commands --json --select commands.command\n")
|
|
54
|
+
.action(function () {
|
|
55
|
+
const output = resolveFlags(program);
|
|
56
|
+
const manifest = commandManifest(program);
|
|
57
|
+
const rows = manifest.commands.map(({ command, risk, description }) => ({ command, risk, description }));
|
|
58
|
+
if (output.mode === "json" || output.mode === "ndjson")
|
|
59
|
+
printObject(manifest, fixedColumns(Object.keys(manifest), output));
|
|
60
|
+
else
|
|
61
|
+
printRecords(rows, fixedColumns(["command", "risk", "description"], output));
|
|
62
|
+
});
|
|
63
|
+
};
|