@zinn-dev/cli 0.39.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 (93) hide show
  1. package/README.md +5 -2
  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.ts → activity-router.js} +36 -46
  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 -159
  67. package/src/presentation/activity-presentation.test.ts +0 -112
  68. package/src/presentation/activity-presentation.ts +0 -490
  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/project.test.ts +0 -479
  77. package/src/project.ts +0 -53
  78. package/src/routes/backup-router.ts +0 -24
  79. package/src/routes/comment-router.ts +0 -171
  80. package/src/routes/label-router.ts +0 -168
  81. package/src/routes/migrate-router.test.ts +0 -31
  82. package/src/routes/migrate-router.ts +0 -48
  83. package/src/routes/project-router.ts +0 -415
  84. package/src/routes/reindex-router.ts +0 -27
  85. package/src/routes/relation-router.ts +0 -194
  86. package/src/routes/restore-router.test.ts +0 -44
  87. package/src/routes/restore-router.ts +0 -90
  88. package/src/routes/router.test.ts +0 -136
  89. package/src/routes/router.ts +0 -248
  90. package/src/routes/routes.ts +0 -20
  91. package/src/routes/task-router.ts +0 -649
  92. package/src/text-edit.ts +0 -68
  93. package/src/types.ts +0 -6
@@ -0,0 +1,533 @@
1
+ import { parseArgs } from "node:util";
2
+ import { task, project, positiveIntegerPattern, searchLimitMessage, parseTaskKey, } from "@zinn-dev/core";
3
+ import { confirmAction, failureMessage, output, quit, UsageError, validatePositionals, validateUniqueOptions, } from "../lib.js";
4
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit.js";
5
+ import { formatRelations, presentRelations, relationRouter } from "./relation-router.js";
6
+ import { commentRouter, formatComments, presentComments } from "./comment-router.js";
7
+ import { currentActor } from "../actor.js";
8
+ import { resolveProjectKey } from "../project.js";
9
+ import { formatSection } from "../presentation/section.js";
10
+ import { formatActivityList, presentActivities } from "../presentation/activity-presentation.js";
11
+ import { formatTaskList, formatTaskListWithStatus, formatTaskRow, presentTask, } from "../presentation/task-presentation.js";
12
+ export const taskRouter = {
13
+ create: {
14
+ run: (args) => {
15
+ const { values, positionals, tokens } = parseArgs({
16
+ args,
17
+ options: {
18
+ title: { type: "string" },
19
+ description: { type: "string" },
20
+ priority: { type: "string" },
21
+ label: { type: "string", multiple: true },
22
+ column: { type: "string" },
23
+ parent: { type: "string" },
24
+ "depends-on": { type: "string", multiple: true },
25
+ "duplicate-of": { type: "string" },
26
+ related: { type: "string", multiple: true },
27
+ },
28
+ allowPositionals: true,
29
+ strict: true,
30
+ tokens: true,
31
+ });
32
+ validateUniqueOptions(tokens, ["label", "depends-on", "related"]);
33
+ validatePositionals(positionals, ["[<project-key>]"]);
34
+ const projectKey = resolveProjectKey(positionals[0], { required: true });
35
+ if (values.title === undefined) {
36
+ quit("A task needs at least a title: use --title");
37
+ }
38
+ const projectMatch = project.getByKey(projectKey);
39
+ if (projectMatch == null) {
40
+ quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist`);
41
+ }
42
+ const createdTask = task.create({
43
+ project_id: projectMatch.id,
44
+ title: values.title,
45
+ description: values.description ?? null,
46
+ priority: parsePriority(values.priority),
47
+ labelNames: values.label,
48
+ columnName: values.column,
49
+ relations: parseNewTaskRelations(values),
50
+ }, currentActor());
51
+ output(presentTask(createdTask), formatTaskRow);
52
+ },
53
+ help: `Usage: zinn task create [<project-key>] --title <text> [--description <text>] [--priority {low|medium|high|urgent|none}] [--label <name>]... [--column <name>] [--parent <task-key>] [--depends-on <task-key>]... [--duplicate-of <task-key>] [--related <task-key>]...
54
+
55
+ Create a task at the bottom of a column. Without --column, it starts in the project's first column.
56
+
57
+ An omitted project key uses defaultProject from settings, if present.
58
+ If no default project is set, the key is required.
59
+
60
+ Column names are matched case-insensitively. An unknown column is an error and creates nothing.
61
+ Priority defaults to none (unassigned).
62
+ Repeat --label to attach multiple existing labels. Unknown labels are errors.
63
+ Label names are matched case-insensitively.
64
+ Titles are trimmed and cannot be blank or contain line breaks or control characters. Use --title="--example" for text beginning with a dash.
65
+
66
+ Relations are set from the new task's perspective: it becomes a subtask of --parent, depends on --depends-on,
67
+ is a duplicate of --duplicate-of, and is related to --related.
68
+ Repeat --depends-on and --related to name several tasks.
69
+ A target task that does not exist causes an error, and task creation is aborted.
70
+
71
+ Examples:
72
+ zinn task create MDR --title "Refine the numbers" --description "Meet the quarterly quota" --label urgent
73
+ zinn task create MDR --title "Review the numbers" --column "In Progress"
74
+ zinn task create MDR --title "Sort the files" --parent MDR-1 --depends-on MDR-2`,
75
+ },
76
+ list: {
77
+ run: (args) => {
78
+ const { values, positionals, tokens } = parseArgs({
79
+ args,
80
+ options: {
81
+ archived: { type: "boolean" },
82
+ all: { type: "boolean" },
83
+ "all-projects": { type: "boolean" },
84
+ label: { type: "string", multiple: true },
85
+ column: { type: "string" },
86
+ },
87
+ allowPositionals: true,
88
+ strict: true,
89
+ tokens: true,
90
+ });
91
+ validateUniqueOptions(tokens, ["label"]);
92
+ validatePositionals(positionals, ["[<project-key>]"]);
93
+ if (values.archived && values.all) {
94
+ quit('Use either "--archived" or "--all", not both');
95
+ }
96
+ const projectKey = resolveProjectKey(positionals[0], { allProjects: values["all-projects"] });
97
+ const archive = values.all ? "all" : values.archived ? "archived" : "active";
98
+ const tasks = task.getAll({
99
+ projectKey,
100
+ archive,
101
+ labelNames: values.label,
102
+ columnName: values.column,
103
+ });
104
+ output(tasks.map(presentTask), (presentedTasks) => formatTaskList(presentedTasks, { showsStatus: values.all }));
105
+ },
106
+ help: `Usage: zinn task list [<project-key>|--all-projects] [--archived|--all] [--label <name>]... [--column <name>]
107
+
108
+ List active tasks by default.
109
+ An omitted project key uses defaultProject from settings, if present.
110
+ If no default project is set, the command lists every project.
111
+ Use --all-projects to list every project, overriding the default. It cannot be combined with a typed project key.
112
+ Use --archived to list archived tasks or --all to list both.
113
+ Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
114
+ Use --column to filter by an exact column name without case sensitivty.
115
+ Column, label and archive filters can be combined together. No matches print nothing, or return [] for --json, and exit successfully.
116
+
117
+ Each row shows a task's key, column, priority marker, title, and labels. --all adds an Active or Archived status after the key.
118
+ Priority markers: - unassigned, L low, M medium, H high, U urgent.
119
+ Use 'task view' to see a task's full details, including its description.
120
+
121
+ Example: zinn task list MDR --label cli`,
122
+ },
123
+ search: {
124
+ run: (args) => {
125
+ const { values, positionals, tokens } = parseArgs({
126
+ args,
127
+ options: {
128
+ archived: { type: "boolean" },
129
+ all: { type: "boolean" },
130
+ "all-projects": { type: "boolean" },
131
+ limit: { type: "string" },
132
+ label: { type: "string", multiple: true },
133
+ },
134
+ allowPositionals: true,
135
+ strict: true,
136
+ tokens: true,
137
+ });
138
+ validateUniqueOptions(tokens, ["label"]);
139
+ validatePositionals(positionals, ["<query>", "[<project-key>]"]);
140
+ const query = positionals[0];
141
+ if (values.archived && values.all) {
142
+ quit('Use either "--archived" or "--all", not both');
143
+ }
144
+ const archive = values.all ? "all" : values.archived ? "archived" : "active";
145
+ const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
146
+ if (values.limit !== undefined && !limitPattern.test(values.limit)) {
147
+ quit(searchLimitMessage);
148
+ }
149
+ const isTaskKeyQuery = parseTaskKey(query.trim()) !== null;
150
+ const projectKey = resolveProjectKey(positionals[1], {
151
+ allProjects: values["all-projects"],
152
+ useDefault: !isTaskKeyQuery,
153
+ });
154
+ const limit = values.limit === undefined ? undefined : Number(values.limit);
155
+ const result = task.search({
156
+ query,
157
+ projectKey,
158
+ archive,
159
+ limit,
160
+ labelNames: values.label,
161
+ });
162
+ output(result.tasks.map(presentTask), (presentedTasks) => formatTaskList(presentedTasks, { showsStatus: values.all }));
163
+ if (result.hiddenArchivedCount > 0) {
164
+ const count = result.hiddenArchivedCount;
165
+ const noun = count === 1 ? "match" : "matches";
166
+ console.error(`${count} archived ${noun} hidden, use --all to include them`);
167
+ }
168
+ },
169
+ help: `Usage: zinn task search <query> [<project-key>|--all-projects] [--archived|--all] [--limit <n>] [--label <name>]...
170
+
171
+ Search task titles, descriptions, and comments. A comment match lists the task it belongs to.
172
+ An omitted project key uses defaultProject from settings, if present.
173
+ If no default project is set, the command searches every project.
174
+ Use --all-projects to search every project, overriding the default. It cannot be combined with a typed project key.
175
+ Each word matches the start of a word, ignoring case and accents: e.g. "auth" finds "Authentication".
176
+ Every word must match. Quote a query with several words.
177
+
178
+ A query that is exactly a task key, such as MDR-1, lists that task first.
179
+ If given, a task key query overrides the configured default, and a typed project key still filters the search.
180
+ Other results are ordered by relevance, with title matches weighted highest.
181
+ Equally relevant tasks are ordered by project key, then task number.
182
+
183
+ By default, only active tasks are searched. Use --archived to search archived tasks or --all to search both.
184
+ When archived matches are hidden, a note is printed to say how many.
185
+ Use --limit to show at most <n> results.
186
+ Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
187
+ A search result's output matches that of 'task list'.
188
+
189
+ Example: zinn task search "refinement quota" MDR --limit 5`,
190
+ },
191
+ view: {
192
+ run: (args) => {
193
+ const { values, positionals, tokens } = parseArgs({
194
+ args,
195
+ options: { history: { type: "boolean" } },
196
+ allowPositionals: true,
197
+ strict: true,
198
+ tokens: true,
199
+ });
200
+ validateUniqueOptions(tokens);
201
+ validatePositionals(positionals, ["<task-key>"]);
202
+ const taskMatch = task.getByKey(positionals[0]);
203
+ const viewedTask = {
204
+ ...presentTask(taskMatch),
205
+ relations: presentRelations(taskMatch),
206
+ comments: presentComments(taskMatch.key),
207
+ ...(values.history === true
208
+ ? {
209
+ activity: task
210
+ .activity(taskMatch.key)
211
+ .sort((left, right) => right.created_at - left.created_at || right.id.localeCompare(left.id)),
212
+ }
213
+ : {}),
214
+ };
215
+ output(viewedTask, (t) => {
216
+ const MIN_SECTION_SEPARATOR_WIDTH = 60;
217
+ const terminalWidth = process.stdout.columns;
218
+ const hasTerminalWidth = process.stdout.isTTY === true && terminalWidth > 0;
219
+ const sectionOptions = {
220
+ separatorWidth: hasTerminalWidth ? terminalWidth : MIN_SECTION_SEPARATOR_WIDTH,
221
+ };
222
+ const relations = formatRelations(t.relations);
223
+ const comments = formatComments(t.comments);
224
+ const isArchived = t.status === "Archived";
225
+ const sections = [
226
+ formatTaskList([t], { showsStatus: isArchived, showsFullPriority: true }),
227
+ ];
228
+ if (t.description != null) {
229
+ sections.push(formatSection("Description", t.description, sectionOptions));
230
+ }
231
+ if (relations.length > 0) {
232
+ sections.push(formatSection("Relations", relations, sectionOptions));
233
+ }
234
+ if (comments.length > 0) {
235
+ sections.push(formatSection("Comments", comments, sectionOptions));
236
+ }
237
+ if (t.activity !== undefined) {
238
+ const history = formatActivityList(presentActivities(t.activity));
239
+ if (history.length > 0) {
240
+ sections.push(formatSection("History", history, sectionOptions));
241
+ }
242
+ }
243
+ return sections.join("\n\n");
244
+ });
245
+ },
246
+ help: `Usage: zinn task view <task-key> [--history]
247
+
248
+ Show a task with its description, relations, and comments.
249
+ A section is shown when the task has that content. The description prints in full, keeping its line breaks.
250
+ Use --history to include this task's recorded activity, newest first, including reorders and comment changes.
251
+ Use activity view <activity-id> for full recorded changes. Text times are local with a UTC offset.
252
+ With --history --json, the activity field contains full activity records, or [] when none are recorded.
253
+ Without --history, JSON omits activity.
254
+
255
+ Examples:
256
+ zinn task view MDR-1
257
+ zinn task view MDR-1 --history`,
258
+ },
259
+ edit: {
260
+ run: (args) => {
261
+ const { values, positionals, tokens } = parseArgs({
262
+ args,
263
+ options: {
264
+ title: { type: "string" },
265
+ description: { type: "string" },
266
+ ...textEditOptions,
267
+ priority: { type: "string" },
268
+ "add-label": { type: "string", multiple: true },
269
+ "remove-label": { type: "string", multiple: true },
270
+ },
271
+ allowPositionals: true,
272
+ strict: true,
273
+ tokens: true,
274
+ });
275
+ validateUniqueOptions(tokens, ["add-label", "remove-label"]);
276
+ validatePositionals(positionals, ["<task-key>"]);
277
+ const taskKey = positionals[0];
278
+ const description = resolveTextEdit(values.description, values, "--description");
279
+ const hasEditFlags = values.title !== undefined ||
280
+ description !== undefined ||
281
+ values.priority !== undefined ||
282
+ values["add-label"] !== undefined ||
283
+ values["remove-label"] !== undefined;
284
+ if (!hasEditFlags) {
285
+ quit("Provide at least one edit flag: --title, --description, --priority, --add-label, or --remove-label");
286
+ }
287
+ const editedTask = task.edit({
288
+ taskKey,
289
+ title: values.title,
290
+ description,
291
+ priority: parsePriority(values.priority),
292
+ addLabelNames: values["add-label"],
293
+ removeLabelNames: values["remove-label"],
294
+ }, currentActor());
295
+ output(presentTask(editedTask), formatTaskRow);
296
+ },
297
+ help: `Usage: zinn task edit <task-key> [--title <text>] [--description <text> ${textEditUsage}] [--priority {low|medium|high|urgent|none}] [--add-label <name>]... [--remove-label <name>]...
298
+
299
+ Edit a task's title, description, priority, or label attachments.
300
+ Use --priority none to clear priority.
301
+ Provide at least one edit flag. Use --description "" to clear the description.
302
+
303
+ ${textEditHelp("--description")}
304
+
305
+ Repeat --add-label or --remove-label for multiple existing labels.
306
+ Label names are matched case-insensitively.
307
+ Adding an attached label or removing an unattached label does not do anything.
308
+ Archived tasks can be edited.
309
+
310
+ The same label cannot be both added and removed.
311
+ Titles are trimmed and cannot be blank or contain line breaks or control characters.
312
+
313
+ Use --title="--example" for text beginning with a dash.
314
+
315
+ Examples:
316
+ zinn task edit MDR-1 --title "Meet the quarterly refinement quota"
317
+ zinn task edit MDR-1 --description "Bring waffles." --append`,
318
+ },
319
+ move: {
320
+ run: (args) => {
321
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
322
+ validatePositionals(positionals, ["<task-key>...", "<target-column>"]);
323
+ const taskKeys = positionals.slice(0, -1);
324
+ const targetColumn = positionals.at(-1);
325
+ const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
326
+ outputTaskChanges(moves, formatTaskList, (movedTask) => `${movedTask.key} was already in the ${movedTask.column} column`);
327
+ },
328
+ help: `Usage: zinn task move <task-key>... <target-column>
329
+
330
+ Move tasks to another column in their projects.
331
+ Moving a task to a different column lists it last in that column,
332
+ matching placement at the bottom of a visual kanban column.
333
+ Several tasks are moved in the order given, and each task's column is looked up in its own project.
334
+
335
+ Giving a task's current column as the target will not do anything, and a note says so.
336
+ Archived tasks must be unarchived before they can be moved.
337
+ On bulk changes, if any task cannot be moved, the bulk operation is aborted.
338
+
339
+ With --json, one task prints an object and several print an array.
340
+ Each task's changed field is 'false' when it was already in the requested state.
341
+
342
+ Example: zinn task move MDR-1 MDR-2 "In Progress"`,
343
+ },
344
+ order: {
345
+ run: (args) => {
346
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
347
+ /**
348
+ * The words every direction needs. Only whether they are there is checked here,
349
+ * since the direction decides whether a target task follows.
350
+ */
351
+ const leadingWords = ["<task-key>", "{top|up|down|bottom|before|after}"];
352
+ validatePositionals(positionals.slice(0, leadingWords.length), leadingWords);
353
+ const taskKey = positionals[0];
354
+ const direction = positionals[1];
355
+ switch (direction) {
356
+ case "before":
357
+ case "after": {
358
+ validatePositionals(positionals, [...leadingWords, "<target-task-key>"]);
359
+ const orderedTask = task.order({ taskKey, direction, targetTaskKey: positionals[2] }, currentActor());
360
+ output(presentTask(orderedTask), formatTaskRow);
361
+ return;
362
+ }
363
+ case "top":
364
+ case "up":
365
+ case "down":
366
+ case "bottom": {
367
+ validatePositionals(positionals, leadingWords);
368
+ const orderedTask = task.order({ taskKey, direction }, currentActor());
369
+ output(presentTask(orderedTask), formatTaskRow);
370
+ return;
371
+ }
372
+ default:
373
+ throw new UsageError(`Unknown order direction "${direction}"`);
374
+ }
375
+ },
376
+ help: `Usage: zinn task order <task-key> {top|up|down|bottom}
377
+ zinn task order <task-key> {before|after} <target-task-key>
378
+
379
+ Change a task's position within its current column.
380
+ Use top or bottom for either end, up or down for one position,
381
+ or before or after to place it relative to another task.
382
+
383
+ Example: zinn task order MDR-2 before MDR-1`,
384
+ },
385
+ archive: {
386
+ run: (args) => {
387
+ const taskKeys = parseTaskKeys(args);
388
+ const archives = task.archiveMany(taskKeys, currentActor());
389
+ outputTaskChanges(archives, formatTaskListWithStatus, (archivedTask) => `${archivedTask.key} was already archived`);
390
+ },
391
+ help: `Usage: zinn task archive <task-key>...
392
+
393
+ Archive tasks so they no longer appear in active task lists.
394
+ Archiving an archived task does not do anything.
395
+ On bulk changes, if any task cannot be archived, the bulk operation is aborted.
396
+
397
+ With --json, one task prints an object and several print an array.
398
+ Each task's changed field is 'false' when it was already in the requested state.
399
+
400
+ Example: zinn task archive MDR-1 MDR-2`,
401
+ },
402
+ unarchive: {
403
+ run: (args) => {
404
+ const taskKeys = parseTaskKeys(args);
405
+ const unarchives = task.unarchiveMany(taskKeys, currentActor());
406
+ outputTaskChanges(unarchives, formatTaskListWithStatus, (unarchivedTask) => `${unarchivedTask.key} was already active`);
407
+ },
408
+ help: `Usage: zinn task unarchive <task-key>...
409
+
410
+ Unarchive tasks at the bottom of their previous columns, in the order given.
411
+ Unarchiving an active task does not do anything.
412
+ On bulk changes, if any task cannot be unarchived, the bulk operation is aborted.
413
+
414
+ With --json, one task prints an object and several print an array.
415
+ Each task's changed field is 'false' when it was already in the requested state.
416
+
417
+ Example: zinn task unarchive MDR-1 MDR-2`,
418
+ },
419
+ delete: {
420
+ run: async (args) => {
421
+ const { values, positionals, tokens } = parseArgs({
422
+ args,
423
+ options: { yes: { type: "boolean" } },
424
+ allowPositionals: true,
425
+ strict: true,
426
+ tokens: true,
427
+ });
428
+ validateUniqueOptions(tokens);
429
+ validatePositionals(positionals, ["<task-key>"]);
430
+ const taskKey = positionals[0];
431
+ try {
432
+ const taskMatch = task.getByKey(taskKey);
433
+ const canDelete = await confirmAction(`Are you sure you want to delete ${taskKey}?`, values.yes === true);
434
+ const presented = presentTask(taskMatch);
435
+ if (canDelete) {
436
+ task.delete(taskKey, currentActor());
437
+ output(presented, (t) => `Deleted ${formatTaskRow(t)}`);
438
+ }
439
+ else {
440
+ output(presented, (t) => `Deletion cancelled for ${formatTaskRow(t)}`);
441
+ }
442
+ }
443
+ catch (err) {
444
+ quit(failureMessage(err, "Something went wrong"));
445
+ }
446
+ },
447
+ help: `Usage: zinn task delete <task-key> [--yes]
448
+
449
+ Permanently delete a task after confirmation.
450
+ Use --yes to skip the confirmation prompt, for example in scripts or with --json.
451
+
452
+ Example: zinn task delete MDR-1`,
453
+ },
454
+ relation: relationRouter,
455
+ comment: commentRouter,
456
+ label: {
457
+ add: {
458
+ run: (args) => {
459
+ const props = parseTaskLabelArgs(args);
460
+ output(presentTask(task.label.add(props, currentActor())), formatTaskRow);
461
+ },
462
+ help: `Usage: zinn task label add <task-key> <label-name>...
463
+
464
+ Add existing labels to a task. Label names are matched case-insensitively.
465
+ Already attached labels are unchanged.`,
466
+ },
467
+ remove: {
468
+ run: (args) => {
469
+ const props = parseTaskLabelArgs(args);
470
+ output(presentTask(task.label.remove(props, currentActor())), formatTaskRow);
471
+ },
472
+ help: `Usage: zinn task label remove <task-key> <label-name>...
473
+
474
+ Remove existing labels from a task. Label names are matched case-insensitively.`,
475
+ },
476
+ },
477
+ };
478
+ function parseTaskKeys(args) {
479
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
480
+ validatePositionals(positionals, ["<task-key>..."]);
481
+ return positionals;
482
+ }
483
+ /**
484
+ * Prints the changed tasks as rows, or as JSON: an object for one task and an array for several.
485
+ * JSON includes each task's `changed` flag, and each unchanged task also gets a note on stderr.
486
+ */
487
+ function outputTaskChanges(changes, formatTasks, describeUnchanged) {
488
+ const presentedChanges = changes.map((change) => ({
489
+ ...presentTask(change.task),
490
+ changed: change.changed,
491
+ }));
492
+ if (presentedChanges.length === 1) {
493
+ output(presentedChanges[0], (presentedChange) => formatTasks([presentedChange]));
494
+ }
495
+ else {
496
+ output(presentedChanges, formatTasks);
497
+ }
498
+ for (const presentedChange of presentedChanges) {
499
+ if (!presentedChange.changed) {
500
+ console.error(describeUnchanged(presentedChange));
501
+ }
502
+ }
503
+ }
504
+ function parseTaskLabelArgs(args) {
505
+ const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
506
+ validatePositionals(positionals, ["<task-key>", "<label-name>..."]);
507
+ return { taskKey: positionals[0], labelNames: positionals.slice(1) };
508
+ }
509
+ // The new task is the source of each relation, so a flag names the type from its point of view.
510
+ function parseNewTaskRelations(flags) {
511
+ const targetsByType = [
512
+ ["subtask", flags.parent === undefined ? [] : [flags.parent]],
513
+ ["dependency", flags["depends-on"] ?? []],
514
+ ["duplicate", flags["duplicate-of"] === undefined ? [] : [flags["duplicate-of"]]],
515
+ ["related", flags.related ?? []],
516
+ ];
517
+ return targetsByType.flatMap(([relation_type, targetTaskKeys]) => targetTaskKeys.map((targetTaskKey) => ({ relation_type, targetTaskKey })));
518
+ }
519
+ function parsePriority(value) {
520
+ switch (value) {
521
+ case undefined:
522
+ return undefined;
523
+ case "none":
524
+ return null;
525
+ case "low":
526
+ case "medium":
527
+ case "high":
528
+ case "urgent":
529
+ return value;
530
+ default:
531
+ quit("Priority must be low, medium, high, urgent, or none");
532
+ }
533
+ }
@@ -0,0 +1,25 @@
1
+ import type { TextEdit } from "@zinn-dev/core";
2
+ /** The flags that change how a text flag (--description, --text) is applied to the stored text. */
3
+ export declare const textEditOptions: {
4
+ readonly append: {
5
+ readonly type: "boolean";
6
+ };
7
+ readonly replacing: {
8
+ readonly type: "string";
9
+ };
10
+ readonly all: {
11
+ readonly type: "boolean";
12
+ };
13
+ };
14
+ type TextEditFlags = {
15
+ append?: boolean | undefined;
16
+ replacing?: string | undefined;
17
+ all?: boolean | undefined;
18
+ };
19
+ /** The usage form of the text-edit flags, to follow the text flag in a usage line. */
20
+ export declare const textEditUsage = "[--append|--replacing <old> [--all]]";
21
+ /** Help paragraph for the text-edit flags of a command whose text flag is `textFlag`. */
22
+ export declare function textEditHelp(textFlag: "--description" | "--text"): string;
23
+ /** The value to send to core for a text flag: the full text, or one edit object. */
24
+ export declare function resolveTextEdit(text: string | undefined, flags: TextEditFlags, textFlag: "--description" | "--text"): string | TextEdit | undefined;
25
+ export {};
@@ -0,0 +1,45 @@
1
+ import { quit } from "./lib.js";
2
+ /** The flags that change how a text flag (--description, --text) is applied to the stored text. */
3
+ export const textEditOptions = {
4
+ append: { type: "boolean" },
5
+ replacing: { type: "string" },
6
+ all: { type: "boolean" },
7
+ };
8
+ /** The usage form of the text-edit flags, to follow the text flag in a usage line. */
9
+ export const textEditUsage = "[--append|--replacing <old> [--all]]";
10
+ /** Help paragraph for the text-edit flags of a command whose text flag is `textFlag`. */
11
+ export function textEditHelp(textFlag) {
12
+ return `With --append, the ${textFlag} text is added as a new paragraph.
13
+ With --replacing <old>, it replaces the one exact, case-sensitive match of <old>
14
+ --all replaces every match.
15
+
16
+ No match, or several matches without --all, fails without changing anything.
17
+ An empty ${textFlag} with --replacing deletes the match.`;
18
+ }
19
+ /** The value to send to core for a text flag: the full text, or one edit object. */
20
+ export function resolveTextEdit(text, flags, textFlag) {
21
+ const isAppending = flags.append === true;
22
+ const isReplacing = flags.replacing !== undefined;
23
+ if (isAppending && isReplacing) {
24
+ quit(`Option "--append" cannot be used with "--replacing"`);
25
+ }
26
+ if ((isAppending || isReplacing) && text === undefined) {
27
+ const modifier = isAppending ? "--append" : "--replacing";
28
+ quit(`Option "${modifier}" needs "${textFlag}"`);
29
+ }
30
+ if (flags.all === true && !isReplacing) {
31
+ quit(`Option "--all" needs "--replacing"`);
32
+ }
33
+ if (text === undefined) {
34
+ return undefined;
35
+ }
36
+ if (isAppending) {
37
+ return { append: text };
38
+ }
39
+ if (flags.replacing !== undefined) {
40
+ return flags.all === true
41
+ ? { find: flags.replacing, replace: text, all: true }
42
+ : { find: flags.replacing, replace: text };
43
+ }
44
+ return text;
45
+ }
package/src/types.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export type Command = {
2
+ run: (args: Array<string>) => void | Promise<void>;
3
+ help: string;
4
+ };
5
+ export type ParsedRoute = {
6
+ command: string;
7
+ } & Command;
8
+ export type RouteDef = {
9
+ [key: string]: Command | RouteDef;
10
+ };
package/src/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/index.ts DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import packageJson from "./package.json";
4
-
5
- const args = process.argv.slice(2);
6
- const isVersionRequest = args.length === 1 && ["-v", "--version"].includes(args[0]!);
7
-
8
- if (isVersionRequest) {
9
- console.info(packageJson.version);
10
- } else {
11
- const { isHelpFlag } = await import("./src/lib");
12
- const { createRouter } = await import("./src/routes/router");
13
- const { routes } = await import("./src/routes/routes");
14
- const router = createRouter(routes);
15
-
16
- if (args.length === 0 || isHelpFlag(args[0]!)) {
17
- console.info(router.help);
18
- } else {
19
- const { configureDatabase } = await import("@zinn-dev/core");
20
- const { cliOpenPolicy } = await import("./src/database");
21
-
22
- // Only records the policy. core then opens the database when a command first uses it.
23
- configureDatabase(cliOpenPolicy());
24
- router.route(args);
25
- }
26
- }
@@ -1 +0,0 @@
1
- {"release":"published"}