@zinn-dev/cli 0.38.0 → 0.40.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.
Files changed (92) hide show
  1. package/README.md +47 -9
  2. package/index.d.ts +2 -0
  3. package/index.js +23 -0
  4. package/package.json +22 -18
  5. package/src/actor.d.ts +6 -0
  6. package/src/actor.js +62 -0
  7. package/src/database.d.ts +6 -0
  8. package/src/database.js +27 -0
  9. package/src/lib.d.ts +31 -0
  10. package/src/lib.js +137 -0
  11. package/src/presentation/activity-presentation.d.ts +23 -0
  12. package/src/presentation/activity-presentation.js +389 -0
  13. package/src/presentation/color.d.ts +9 -0
  14. package/src/presentation/color.js +21 -0
  15. package/src/presentation/column-presentation.d.ts +16 -0
  16. package/src/presentation/column-presentation.js +29 -0
  17. package/src/presentation/description-presentation.d.ts +3 -0
  18. package/src/presentation/description-presentation.js +11 -0
  19. package/src/presentation/row-layout.d.ts +22 -0
  20. package/src/presentation/row-layout.js +58 -0
  21. package/src/presentation/section.d.ts +4 -0
  22. package/src/presentation/section.js +9 -0
  23. package/src/presentation/task-presentation.d.ts +17 -0
  24. package/src/presentation/task-presentation.js +62 -0
  25. package/src/presentation/time.d.ts +1 -0
  26. package/src/presentation/time.js +13 -0
  27. package/src/project.d.ts +6 -0
  28. package/src/project.js +31 -0
  29. package/src/release-identity.d.ts +2 -0
  30. package/src/release-identity.js +1 -0
  31. package/src/routes/activity-router.d.ts +10 -0
  32. package/src/routes/activity-router.js +71 -0
  33. package/src/routes/backup-router.d.ts +4 -0
  34. package/src/routes/backup-router.js +18 -0
  35. package/src/routes/comment-router.d.ts +24 -0
  36. package/src/routes/comment-router.js +134 -0
  37. package/src/routes/label-router.d.ts +18 -0
  38. package/src/routes/label-router.js +136 -0
  39. package/src/routes/migrate-router.d.ts +4 -0
  40. package/src/routes/migrate-router.js +37 -0
  41. package/src/routes/project-router.d.ts +40 -0
  42. package/src/routes/project-router.js +328 -0
  43. package/src/routes/reindex-router.d.ts +4 -0
  44. package/src/routes/reindex-router.js +21 -0
  45. package/src/routes/relation-router.d.ts +28 -0
  46. package/src/routes/relation-router.js +163 -0
  47. package/src/routes/restore-router.d.ts +4 -0
  48. package/src/routes/restore-router.js +71 -0
  49. package/src/routes/router.d.ts +6 -0
  50. package/src/routes/router.js +185 -0
  51. package/src/routes/routes.d.ts +170 -0
  52. package/src/routes/routes.js +19 -0
  53. package/src/routes/task-router.d.ts +84 -0
  54. package/src/routes/task-router.js +533 -0
  55. package/src/text-edit.d.ts +25 -0
  56. package/src/text-edit.js +45 -0
  57. package/src/types.d.ts +10 -0
  58. package/src/types.js +1 -0
  59. package/index.ts +0 -26
  60. package/release-stamp.json +0 -1
  61. package/src/actor.test.ts +0 -41
  62. package/src/actor.ts +0 -78
  63. package/src/database.test.ts +0 -70
  64. package/src/database.ts +0 -41
  65. package/src/lib.test.ts +0 -86
  66. package/src/lib.ts +0 -145
  67. package/src/presentation/activity-presentation.test.ts +0 -71
  68. package/src/presentation/activity-presentation.ts +0 -489
  69. package/src/presentation/color.ts +0 -29
  70. package/src/presentation/column-presentation.ts +0 -48
  71. package/src/presentation/description-presentation.ts +0 -18
  72. package/src/presentation/row-layout.ts +0 -77
  73. package/src/presentation/section.ts +0 -16
  74. package/src/presentation/task-presentation.ts +0 -92
  75. package/src/presentation/time.ts +0 -17
  76. package/src/routes/activity-router.ts +0 -77
  77. package/src/routes/backup-router.ts +0 -24
  78. package/src/routes/comment-router.ts +0 -171
  79. package/src/routes/label-router.ts +0 -168
  80. package/src/routes/migrate-router.test.ts +0 -31
  81. package/src/routes/migrate-router.ts +0 -48
  82. package/src/routes/project-router.ts +0 -387
  83. package/src/routes/reindex-router.ts +0 -27
  84. package/src/routes/relation-router.ts +0 -194
  85. package/src/routes/restore-router.test.ts +0 -44
  86. package/src/routes/restore-router.ts +0 -90
  87. package/src/routes/router.test.ts +0 -136
  88. package/src/routes/router.ts +0 -248
  89. package/src/routes/routes.ts +0 -20
  90. package/src/routes/task-router.ts +0 -594
  91. package/src/text-edit.ts +0 -68
  92. package/src/types.ts +0 -6
