@zinn-dev/cli 0.43.0 → 0.45.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 +1 -1
- package/index.js +3 -3
- package/package.json +7 -4
- package/skills/zinn/SKILL.md +7 -9
- package/src/actor.d.ts +8 -0
- package/src/actor.js +5 -1
- package/src/capabilities-schema.d.ts +6 -2
- package/src/column-hint.js +2 -5
- package/src/database.d.ts +1 -2
- package/src/database.js +1 -6
- package/src/duration-input.d.ts +7 -0
- package/src/duration-input.js +31 -0
- package/src/errors.d.ts +34 -3
- package/src/errors.js +49 -7
- package/src/expected-values.d.ts +48 -0
- package/src/expected-values.js +60 -0
- package/src/failure-log.d.ts +6 -0
- package/src/failure-log.js +167 -0
- package/src/follow.d.ts +9 -0
- package/src/follow.js +58 -0
- package/src/input.d.ts +10 -7
- package/src/input.js +57 -13
- package/src/lib.d.ts +12 -7
- package/src/lib.js +70 -41
- package/src/list-continuation.js +1 -4
- package/src/list-limit.d.ts +2 -2
- package/src/list-limit.js +2 -2
- package/src/overview.d.ts +10 -0
- package/src/overview.js +41 -0
- package/src/presentation/activity-presentation.d.ts +4 -0
- package/src/presentation/activity-presentation.js +154 -38
- package/src/presentation/column-presentation.d.ts +22 -2
- package/src/presentation/column-presentation.js +68 -12
- package/src/presentation/doctor-presentation.d.ts +4 -0
- package/src/presentation/doctor-presentation.js +24 -0
- package/src/presentation/info-presentation.js +36 -6
- package/src/presentation/relation-presentation.d.ts +6 -2
- package/src/presentation/relation-presentation.js +37 -26
- package/src/presentation/task-blame-presentation.d.ts +8 -0
- package/src/presentation/task-blame-presentation.js +56 -0
- package/src/presentation/task-presentation.d.ts +8 -1
- package/src/presentation/task-presentation.js +59 -10
- package/src/result-schemas.d.ts +780 -20
- package/src/result-schemas.js +99 -2
- package/src/results.d.ts +6 -2
- package/src/results.js +9 -3
- package/src/routes/activity-router.d.ts +21 -4
- package/src/routes/activity-router.js +107 -60
- package/src/routes/aliases.js +1 -0
- package/src/routes/comment-router.d.ts +24 -6
- package/src/routes/comment-router.js +15 -5
- package/src/routes/doctor-router.d.ts +39 -0
- package/src/routes/doctor-router.js +103 -0
- package/src/routes/info-router.js +3 -2
- package/src/routes/label-router.d.ts +39 -6
- package/src/routes/label-router.js +22 -5
- package/src/routes/migrate-router.js +2 -2
- package/src/routes/project-router.d.ts +61 -12
- package/src/routes/project-router.js +103 -45
- package/src/routes/restore-router.js +11 -5
- package/src/routes/router.js +25 -16
- package/src/routes/routes.d.ts +455 -41
- package/src/routes/routes.js +4 -0
- package/src/routes/skill-router.d.ts +25 -0
- package/src/routes/skill-router.js +96 -0
- package/src/routes/task-router.d.ts +272 -19
- package/src/routes/task-router.js +325 -40
- package/src/routes/whoami-router.js +1 -1
- package/src/run-facts.d.ts +14 -0
- package/src/run-facts.js +14 -0
- package/src/store-folder.d.ts +5 -0
- package/src/store-folder.js +16 -0
- package/src/telemetry.d.ts +31 -0
- package/src/telemetry.js +329 -0
- package/src/text-edit.d.ts +2 -2
- package/src/text-input.d.ts +19 -1
- package/src/text-input.js +27 -10
- package/src/types.d.ts +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsonResult } from "../results.js";
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { column, project, columnOrderSchema, columnDeleteSchema, projectCreateSchema, projectEditSchema, } from "@zinn-dev/core";
|
|
3
|
+
import { column, project, columnCategorySchema, columnOrderSchema, columnDeleteSchema, projectCreateSchema, projectEditSchema, } from "@zinn-dev/core";
|
|
4
4
|
import { CliError } from "../errors.js";
|
|
5
5
|
import { generateCommandUsage, getOptionInputs, noInput, violatesConstraint } from "../input.js";
|
|
6
6
|
import { confirmationDescription, canPrompt, confirmAction, dashValueHelp, diagnostic, output, outputChanges, quit, validatePositionals, validateOrderForms, requireStringOption, validateUniqueOptions, } from "../lib.js";
|
|
7
7
|
import { resolveTextEdit, textEditHelp, textEditOptions, textEditConstraints, } from "../text-edit.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { expectedValueFlags } from "../expected-values.js";
|
|
9
|
+
import { checkFieldsBeforeText, checkSingleStdinReader, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
|
|
10
|
+
import { formatColumnList, presentColumn, presentColumnTaskCounts, } from "../presentation/column-presentation.js";
|
|
10
11
|
import { formatProjectList, presentProject } from "../presentation/project-presentation.js";
|
|
11
12
|
import { formatSection } from "../presentation/section.js";
|
|
12
13
|
import { currentActor } from "../actor.js";
|
|
@@ -15,6 +16,34 @@ const projectEditConstraint = {
|
|
|
15
16
|
kind: "atLeastOne",
|
|
16
17
|
members: ["option:name", "option:description", "option:description-file"],
|
|
17
18
|
};
|
|
19
|
+
const projectExpectations = expectedValueFlags({
|
|
20
|
+
name: { field: "name", option: { type: "string", value: { kind: "text", name: "text" } } },
|
|
21
|
+
description: { field: "description", text: true },
|
|
22
|
+
});
|
|
23
|
+
const columnCategoryOption = {
|
|
24
|
+
type: "string",
|
|
25
|
+
value: { kind: "enum", name: "category", choices: columnCategorySchema.options },
|
|
26
|
+
};
|
|
27
|
+
const columnCategoryValues = columnCategorySchema.options.join(", ");
|
|
28
|
+
const columnEditConstraint = {
|
|
29
|
+
kind: "atLeastOne",
|
|
30
|
+
members: ["option:name", "option:category"],
|
|
31
|
+
};
|
|
32
|
+
/** Asks before a category change that would change whether a column's tasks count as open or closed */
|
|
33
|
+
async function confirmCategoryChange(projectKey, columnName, category, isPreconfirmed) {
|
|
34
|
+
const columnMatch = column.getByName(projectKey, columnName);
|
|
35
|
+
const isSameCategory = columnMatch.category === category;
|
|
36
|
+
if (isPreconfirmed || isSameCategory) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
const { taskCount, archivedTaskCount } = column
|
|
40
|
+
.getTaskCountsByProjectKey(projectKey)
|
|
41
|
+
.columns.find((entry) => entry.column.id === columnMatch.id);
|
|
42
|
+
if (taskCount + archivedTaskCount === 0) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return confirmAction(`Column "${columnMatch.name}" holds ${taskCount} active and ${archivedTaskCount} archived tasks. Change its category from ${columnMatch.category} to ${category}?`, false);
|
|
46
|
+
}
|
|
18
47
|
const projectInputs = {
|
|
19
48
|
create: {
|
|
20
49
|
options: {
|
|
@@ -48,6 +77,7 @@ const projectInputs = {
|
|
|
48
77
|
description: { type: "string", value: { kind: "text", name: "text" } },
|
|
49
78
|
"description-file": textFileOption,
|
|
50
79
|
...textEditOptions,
|
|
80
|
+
...projectExpectations.options,
|
|
51
81
|
},
|
|
52
82
|
forms: [
|
|
53
83
|
{
|
|
@@ -59,8 +89,9 @@ const projectInputs = {
|
|
|
59
89
|
textSourceConstraint("--description"),
|
|
60
90
|
...textEditConstraints("--description"),
|
|
61
91
|
projectEditConstraint,
|
|
92
|
+
...projectExpectations.constraints,
|
|
62
93
|
],
|
|
63
|
-
notes: [requiredProjectDescription, textEditHelp("--description")],
|
|
94
|
+
notes: [requiredProjectDescription, textEditHelp("--description"), projectExpectations.help],
|
|
64
95
|
},
|
|
65
96
|
delete: {
|
|
66
97
|
options: { yes: { type: "boolean" } },
|
|
@@ -74,7 +105,7 @@ const projectInputs = {
|
|
|
74
105
|
notes: [requiredProjectDescription],
|
|
75
106
|
},
|
|
76
107
|
column_create: {
|
|
77
|
-
options: {},
|
|
108
|
+
options: { category: { ...columnCategoryOption, required: true } },
|
|
78
109
|
forms: [
|
|
79
110
|
{
|
|
80
111
|
id: "default",
|
|
@@ -98,7 +129,11 @@ const projectInputs = {
|
|
|
98
129
|
notes: [requiredProjectDescription],
|
|
99
130
|
},
|
|
100
131
|
column_edit: {
|
|
101
|
-
options: {
|
|
132
|
+
options: {
|
|
133
|
+
name: { type: "string", value: { kind: "text", name: "text" } },
|
|
134
|
+
category: columnCategoryOption,
|
|
135
|
+
yes: { type: "boolean" },
|
|
136
|
+
},
|
|
102
137
|
forms: [
|
|
103
138
|
{
|
|
104
139
|
id: "default",
|
|
@@ -108,7 +143,7 @@ const projectInputs = {
|
|
|
108
143
|
],
|
|
109
144
|
},
|
|
110
145
|
],
|
|
111
|
-
constraints: [],
|
|
146
|
+
constraints: [columnEditConstraint],
|
|
112
147
|
},
|
|
113
148
|
column_delete: {
|
|
114
149
|
options: { yes: { type: "boolean" } },
|
|
@@ -248,11 +283,7 @@ Example: zinn project list`,
|
|
|
248
283
|
const taskCounts = column.getTaskCountsByProjectKey(projectMatch.key);
|
|
249
284
|
const presentedProject = {
|
|
250
285
|
...presentProject(projectMatch),
|
|
251
|
-
columns: taskCounts
|
|
252
|
-
id: columnCount.column.id,
|
|
253
|
-
name: columnCount.column.name,
|
|
254
|
-
taskCount: columnCount.taskCount,
|
|
255
|
-
})),
|
|
286
|
+
columns: presentColumnTaskCounts(taskCounts),
|
|
256
287
|
archivedTaskCount: taskCounts.archivedTaskCount,
|
|
257
288
|
};
|
|
258
289
|
output(presentedProject, (viewedProject) => {
|
|
@@ -296,10 +327,13 @@ Example: zinn project view MDR`,
|
|
|
296
327
|
validateUniqueOptions(tokens, projectInputs.edit.options);
|
|
297
328
|
validatePositionals(positionals, projectInputs.edit.forms[0]);
|
|
298
329
|
const projectChoice = chooseProjectKey(positionals[0], { required: true });
|
|
330
|
+
const expected = projectExpectations.parseValues(values);
|
|
299
331
|
checkFieldsBeforeText(projectEditSchema, {
|
|
300
332
|
projectKey: projectChoice.key,
|
|
301
333
|
name: values.name,
|
|
334
|
+
expected,
|
|
302
335
|
});
|
|
336
|
+
checkSingleStdinReader(values, ["--description", ...projectExpectations.textFlags]);
|
|
303
337
|
const description = await resolveTextEdit(values, "--description");
|
|
304
338
|
// Without a text source nothing was read, so this usage error still comes before any input
|
|
305
339
|
if (violatesConstraint(projectEditConstraint, getOptionInputs(values))) {
|
|
@@ -308,7 +342,13 @@ Example: zinn project view MDR`,
|
|
|
308
342
|
});
|
|
309
343
|
}
|
|
310
344
|
checkDefaultProject(projectChoice);
|
|
311
|
-
const
|
|
345
|
+
const expectedText = await projectExpectations.resolveText(values);
|
|
346
|
+
const editedProject = project.edit({
|
|
347
|
+
projectKey: projectChoice.key,
|
|
348
|
+
name: values.name,
|
|
349
|
+
description,
|
|
350
|
+
expected: { ...expected, ...expectedText },
|
|
351
|
+
}, currentActor());
|
|
312
352
|
outputChanges([editedProject], (change) => presentProject(change.project), formatProjectList, (entry) => `Project ${entry.key} was unchanged`);
|
|
313
353
|
},
|
|
314
354
|
help: `${generateCommandUsage("project edit", projectInputs.edit)}
|
|
@@ -321,11 +361,14 @@ ${textFileHelp("--description")}
|
|
|
321
361
|
|
|
322
362
|
${textEditHelp("--description")}
|
|
323
363
|
|
|
364
|
+
${projectExpectations.help}
|
|
365
|
+
|
|
324
366
|
${dashValueHelp("--description")}
|
|
325
367
|
|
|
326
368
|
Examples:
|
|
327
369
|
zinn project edit MDR --name 'Macrodata Refinement'
|
|
328
|
-
zinn project edit MDR --description database --replacing board --all
|
|
370
|
+
zinn project edit MDR --description database --replacing board --all
|
|
371
|
+
zinn project edit MDR --name 'Macrodata Refinement' --expect-name 'Macrodata'`,
|
|
329
372
|
},
|
|
330
373
|
delete: {
|
|
331
374
|
summary: "Permanently delete a project and all of its columns and tasks after confirmation.",
|
|
@@ -397,29 +440,34 @@ Example: zinn project delete MDR`,
|
|
|
397
440
|
input: projectInputs.column_create,
|
|
398
441
|
results: [jsonResult("Column")],
|
|
399
442
|
run: (args) => {
|
|
400
|
-
const { positionals } = parseArgs({
|
|
443
|
+
const { values, positionals, tokens } = parseArgs({
|
|
401
444
|
options: projectInputs.column_create.options,
|
|
402
445
|
args,
|
|
403
446
|
allowPositionals: true,
|
|
404
447
|
strict: true,
|
|
448
|
+
tokens: true,
|
|
405
449
|
});
|
|
450
|
+
validateUniqueOptions(tokens, projectInputs.column_create.options);
|
|
406
451
|
validatePositionals(positionals, projectInputs.column_create.forms[0]);
|
|
407
|
-
const
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
throw err;
|
|
415
|
-
}
|
|
452
|
+
const category = requireStringOption(projectInputs.column_create.options.category, values.category, "category", `Provide the column's category with --category: ${columnCategoryValues}`);
|
|
453
|
+
const createdColumn = column.create({
|
|
454
|
+
projectKey: positionals[0],
|
|
455
|
+
name: positionals[1],
|
|
456
|
+
category: category,
|
|
457
|
+
}, currentActor());
|
|
458
|
+
output(presentColumn(createdColumn), (entry) => formatColumnList([entry], { showsProject: true }));
|
|
416
459
|
},
|
|
417
460
|
help: `${generateCommandUsage("project column create", projectInputs.column_create)}
|
|
418
461
|
|
|
419
462
|
Add a column at the end of a project's board.
|
|
420
463
|
Names are trimmed, cannot be blank or contain line breaks or control characters, and must be unique within the project regardless of casing.
|
|
421
464
|
|
|
422
|
-
|
|
465
|
+
--category is required and says what the column's tasks are to Zinn, whatever the column is called.
|
|
466
|
+
Category values: ${columnCategoryValues}.
|
|
467
|
+
Tasks in done and cancelled columns are closed: task next skips them, and they no longer block tasks that depend on them.
|
|
468
|
+
task next hands out tasks in todo columns, then backlog columns.
|
|
469
|
+
|
|
470
|
+
Example: zinn project column create MDR Boardlog --category backlog`,
|
|
423
471
|
},
|
|
424
472
|
list: {
|
|
425
473
|
summary: "List a project's columns in board order with their unarchived task counts.",
|
|
@@ -436,12 +484,7 @@ Example: zinn project column create MDR Boardlog`,
|
|
|
436
484
|
});
|
|
437
485
|
validatePositionals(positionals, projectInputs.column_list.forms[0]);
|
|
438
486
|
const projectKey = resolveProjectKey(positionals[0], { required: true });
|
|
439
|
-
const
|
|
440
|
-
const columns = taskCounts.columns.map((columnCount) => ({
|
|
441
|
-
id: columnCount.column.id,
|
|
442
|
-
name: columnCount.column.name,
|
|
443
|
-
taskCount: columnCount.taskCount,
|
|
444
|
-
}));
|
|
487
|
+
const columns = presentColumnTaskCounts(column.getTaskCountsByProjectKey(projectKey));
|
|
445
488
|
output(columns, (presentedColumns) => formatColumnList(presentedColumns, {
|
|
446
489
|
showsTaskCounts: true,
|
|
447
490
|
}));
|
|
@@ -454,12 +497,15 @@ ${requiredProjectDescription}
|
|
|
454
497
|
Example: zinn project column list MDR`,
|
|
455
498
|
},
|
|
456
499
|
edit: {
|
|
457
|
-
summary: "Rename a column.",
|
|
500
|
+
summary: "Rename a column or change its category.",
|
|
458
501
|
effects: { domain: "update", storage: "normal-open" },
|
|
459
|
-
confirmation: {
|
|
502
|
+
confirmation: {
|
|
503
|
+
kind: "prompt",
|
|
504
|
+
description: `Only asks when changing the category of a column that holds tasks. ${confirmationDescription}`,
|
|
505
|
+
},
|
|
460
506
|
input: projectInputs.column_edit,
|
|
461
507
|
results: [jsonResult("ColumnChange")],
|
|
462
|
-
run: (args) => {
|
|
508
|
+
run: async (args) => {
|
|
463
509
|
const { values, positionals, tokens } = parseArgs({
|
|
464
510
|
args,
|
|
465
511
|
options: projectInputs.column_edit.options,
|
|
@@ -469,19 +515,29 @@ Example: zinn project column list MDR`,
|
|
|
469
515
|
});
|
|
470
516
|
validateUniqueOptions(tokens, projectInputs.column_edit.options);
|
|
471
517
|
validatePositionals(positionals, projectInputs.column_edit.forms[0]);
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
518
|
+
if (violatesConstraint(columnEditConstraint, getOptionInputs(values))) {
|
|
519
|
+
quit("Provide an edit flag: --name or --category", undefined, { field: [] });
|
|
520
|
+
}
|
|
521
|
+
const projectKey = positionals[0];
|
|
522
|
+
const columnName = positionals[1];
|
|
523
|
+
const category = values.category;
|
|
524
|
+
if (category !== undefined) {
|
|
525
|
+
const isConfirmed = await confirmCategoryChange(projectKey, columnName, category, values.yes === true);
|
|
526
|
+
if (!isConfirmed) {
|
|
527
|
+
diagnostic("Column edit cancelled");
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const editedColumn = column.edit({ projectKey, columnName, name: values.name, category }, currentActor());
|
|
478
532
|
outputChanges([editedColumn], (change) => presentColumn(change.column), (entries) => formatColumnList(entries, { showsProject: true }), (entry) => `Column "${entry.name}" was unchanged`);
|
|
479
533
|
},
|
|
480
534
|
help: `${generateCommandUsage("project column edit", projectInputs.column_edit)}
|
|
481
535
|
|
|
482
|
-
Rename a column.
|
|
483
|
-
|
|
484
|
-
|
|
536
|
+
Rename a column, change its category, or both.
|
|
537
|
+
Provide --name, --category or both.
|
|
538
|
+
Category values: ${columnCategoryValues}.
|
|
539
|
+
Changing the category of a column that holds tasks, active or archived, asks first: it changes which of them count as open or closed. Use --yes to change it without a prompt, including with --json or without a terminal.
|
|
540
|
+
With --json, changed is false when the name and category already match.
|
|
485
541
|
|
|
486
542
|
Columns are matched by name, and matching is case-insensitive.
|
|
487
543
|
Names are trimmed, and must remain unique within the same project.
|
|
@@ -489,7 +545,9 @@ Changing only the casing of a column's own name is allowed.
|
|
|
489
545
|
|
|
490
546
|
${dashValueHelp("--name")}
|
|
491
547
|
|
|
492
|
-
|
|
548
|
+
Examples:
|
|
549
|
+
zinn project column edit MDR Doing --name Refining
|
|
550
|
+
zinn project column edit MDR Shipped --category done --yes`,
|
|
493
551
|
},
|
|
494
552
|
order: {
|
|
495
553
|
summary: "Change a column's position on the project's board.",
|
|
@@ -531,7 +589,7 @@ Columns are matched by name, and matching is case-insensitive.
|
|
|
531
589
|
Ordering to the current position, or before or after itself, leaves the column unchanged.
|
|
532
590
|
With --json, changed is false when the column was already in that position.
|
|
533
591
|
|
|
534
|
-
Example: zinn project column order MDR Review before
|
|
592
|
+
Example: zinn project column order MDR Review before Doing`,
|
|
535
593
|
},
|
|
536
594
|
delete: {
|
|
537
595
|
summary: "Delete an empty project column after confirmation.",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { backup, RestoreRefusedError,
|
|
3
|
+
import { backup, RestoreRefusedError, getBackupStorage, isSqliteErrorFamily } from "@zinn-dev/core";
|
|
4
4
|
import { jsonResult } from "../results.js";
|
|
5
5
|
import { reportLockWait } from "../database.js";
|
|
6
6
|
import { confirmationDescription } from "../lib.js";
|
|
@@ -34,11 +34,12 @@ export const restoreCommand = {
|
|
|
34
34
|
validateUniqueOptions(tokens, restoreInputs.command.options);
|
|
35
35
|
validatePositionals(positionals, restoreInputs.command.forms[0]);
|
|
36
36
|
const path = resolve(positionals[0]);
|
|
37
|
-
const
|
|
37
|
+
const storage = getBackupStorage();
|
|
38
|
+
const { databasePath, backupDirectory } = storage;
|
|
38
39
|
const isPreconfirmed = values.yes === true;
|
|
39
40
|
// A backup that would be refused is refused before the prompt.
|
|
40
41
|
if (!isPreconfirmed) {
|
|
41
|
-
backup.check({ ...build, path });
|
|
42
|
+
backup.check({ ...build, path, storage });
|
|
42
43
|
}
|
|
43
44
|
const isConfirmed = await askConfirmation(`Replace the database at ${databasePath} with the backup ${path}? The current database is saved to ${backupDirectory} first.`, isPreconfirmed);
|
|
44
45
|
if (!isConfirmed) {
|
|
@@ -46,7 +47,12 @@ export const restoreCommand = {
|
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
try {
|
|
49
|
-
const result = backup.restore({
|
|
50
|
+
const result = backup.restore({
|
|
51
|
+
...build,
|
|
52
|
+
path,
|
|
53
|
+
storage,
|
|
54
|
+
onWait: reportLockWait,
|
|
55
|
+
});
|
|
50
56
|
output(result, (r) => {
|
|
51
57
|
const restored = `Restored the database from ${path} at schema version ${r.restoredVersion}.`;
|
|
52
58
|
return r.backupPath == null
|
|
@@ -78,7 +84,7 @@ Replace the database with the one in a backup file, such as one saved by \`zinn
|
|
|
78
84
|
The current database is saved first, in the same place as \`zinn backup\`, and the restore is applied completely or not at all.
|
|
79
85
|
A backup with an older schema version is restored at that version. Zinn then upgrades it like any older database: by itself, except for ~/.zinn run from a source checkout, which needs \`zinn migrate\`.
|
|
80
86
|
Restoring onto a missing database creates it inside an existing Zinn folder.
|
|
81
|
-
Fails, leaving the database as it is, when the backup has a newer schema version than this Zinn or none at all, is damaged,
|
|
87
|
+
Fails, leaving the database as it is, when the backup has a newer schema version than this Zinn or none at all, is damaged, is not a Zinn database, is the database itself, or changes after restore checked it.
|
|
82
88
|
Use --yes to skip the confirmation prompt, for example in scripts or with --json.
|
|
83
89
|
|
|
84
90
|
Example: zinn restore ~/.zinn/backups/2026-10-06T12-30-05Z-cli-0.40.0-1a2b3c4d.sqlite`,
|
package/src/routes/router.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
|
-
import { routerOptions, helpSpellings, versionSpellings, usageLabel } from "../input.js";
|
|
2
|
+
import { routerOptions, helpSpellings, versionSpellings, usageLabel, isHelpFlag, isRouterFlag, splitAtOptionSeparator, } from "../input.js";
|
|
3
3
|
import { getCommandAliases } from "./aliases.js";
|
|
4
4
|
import { classifyFailure, CliError } from "../errors.js";
|
|
5
5
|
import { quotedColumnHint } from "../column-hint.js";
|
|
6
6
|
import { formatCell } from "../presentation/row-layout.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return process.env.ZINN_DEBUG === "1";
|
|
11
|
-
}
|
|
7
|
+
import { formatOverview } from "../overview.js";
|
|
8
|
+
import { boundParserMessage, dashValueHelp, diagnostic, failureMessage, finishRun, isDebugOutputEnabled, isParseArgsError, parseArgsFailure, prepareOutput, quit, renderFailure, UsageError, validateUniqueOptions, } from "../lib.js";
|
|
9
|
+
import { noteMatchedRun, noteParseArgsThrew, noteUnmatchedRun } from "../telemetry.js";
|
|
12
10
|
function getIsRunnable(obj) {
|
|
13
11
|
return Object.hasOwn(obj, "run");
|
|
14
12
|
}
|
|
15
|
-
// --json
|
|
13
|
+
// --json can be given once, like a command's own flags.
|
|
16
14
|
function validateRouterFlags(routableArgs) {
|
|
17
15
|
const { tokens } = parseArgs({
|
|
18
16
|
args: routableArgs.filter(isRouterFlag),
|
|
@@ -79,11 +77,13 @@ Options:
|
|
|
79
77
|
${helpSpellings.join(", ")} Show help
|
|
80
78
|
${versionSpellings.join(", ")} Show version
|
|
81
79
|
--json Print command output as JSON
|
|
82
|
-
--allow-legacy-read Read a database without a schema version, best effort and read-only
|
|
83
80
|
|
|
84
81
|
Commands:
|
|
85
82
|
${formatCommands(parsedRoutes, "")}
|
|
86
83
|
|
|
84
|
+
What Zinn can do:
|
|
85
|
+
${formatOverview()}
|
|
86
|
+
|
|
87
87
|
Run zinn <namespace> --help or zinn <command> --help for more information.
|
|
88
88
|
--help shows help for the command words before it and runs nothing. The rest of the line is ignored.
|
|
89
89
|
-- ends the options; every word after it is positional, even if it starts with a dash.
|
|
@@ -112,6 +112,11 @@ function routeToNamespace(parsedRoutes, words, isHelpRequest) {
|
|
|
112
112
|
const { namespace, wordCount, help } = findNearestNamespace(parsedRoutes, words);
|
|
113
113
|
const unknownWord = words[wordCount];
|
|
114
114
|
const commandName = namespace === "" ? "zinn" : `zinn ${namespace}`;
|
|
115
|
+
noteUnmatchedRun({
|
|
116
|
+
namespace,
|
|
117
|
+
help: isHelpRequest,
|
|
118
|
+
...(unknownWord == null ? {} : { unmatchedWord: unknownWord }),
|
|
119
|
+
});
|
|
115
120
|
if (unknownWord == null && isHelpRequest) {
|
|
116
121
|
console.info(help);
|
|
117
122
|
return;
|
|
@@ -168,13 +173,8 @@ export function parseRoutes(routesDef, prefix) {
|
|
|
168
173
|
async function route(parsedRoutes, rawArgs, beforeRun) {
|
|
169
174
|
prepareOutput(rawArgs);
|
|
170
175
|
// Anything after "--" belongs to the command, so "--json" there is search text, not a flag.
|
|
171
|
-
const
|
|
172
|
-
const routableArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
|
|
173
|
-
const passthroughArgs = separatorIndex === -1 ? [] : rawArgs.slice(separatorIndex);
|
|
176
|
+
const { optionWords: routableArgs, passthroughWords: passthroughArgs } = splitAtOptionSeparator(rawArgs);
|
|
174
177
|
const filteredRoutableArgs = routableArgs.filter((arg) => !isRouterFlag(arg));
|
|
175
|
-
if (routableArgs.some(isAllowLegacyReadFlag)) {
|
|
176
|
-
setLegacyReadAllowed(true);
|
|
177
|
-
}
|
|
178
178
|
// A help flag asks for help with the command words before it, so nothing after it is read.
|
|
179
179
|
const helpFlagIndex = filteredRoutableArgs.findIndex(isHelpFlag);
|
|
180
180
|
const isHelpRequest = helpFlagIndex !== -1;
|
|
@@ -192,17 +192,26 @@ async function route(parsedRoutes, rawArgs, beforeRun) {
|
|
|
192
192
|
routeToNamespace(parsedRoutes, args, isHelpRequest);
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
+
const commandArgs = args.slice(nestingLevel);
|
|
196
|
+
noteMatchedRun({
|
|
197
|
+
match,
|
|
198
|
+
typedRoute: toCommand(args.slice(0, nestingLevel)),
|
|
199
|
+
commandArgs,
|
|
200
|
+
help: isHelpRequest,
|
|
201
|
+
});
|
|
195
202
|
if (isHelpRequest) {
|
|
196
203
|
console.info(match.help);
|
|
197
204
|
return;
|
|
198
205
|
}
|
|
199
206
|
validateRouterFlags(routableArgs);
|
|
200
|
-
const commandArgs = args.slice(nestingLevel);
|
|
201
207
|
try {
|
|
202
208
|
await beforeRun?.(match);
|
|
203
209
|
await match.run(commandArgs);
|
|
204
210
|
}
|
|
205
211
|
catch (err) {
|
|
212
|
+
if (isParseArgsError(err)) {
|
|
213
|
+
noteParseArgsThrew();
|
|
214
|
+
}
|
|
206
215
|
if (err instanceof UsageError) {
|
|
207
216
|
err.help = getUsage(match.help);
|
|
208
217
|
}
|
|
@@ -249,7 +258,7 @@ export function createRouter(routesDef, beforeRun) {
|
|
|
249
258
|
route: async (args) => {
|
|
250
259
|
try {
|
|
251
260
|
await route(parsedRoutes, args, beforeRun);
|
|
252
|
-
|
|
261
|
+
finishRun();
|
|
253
262
|
}
|
|
254
263
|
catch (error) {
|
|
255
264
|
renderFailure(error);
|