@@ -1,92 +0,0 @@
1
- import type { LabelColor, TaskPriority, TaskWithKey } from "@zinn-dev/core";
2
- import type { RowCell } from "./row-layout";
3
-
4
- import { column, label, task } from "@zinn-dev/core";
5
-
6
- import { styleOutputText } from "./color";
7
- import { columnNameCell } from "./column-presentation";
8
- import { formatCellSeparator, formatRows } from "./row-layout";
9
-
10
- export type PresentedTask = {
11
- key: string;
12
- status: "Active" | "Archived";
13
- column: string;
14
- title: string;
15
- description: string | null;
16
- priority: TaskPriority | null;
17
- labels: Array<string>;
18
- };
19
-
20
- const EMPTY_CELL_MARKER = "-";
21
- const LABEL_NAME_SEPARATOR = ", ";
22
-
23
- function taskPriorityCell(priority: TaskPriority | null, showsFullPriority: boolean): RowCell {
24
- if (priority == null) {
25
- return { text: EMPTY_CELL_MARKER, style: "dim" };
26
- }
27
-
28
- const priorityInitial = priority[0]!.toUpperCase();
29
- return { text: showsFullPriority ? `${priorityInitial}${priority.slice(1)}` : priorityInitial };
30
- }
31
-
32
- /**
33
- * `PresentedTask` carries label names only, so JSON stays a list of names.
34
- * Text output looks the colors up from the label definitions instead.
35
- */
36
- function getLabelColorsByName() {
37
- return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
38
- }
39
-
40
- function formatLabelNames(labelNames: Array<string>, labelColorsByName: Map<string, LabelColor>) {
41
- return labelNames
42
- .map((labelName) => styleOutputText(labelColorsByName.get(labelName)!, labelName))
43
- .join(LABEL_NAME_SEPARATOR);
44
- }
45
-
46
- export function presentTask(taskMatch: TaskWithKey): PresentedTask {
47
- return {
48
- key: taskMatch.key,
49
- status: taskMatch.archived_at == null ? "Active" : "Archived",
50
- column: column.getById(taskMatch.column_id)!.name,
51
- title: taskMatch.title,
52
- description: taskMatch.description,
53
- priority: taskMatch.priority,
54
- labels: task.label.getAll(taskMatch.key).map((label) => label.name),
55
- };
56
- }
57
-
58
- export function formatTaskRow(presented: PresentedTask) {
59
- return formatTaskList([presented]);
60
- }
61
-
62
- export function formatTaskList(
63
- presentedTasks: Array<PresentedTask>,
64
- options: { showsStatus?: boolean; showsFullPriority?: boolean } = {},
65
- ) {
66
- const labelColorsByName = getLabelColorsByName();
67
-
68
- return formatRows(
69
- presentedTasks.map((presentedTask) => {
70
- const statusCells: Array<RowCell> = options.showsStatus
71
- ? [{ text: presentedTask.status }]
72
- : [];
73
- const hasLabels = presentedTask.labels.length > 0;
74
- // The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
75
- const labels = hasLabels
76
- ? `${formatCellSeparator()}${formatLabelNames(presentedTask.labels, labelColorsByName)}`
77
- : "";
78
-
79
- return [
80
- { text: presentedTask.key },
81
- ...statusCells,
82
- columnNameCell(presentedTask.column),
83
- taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
84
- { text: `${presentedTask.title}${labels}` },
85
- ];
86
- }),
87
- );
88
- }
89
-
90
- export function formatTaskListWithStatus(presentedTasks: Array<PresentedTask>) {
91
- return formatTaskList(presentedTasks, { showsStatus: true });
92
- }
@@ -1,17 +0,0 @@
1
- const MINUTES_PER_HOUR = 60;
2
-
3
- export function formatLocalTime(timestamp: number) {
4
- const date = new Date(timestamp);
5
- const offsetMinutes = -date.getTimezoneOffset();
6
- const offsetSign = offsetMinutes >= 0 ? "+" : "-";
7
- const absoluteOffsetMinutes = Math.abs(offsetMinutes);
8
- const offsetHours = Math.floor(absoluteOffsetMinutes / MINUTES_PER_HOUR);
9
- const remainingOffsetMinutes = absoluteOffsetMinutes % MINUTES_PER_HOUR;
10
- const pad = (value: number) => String(value).padStart(2, "0");
11
-
12
- return (
13
- `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
14
- `${pad(date.getHours())}:${pad(date.getMinutes())} ` +
15
- `${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`
16
- );
17
- }
@@ -1,77 +0,0 @@
1
- import type { RouteDef } from "../types";
2
-
3
- import { parseArgs } from "node:util";
4
- import { activity, activityLimitMessage, positiveIntegerPattern } from "@zinn-dev/core";
5
- import { output, quit, validatePositionals, validateUniqueOptions } from "../lib";
6
- import { formatActivityList, presentActivities } from "../presentation/activity-presentation";
7
-
8
- export const activityRouter = {
9
- list: {
10
- run: (args) => {
11
- const { values, positionals, tokens } = parseArgs({
12
- args,
13
- options: { task: { type: "string" }, limit: { type: "string" } },
14
- allowPositionals: true,
15
- strict: true,
16
- tokens: true,
17
- });
18
- validateUniqueOptions(tokens);
19
- validatePositionals(positionals, []);
20
-
21
- // Safe integers can have one more digit than readable task numbers.
22
- const limitPattern = new RegExp(`^${positiveIntegerPattern}\\d?$`);
23
- if (values.limit !== undefined && !limitPattern.test(values.limit)) {
24
- quit(activityLimitMessage);
25
- }
26
-
27
- const events = activity.getAll({
28
- taskKey: values.task,
29
- limit: values.limit === undefined ? undefined : Number(values.limit),
30
- });
31
-
32
- output(events, (items) =>
33
- formatActivityList(presentActivities(items, { taskKey: values.task })),
34
- );
35
- },
36
- help: `Usage: zinn activity list [--task <task-key>] [--limit <n>] [--json]
37
-
38
- List recorded activity across the database, newest first.
39
- By default, all matching events are returned. --limit takes a positive safe integer.
40
- --task includes existing, archived and deleted task lifetimes for that key,
41
- including the recorded project deletion that removed a task.
42
- A key reused after project deletion includes every known lifetime.
43
- A valid key without recoverable history returns an empty list.
44
-
45
- Text times are local dates/times with a UTC offset.
46
- Event IDs are the shortest globally unique left prefixes of at least eight hex digits.
47
- Use activity view for full recorded changes; full IDs are durable, short prefixes may become ambiguous.
48
- With --json, output is an array of full activity records, with parsed changes or null.
49
-
50
- Examples:
51
- zinn activity list --limit 10
52
- zinn activity list --task APP-2 --json`,
53
- },
54
- view: {
55
- run: (args) => {
56
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
57
- validatePositionals(positionals, ["<activity-id>"]);
58
- output(activity.getById(positionals[0]!), (event) =>
59
- formatActivityList(presentActivities([event], { showsFullIds: true }), {
60
- showsDetails: true,
61
- }),
62
- );
63
- },
64
- help: `Usage: zinn activity view <activity-id> [--json]
65
-
66
- Show one recorded event with full activity/entity IDs, actor and complete changes.
67
- Text and line breaks are preserved; unknown change fields remain available as raw JSON.
68
- Text times are local dates/times with a UTC offset.
69
-
70
- Accept a full UUID or unique left prefix with at least eight hexadecimal digits.
71
- Matching ignores case and accepts canonical hyphens or uninterrupted hexadecimal digits.
72
- An ambiguous prefix lists candidate IDs and requires more characters.
73
- With --json, output is one full activity record, with parsed changes or null.
74
-
75
- Example: zinn activity view 019abcdf-1234-7`,
76
- },
77
- } satisfies RouteDef;
@@ -1,24 +0,0 @@
1
- import type { Command } from "../types";
2
-
3
- import { parseArgs } from "node:util";
4
- import { backup } from "@zinn-dev/core";
5
-
6
- import { output, validatePositionals } from "../lib";
7
- import packageJson from "../../package.json";
8
-
9
- export const backupCommand = {
10
- run: (args) => {
11
- const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
12
- validatePositionals(positionals, []);
13
-
14
- const created = backup.create({ client: "cli", version: packageJson.version });
15
-
16
- output(created, (b) => `Saved a backup to ${b.path}`);
17
- },
18
- help: `Usage: zinn backup
19
-
20
- Save a copy of the database to ~/.zinn/backups/, or to backups/ in ZINN_DIR when it is set.
21
-
22
- The copy includes recent writes and is safe to take while Zinn is in use.
23
- Fails when there is no database yet. Existing backups are never overwritten.`,
24
- } satisfies Command;
@@ -1,171 +0,0 @@
1
- import type { CommentWithKey } from "@zinn-dev/core";
2
- import type { RowCell } from "../presentation/row-layout";
3
- import type { RouteDef } from "../types";
4
-
5
- import { parseArgs } from "node:util";
6
- import { comment } from "@zinn-dev/core";
7
-
8
- import {
9
- confirmAction,
10
- output,
11
- quit,
12
- validatePositionals,
13
- validateUniqueOptions,
14
- } from "../lib";
15
- import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
16
- import { currentActor } from "../actor";
17
- import { formatRows } from "../presentation/row-layout";
18
- import { formatLocalTime } from "../presentation/time";
19
-
20
- type PresentedComment = Pick<CommentWithKey, "key" | "text" | "created_at" | "updated_at">;
21
-
22
- function presentComment(commentMatch: CommentWithKey): PresentedComment {
23
- return {
24
- key: commentMatch.key,
25
- text: commentMatch.text,
26
- created_at: commentMatch.created_at,
27
- updated_at: commentMatch.updated_at,
28
- };
29
- }
30
-
31
- export function presentComments(taskKey: string) {
32
- return comment.getAll(taskKey).map(presentComment);
33
- }
34
-
35
- function commentRow(commentMatch: PresentedComment, options: { showsCreatedAt: boolean }) {
36
- const createdAtCells: Array<RowCell> = options.showsCreatedAt
37
- ? [{ text: formatLocalTime(commentMatch.created_at), style: "dim" }]
38
- : [];
39
-
40
- return [{ text: commentMatch.key }, ...createdAtCells, { text: commentMatch.text }];
41
- }
42
-
43
- export function formatComment(commentMatch: PresentedComment) {
44
- return formatRows([commentRow(commentMatch, { showsCreatedAt: false })], {
45
- indentsContinuationLines: true,
46
- });
47
- }
48
-
49
- export function formatComments(comments: Array<PresentedComment>) {
50
- return formatRows(
51
- comments.map((commentMatch) => commentRow(commentMatch, { showsCreatedAt: true })),
52
- { indentsContinuationLines: true },
53
- );
54
- }
55
-
56
- function parseTextArgs(args: Array<string>) {
57
- const { values, positionals, tokens } = parseArgs({
58
- args,
59
- options: { text: { type: "string" } },
60
- allowPositionals: true,
61
- strict: true,
62
- tokens: true,
63
- });
64
-
65
- validateUniqueOptions(tokens);
66
- validatePositionals(positionals, ["<task-key>"]);
67
-
68
- if (values.text === undefined) {
69
- quit("Comment text must be specified with --text");
70
- }
71
-
72
- return { key: positionals[0]!, text: values.text };
73
- }
74
-
75
- function parseCommentEditArgs(args: Array<string>) {
76
- const { values, positionals, tokens } = parseArgs({
77
- args,
78
- options: { text: { type: "string" }, ...textEditOptions },
79
- allowPositionals: true,
80
- strict: true,
81
- tokens: true,
82
- });
83
-
84
- validateUniqueOptions(tokens);
85
- validatePositionals(positionals, ["<comment-key>"]);
86
-
87
- const text = resolveTextEdit(values.text, values, "--text");
88
- if (text === undefined) {
89
- quit("Comment text must be specified with --text");
90
- }
91
-
92
- return { key: positionals[0]!, text };
93
- }
94
-
95
- export const commentRouter = {
96
- create: {
97
- run: (args) => {
98
- const props = parseTextArgs(args);
99
- const created = comment.create({ taskKey: props.key, text: props.text }, currentActor());
100
- output(presentComment(created), formatComment);
101
- },
102
- help: `Usage: zinn task comment create <task-key> --text <text>
103
-
104
- Add a comment to a task. Comment text cannot be blank.
105
- Archived tasks can be commented on.
106
-
107
- Example: zinn task comment create MDR-1 --text "Ready for review"`,
108
- },
109
- list: {
110
- run: (args) => {
111
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
112
- validatePositionals(positionals, ["<task-key>"]);
113
- output(presentComments(positionals[0]!), formatComments);
114
- },
115
- help: `Usage: zinn task comment list <task-key>
116
-
117
- List a task's comments by oldest first.
118
-
119
- Example: zinn task comment list MDR-1`,
120
- },
121
- edit: {
122
- run: (args) => {
123
- const props = parseCommentEditArgs(args);
124
- const edited = comment.edit({ commentKey: props.key, text: props.text }, currentActor());
125
- output(presentComment(edited), formatComment);
126
- },
127
- help: `Usage: zinn task comment edit <comment-key> --text <text> ${textEditUsage}
128
-
129
- Replace a comment's text. Comment text cannot be blank.
130
-
131
- ${textEditHelp("--text")}
132
-
133
- Examples:
134
- zinn task comment edit MDR-1#2 --text "Approved"
135
- zinn task comment edit MDR-1#2 --text "Also approved." --append`,
136
- },
137
- delete: {
138
- run: (args) => {
139
- const { values, positionals, tokens } = parseArgs({
140
- args,
141
- options: { yes: { type: "boolean" } },
142
- allowPositionals: true,
143
- strict: true,
144
- tokens: true,
145
- });
146
- validateUniqueOptions(tokens);
147
- validatePositionals(positionals, ["<comment-key>"]);
148
-
149
- const commentMatch = comment.getByKey(positionals[0]!);
150
- const canDelete = confirmAction(
151
- `Are you sure you want to delete ${commentMatch.key}?`,
152
- values.yes === true,
153
- );
154
- const presented = presentComment(commentMatch);
155
-
156
- if (!canDelete) {
157
- output(presented, (entry) => `Deletion cancelled for ${entry.key}`);
158
- return;
159
- }
160
-
161
- comment.delete({ commentKey: commentMatch.key }, currentActor());
162
- output(presented, (entry) => `Deleted ${entry.key}`);
163
- },
164
- help: `Usage: zinn task comment delete <comment-key> [--yes]
165
-
166
- Permanently delete a comment after confirmation.
167
- Use --yes to skip the confirmation prompt, for example in scripts or with --json.
168
-
169
- Example: zinn task comment delete MDR-1#2`,
170
- },
171
- } satisfies RouteDef;
@@ -1,168 +0,0 @@
1
- import type { Label } from "@zinn-dev/core";
2
- import type { RowCell } from "../presentation/row-layout";
3
- import type { RouteDef } from "../types";
4
-
5
- import { parseArgs } from "node:util";
6
- import { label, labelCreateSchema, labelDeleteSchema, labelEditSchema } from "@zinn-dev/core";
7
-
8
- import { confirmAction, output, quit, validatePositionals, validateUniqueOptions } from "../lib";
9
- import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
10
- import { currentActor } from "../actor";
11
- import { isColorEnabled } from "../presentation/color";
12
- import { formatRows } from "../presentation/row-layout";
13
-
14
- type PresentedLabel = Omit<Label, "id">;
15
-
16
- function presentLabel(labelMatch: Label): PresentedLabel {
17
- return { name: labelMatch.name, color: labelMatch.color, description: labelMatch.description };
18
- }
19
-
20
- function formatLabel(presented: PresentedLabel) {
21
- return formatLabelList([presented]);
22
- }
23
-
24
- function formatLabelList(presentedLabels: Array<PresentedLabel>) {
25
- return formatRows(
26
- presentedLabels.map((presented) => {
27
- const descriptionCells: Array<RowCell> =
28
- presented.description == null ? [] : [{ text: presented.description }];
29
-
30
- /**
31
- * The colored name shows the color, and if the environment
32
- * does not support color, it is explicitly printed instead
33
- */
34
- if (isColorEnabled()) {
35
- return [{ text: presented.name, style: presented.color }, ...descriptionCells];
36
- }
37
-
38
- return [{ text: presented.name }, { text: presented.color }, ...descriptionCells];
39
- }),
40
- );
41
- }
42
-
43
- export const labelRouter = {
44
- create: {
45
- run: (args) => {
46
- const { values, positionals, tokens } = parseArgs({
47
- args,
48
- options: { description: { type: "string" }, color: { type: "string" } },
49
- allowPositionals: true,
50
- strict: true,
51
- tokens: true,
52
- });
53
-
54
- validateUniqueOptions(tokens);
55
- validatePositionals(positionals, ["<name>"]);
56
-
57
- const input = labelCreateSchema.parse({ name: positionals[0], ...values });
58
- const created = label.create(input, currentActor());
59
-
60
- output(presentLabel(created), formatLabel);
61
- },
62
- help: `Usage: zinn label create <name> [--description <text>] [--color <color>]
63
-
64
- Create a global label. Names preserve casing, but uniqueness is case-insensitive.
65
- Names are trimmed and cannot be blank or contain line breaks or control characters.
66
- Description is optional.
67
-
68
- Color defaults to white.
69
- Valid colors: red, green, yellow, blue, magenta, cyan, white, gray.
70
-
71
- Example: zinn label create bug --description "Unexpected behavior" --color red`,
72
- },
73
- list: {
74
- run: (args) => {
75
- const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
76
- validatePositionals(positionals, []);
77
-
78
- output(label.getAll().map(presentLabel), formatLabelList);
79
- },
80
- help: `Usage: zinn label list
81
-
82
- List all global label definitions.`,
83
- },
84
- edit: {
85
- run: (args) => {
86
- const { values, positionals, tokens } = parseArgs({
87
- args,
88
- options: {
89
- name: { type: "string" },
90
- description: { type: "string" },
91
- ...textEditOptions,
92
- color: { type: "string" },
93
- },
94
- allowPositionals: true,
95
- strict: true,
96
- tokens: true,
97
- });
98
-
99
- validateUniqueOptions(tokens);
100
- validatePositionals(positionals, ["<name>"]);
101
-
102
- const input = labelEditSchema.parse({
103
- labelName: positionals[0],
104
- name: values.name,
105
- description: resolveTextEdit(values.description, values, "--description"),
106
- color: values.color,
107
- });
108
- const edited = label.edit(input, currentActor());
109
-
110
- output(presentLabel(edited), formatLabel);
111
- },
112
- help: `Usage: zinn label edit <name> [--name <text>] [--description <text> ${textEditUsage}] [--color <color>]
113
-
114
- Change specified fields.
115
- Provide at least one edit flag. Use --description "" to clear the description.
116
-
117
- ${textEditHelp("--description")}
118
-
119
- Names are matched and kept unique case-insensitively while preserving their casing.
120
- Names are trimmed. Changing only the casing is allowed.
121
- Editing does not affect task attachments or task timestamps.
122
-
123
- Examples:
124
- zinn label edit bug --name defect --color yellow
125
- zinn label edit bug --description "Reported by users." --append`,
126
- },
127
- delete: {
128
- run: (args) => {
129
- const { values, positionals, tokens } = parseArgs({
130
- args,
131
- options: { yes: { type: "boolean" } },
132
- strict: true,
133
- allowPositionals: true,
134
- tokens: true,
135
- });
136
-
137
- validateUniqueOptions(tokens);
138
- validatePositionals(positionals, ["<name>"]);
139
-
140
- const props = labelDeleteSchema.parse({ name: positionals[0] });
141
- const labelMatch = label.getByName(props.name);
142
-
143
- if (labelMatch == null) {
144
- quit(`A label with name "${props.name}" does not exist`);
145
- }
146
-
147
- const canDelete = confirmAction(
148
- `Are you sure you want to delete label "${labelMatch.name}" and remove it from all tasks?`,
149
- values.yes === true,
150
- );
151
-
152
- if (!canDelete) {
153
- output(presentLabel(labelMatch), (l) => `Deletion cancelled for label "${l.name}"`);
154
- return;
155
- }
156
-
157
- const deleted = label.delete(props, currentActor());
158
- output(presentLabel(deleted), (l) => `Deleted label "${l.name}"`);
159
- },
160
- help: `Usage: zinn label delete <name> [--yes]
161
-
162
- Delete a label definition and remove it from all tasks after confirmation.
163
- To remove a label from just one task, use zinn task label remove.
164
- Label names are matched case-insensitively.
165
-
166
- Use --yes to skip the confirmation prompt, for example in scripts or with --json.`,
167
- },
168
- } satisfies RouteDef;
@@ -1,31 +0,0 @@
1
- import { expect, spyOn, test } from "bun:test";
2
- import { migrate, getStorage } from "@zinn-dev/core";
3
-
4
- import { migrateCommand } from "./migrate-router";
5
-
6
- // ? The shipped migration list is empty, so the CLI cannot reach an older database yet.
7
- // ? Making the core call fail stands in for any failure of an upgrade, since the line
8
- // ? on stderr does not depend on the stage that failed.
9
- test("a failed upgrade names the backup folder on stderr and rethrows the original error", () => {
10
- const failure = new Error("migration broke");
11
- const run = spyOn(migrate, "run").mockImplementation(() => {
12
- throw failure;
13
- });
14
- const stderr = spyOn(console, "error").mockImplementation(() => {});
15
-
16
- try {
17
- expect(() => migrateCommand.run([])).toThrow(failure);
18
- expect(stderr.mock.calls).toEqual([
19
- [
20
- `The database is unchanged. Backups taken before each upgrade attempt are kept in ${getStorage().backupDirectory}.`,
21
- ],
22
- ]);
23
- } finally {
24
- run.mockRestore();
25
- stderr.mockRestore();
26
- }
27
- });
28
-
29
- test("the backup folder is inside the isolated test directory", () => {
30
- expect(getStorage().backupDirectory.startsWith(process.env.ZINN_DIR!)).toBe(true);
31
- });
@@ -1,48 +0,0 @@
1
- import type { Command } from "../types";
2
-
3
- import { parseArgs } from "node:util";
4
- import { migrate, MigrationRefusedError, getStorage } from "@zinn-dev/core";
5
-
6
- import { reportLockWait } from "../database";
7
- import { output, validatePositionals } from "../lib";
8
- import packageJson from "../../package.json";
9
-
10
- export const migrateCommand = {
11
- run: (args) => {
12
- const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
13
- validatePositionals(positionals, []);
14
-
15
- // Resolved before the try, so a store that cannot be resolved fails without the note about backups.
16
- const { backupDirectory } = getStorage();
17
-
18
- try {
19
- const result = migrate.run({
20
- client: "cli",
21
- version: packageJson.version,
22
- onWait: reportLockWait,
23
- });
24
-
25
- output(result, (r) =>
26
- r.changed
27
- ? `Upgraded the database from schema version ${r.previousVersion} to ${r.finalVersion}. A backup was saved to ${r.backupPath}`
28
- : `The database is already at schema version ${r.finalVersion}`,
29
- );
30
- } catch (error) {
31
- // A refusal attempted nothing, so only a failed upgrade points at the backups.
32
- if (!(error instanceof MigrationRefusedError)) {
33
- console.error(
34
- `The database is unchanged. Backups taken before each upgrade attempt are kept in ${backupDirectory}.`,
35
- );
36
- }
37
-
38
- throw error;
39
- }
40
- },
41
- help: `Usage: zinn migrate
42
-
43
- Upgrade an existing database to the latest schema version.
44
-
45
- A backup is saved first, in the same place as \`zinn backup\`, and the upgrade is applied completely or not at all.
46
- Does nothing when the database is already up to date.
47
- Fails, leaving the database as it is, when there is no database with data yet, when it has no schema version, or when it is newer than this Zinn.`,
48
- } satisfies Command;