@zinn-dev/cli 0.36.1 → 0.38.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.
@@ -1,28 +1,31 @@
1
+ import type { TaskChange, TaskRelationType } from "@zinn-dev/core";
1
2
  import type { RouteDef } from "../types";
3
+ import type { PresentedTask } from "../presentation/task-presentation";
2
4
 
3
5
  import { parseArgs } from "node:util";
4
6
  import { task, project, positiveIntegerPattern, searchLimitMessage } from "@zinn-dev/core";
5
7
 
6
8
  import {
7
9
  confirmAction,
10
+ failureMessage,
8
11
  output,
9
12
  quit,
10
- validatePositionalCount,
13
+ UsageError,
14
+ validatePositionals,
11
15
  validateUniqueOptions,
12
16
  } from "../lib";
17
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
13
18
  import { formatRelations, presentRelations, relationRouter } from "./relation-router";
14
19
  import { commentRouter, formatComments, presentComments } from "./comment-router";
15
20
  import { currentActor } from "../actor";
21
+ import { formatSection } from "../presentation/section";
16
22
  import {
17
- formatTask,
18
23
  formatTaskList,
19
- formatTaskMove,
20
- formatTaskWithStatus,
24
+ formatTaskListWithStatus,
25
+ formatTaskRow,
21
26
  presentTask,
22
27
  } from "../presentation/task-presentation";
23
28
 
24
- const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
25
-
26
29
  export const taskRouter = {
27
30
  create: {
28
31
  run: (args) => {
@@ -33,24 +36,23 @@ export const taskRouter = {
33
36
  description: { type: "string" },
34
37
  priority: { type: "string" },
35
38
  label: { type: "string", multiple: true },
39
+ column: { type: "string" },
40
+ parent: { type: "string" },
41
+ "depends-on": { type: "string", multiple: true },
42
+ "duplicate-of": { type: "string" },
43
+ related: { type: "string", multiple: true },
36
44
  },
37
45
  allowPositionals: true,
38
46
  strict: true,
39
47
  tokens: true,
40
48
  });
41
- const projectKey = positionals[0];
42
- if (projectKey == null) {
43
- quit("A task needs to belong to a project");
44
- }
45
- validatePositionalCount(
46
- positionals,
47
- 1,
48
- "Only one project key can be specified; use --title and --description",
49
- );
49
+ validateUniqueOptions(tokens, ["label", "depends-on", "related"]);
50
+ validatePositionals(positionals, ["<project-key>"]);
51
+
52
+ const projectKey = positionals[0]!;
50
53
  if (values.title === undefined) {
51
54
  quit("A task needs at least a title: use --title");
52
55
  }
53
- validateUniqueOptions(tokens, ["label"]);
54
56
  const projectMatch = project.getByKey(projectKey);
55
57
  if (projectMatch == null) {
56
58
  quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist`);
@@ -62,20 +64,31 @@ export const taskRouter = {
62
64
  description: values.description ?? null,
63
65
  priority: parsePriority(values.priority),
64
66
  labelNames: values.label,
67
+ columnName: values.column,
68
+ relations: parseNewTaskRelations(values),
65
69
  },
66
70
  currentActor(),
67
71
  );
68
- output(presentTask(createdTask), formatTask);
72
+ output(presentTask(createdTask), formatTaskRow);
69
73
  },
70
- help: `Usage: zinn task create <project-key> --title <text> [--description <text>] [--priority {low|medium|high|urgent|none}] [--label <name>]
74
+ 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>]
71
75
 
72
- Create a task in the project's first column.
76
+ Create a task at the bottom of a column. Without --column, it starts in the project's first column.
77
+ Column names are matched case-insensitively. An unknown column is an error and creates nothing.
73
78
  Priority defaults to none (unassigned).
74
79
  Repeat --label to attach multiple existing labels. Unknown labels are errors.
75
80
  Label names are matched case-insensitively.
76
- Titles cannot be blank. Use --title="--example" for text beginning with a dash.
81
+ Titles are trimmed and cannot be blank or contain line breaks or control characters. Use --title="--example" for text beginning with a dash.
82
+
83
+ Relations are set from the new task's perspective: it becomes a subtask of --parent, depends on --depends-on,
84
+ is a duplicate of --duplicate-of, and is related to --related.
85
+ Repeat --depends-on and --related to name several tasks.
86
+ A target task that does not exist causes an error, and task creation is aborted.
77
87
 
78
- Example: zinn task create MDR --title "Refine the numbers" --description "Meet the quarterly quota" --label urgent`,
88
+ Examples:
89
+ zinn task create MDR --title "Refine the numbers" --description "Meet the quarterly quota" --label urgent
90
+ zinn task create MDR --title "Review the numbers" --column "In Progress"
91
+ zinn task create MDR --title "Sort the files" --parent MDR-1 --depends-on MDR-2`,
79
92
  },
80
93
  list: {
81
94
  run: (args) => {
@@ -85,6 +98,7 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
85
98
  archived: { type: "boolean" },
86
99
  all: { type: "boolean" },
87
100
  label: { type: "string", multiple: true },
101
+ column: { type: "string" },
88
102
  },
89
103
  allowPositionals: true,
90
104
  strict: true,
@@ -92,31 +106,37 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
92
106
  });
93
107
 
94
108
  validateUniqueOptions(tokens, ["label"]);
109
+ validatePositionals(positionals, ["[<project-key>]"]);
95
110
 
96
111
  if (values.archived && values.all) {
97
112
  quit('Use either "--archived" or "--all", not both');
98
113
  }
99
114
 
100
115
  const projectKey = positionals[0];
101
-
102
- if (positionals.length > 1) {
103
- quit("Only one project key can be specified");
104
- }
105
-
106
116
  const archive = values.all ? "all" : values.archived ? "archived" : "active";
107
117
 
108
- const tasks = task.getAll({ projectKey, archive, labelNames: values.label });
118
+ const tasks = task.getAll({
119
+ projectKey,
120
+ archive,
121
+ labelNames: values.label,
122
+ columnName: values.column,
123
+ });
109
124
 
110
125
  output(tasks.map(presentTask), (presentedTasks) =>
111
126
  formatTaskList(presentedTasks, { showsStatus: values.all }),
112
127
  );
113
128
  },
114
- help: `Usage: zinn task list [<project-key>] [--archived|--all] [--label <name>]
129
+ help: `Usage: zinn task list [<project-key>] [--archived|--all] [--label <name>] [--column <name>]
115
130
 
116
131
  List active tasks by default.
117
132
  Use --archived to list archived tasks or --all to list both.
118
133
  Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
134
+ Use --column to filter by an exact column name without case sensitivty.
135
+ Column, label and archive filters can be combined together. No matches print nothing, or return [] for --json, and exit successfully.
136
+
137
+ Each row shows a task's key, column, priority marker, title, and labels. --all adds an Active or Archived status after the key.
119
138
  Priority markers: - unassigned, L low, M medium, H high, U urgent.
139
+ Use 'task view' to see a task's full details, including its description.
120
140
 
121
141
  Example: zinn task list MDR --label cli`,
122
142
  },
@@ -135,23 +155,18 @@ Example: zinn task list MDR --label cli`,
135
155
  tokens: true,
136
156
  });
137
157
 
138
- const [query, projectKey] = positionals;
139
-
140
- if (query == null) {
141
- quit("A search query must be specified");
142
- }
143
-
144
- if (positionals.length > 2) {
145
- quit("Only one query and one project key can be specified; quote multi-word queries");
146
- }
147
-
148
158
  validateUniqueOptions(tokens, ["label"]);
159
+ validatePositionals(positionals, ["<query>", "[<project-key>]"]);
160
+
161
+ const query = positionals[0]!;
162
+ const projectKey = positionals[1];
149
163
 
150
164
  if (values.archived && values.all) {
151
165
  quit('Use either "--archived" or "--all", not both');
152
166
  }
153
167
 
154
168
  const archive = values.all ? "all" : values.archived ? "archived" : "active";
169
+ const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
155
170
 
156
171
  if (values.limit !== undefined && !limitPattern.test(values.limit)) {
157
172
  quit(searchLimitMessage);
@@ -192,19 +207,14 @@ Use --limit to show at most <n> results.
192
207
  Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
193
208
  A search result's output matches that of 'task list'.
194
209
 
195
- Use -- before a query that begins with a dash.
196
-
197
210
  Example: zinn task search "refinement quota" MDR --limit 5`,
198
211
  },
199
212
  view: {
200
213
  run: (args) => {
201
- const taskKey = args[0];
214
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
215
+ validatePositionals(positionals, ["<task-key>"]);
202
216
 
203
- if (taskKey == null) {
204
- quit("Task key must be specified");
205
- }
206
-
207
- const taskMatch = task.getByKey(taskKey);
217
+ const taskMatch = task.getByKey(positionals[0]!);
208
218
  const viewedTask = {
209
219
  ...presentTask(taskMatch),
210
220
  relations: presentRelations(taskMatch),
@@ -212,17 +222,31 @@ Example: zinn task search "refinement quota" MDR --limit 5`,
212
222
  };
213
223
 
214
224
  output(viewedTask, (t) => {
225
+ const MIN_SECTION_SEPARATOR_WIDTH = 60;
226
+
227
+ const terminalWidth = process.stdout.columns;
228
+ const hasTerminalWidth = process.stdout.isTTY === true && terminalWidth > 0;
229
+
230
+ const sectionOptions = {
231
+ separatorWidth: hasTerminalWidth ? terminalWidth : MIN_SECTION_SEPARATOR_WIDTH,
232
+ };
215
233
  const relations = formatRelations(t.relations);
216
234
  const comments = formatComments(t.comments);
217
- const formattedTask = formatTask(t);
218
- const sections = [formattedTask];
235
+ const isArchived = t.status === "Archived";
236
+ const sections = [
237
+ formatTaskList([t], { showsStatus: isArchived, showsFullPriority: true }),
238
+ ];
239
+
240
+ if (t.description != null) {
241
+ sections.push(formatSection("Description", t.description, sectionOptions));
242
+ }
219
243
 
220
244
  if (relations.length > 0) {
221
- sections.push(`Relations:\n${relations}`);
245
+ sections.push(formatSection("Relations", relations, sectionOptions));
222
246
  }
223
247
 
224
248
  if (comments.length > 0) {
225
- sections.push(`Comments:\n${comments}`);
249
+ sections.push(formatSection("Comments", comments, sectionOptions));
226
250
  }
227
251
 
228
252
  return sections.join("\n\n");
@@ -230,7 +254,8 @@ Example: zinn task search "refinement quota" MDR --limit 5`,
230
254
  },
231
255
  help: `Usage: zinn task view <task-key>
232
256
 
233
- Show a task with its current column, description, priority, labels, relations, and comments.
257
+ Show a task with its description, relations, and comments.
258
+ A section is shown when the task has that content. The description prints in full, keeping its line breaks.
234
259
 
235
260
  Example: zinn task view MDR-1`,
236
261
  },
@@ -241,6 +266,7 @@ Example: zinn task view MDR-1`,
241
266
  options: {
242
267
  title: { type: "string" },
243
268
  description: { type: "string" },
269
+ ...textEditOptions,
244
270
  priority: { type: "string" },
245
271
  "add-label": { type: "string", multiple: true },
246
272
  "remove-label": { type: "string", multiple: true },
@@ -250,19 +276,15 @@ Example: zinn task view MDR-1`,
250
276
  tokens: true,
251
277
  });
252
278
 
253
- const taskKey = positionals[0];
254
-
255
- if (taskKey == null) {
256
- quit("Task key must be specified");
257
- }
258
-
259
- validatePositionalCount(positionals, 1, "Only one task key can be specified");
260
-
261
279
  validateUniqueOptions(tokens, ["add-label", "remove-label"]);
280
+ validatePositionals(positionals, ["<task-key>"]);
281
+
282
+ const taskKey = positionals[0]!;
283
+ const description = resolveTextEdit(values.description, values, "--description");
262
284
 
263
285
  const hasEditFlags =
264
286
  values.title !== undefined ||
265
- values.description !== undefined ||
287
+ description !== undefined ||
266
288
  values.priority !== undefined ||
267
289
  values["add-label"] !== undefined ||
268
290
  values["remove-label"] !== undefined;
@@ -277,7 +299,7 @@ Example: zinn task view MDR-1`,
277
299
  {
278
300
  taskKey,
279
301
  title: values.title,
280
- description: values.description,
302
+ description,
281
303
  priority: parsePriority(values.priority),
282
304
  addLabelNames: values["add-label"],
283
305
  removeLabelNames: values["remove-label"],
@@ -285,95 +307,97 @@ Example: zinn task view MDR-1`,
285
307
  currentActor(),
286
308
  );
287
309
 
288
- output(presentTask(editedTask), formatTask);
310
+ output(presentTask(editedTask), formatTaskRow);
289
311
  },
290
- help: `Usage: zinn task edit <task-key> [--title <text>] [--description <text>] [--priority {low|medium|high|urgent|none}] [--add-label <name>] [--remove-label <name>]
312
+ help: `Usage: zinn task edit <task-key> [--title <text>] [--description <text> ${textEditUsage}] [--priority {low|medium|high|urgent|none}] [--add-label <name>] [--remove-label <name>]
291
313
 
292
- Change the supplied fields and preserve everything else.
314
+ Edit a task's title, description, priority, or label attachments.
293
315
  Use --priority none to clear priority.
294
316
  Provide at least one edit flag. Use --description "" to clear the description.
295
317
 
318
+ ${textEditHelp("--description")}
319
+
296
320
  Repeat --add-label or --remove-label for multiple existing labels.
297
321
  Label names are matched case-insensitively.
298
322
  Adding an attached label or removing an unattached label does not do anything.
299
- Archived tasks can be edited. Unchanged values leave the task unchanged.
323
+ Archived tasks can be edited.
300
324
 
301
325
  The same label cannot be both added and removed.
302
- Titles cannot be blank.
326
+ Titles are trimmed and cannot be blank or contain line breaks or control characters.
303
327
 
304
328
  Use --title="--example" for text beginning with a dash.
305
329
 
306
- Example: zinn task edit MDR-1 --title "Meet the quarterly refinement quota"`,
330
+ Examples:
331
+ zinn task edit MDR-1 --title "Meet the quarterly refinement quota"
332
+ zinn task edit MDR-1 --description "Bring waffles." --append`,
307
333
  },
308
334
  move: {
309
335
  run: (args) => {
310
- const [taskKey, targetColumn] = args;
311
-
312
- if (taskKey == null) {
313
- quit("Task key must be specified");
314
- }
315
-
316
- if (targetColumn == null) {
317
- quit("Target column must be specified");
318
- }
319
-
320
- const movedTask = task.move({ taskKey, targetColumn }, currentActor());
321
- output(presentTask(movedTask), formatTaskMove);
336
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
337
+ validatePositionals(positionals, ["<task-key>...", "<target-column>"]);
338
+
339
+ const taskKeys = positionals.slice(0, -1);
340
+ const targetColumn = positionals.at(-1)!;
341
+ const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
342
+ outputTaskChanges(
343
+ moves,
344
+ formatTaskList,
345
+ (movedTask) => `${movedTask.key} was already in the ${movedTask.column} column`,
346
+ );
322
347
  },
323
- help: `Usage: zinn task move <task-key> <target-column>
348
+ help: `Usage: zinn task move <task-key>... <target-column>
324
349
 
325
- Move a task to another column in its project.
350
+ Move tasks to another column in their projects.
326
351
  Moving a task to a different column lists it last in that column,
327
352
  matching placement at the bottom of a visual kanban column.
353
+ Several tasks are moved in the order given, and each task's column is looked up in its own project.
328
354
 
329
- Prints the task's key and new column.
330
-
331
- Giving a task's current column as the target will not do anything.
355
+ Giving a task's current column as the target will not do anything, and a note says so.
332
356
  Archived tasks must be unarchived before they can be moved.
357
+ On bulk changes, if any task cannot be moved, the bulk operation is aborted.
333
358
 
334
- Example: zinn task move MDR-1 "In Progress"`,
359
+ With --json, one task prints an object and several print an array.
360
+ Each task's changed field is 'false' when it was already in the requested state.
361
+
362
+ Example: zinn task move MDR-1 MDR-2 "In Progress"`,
335
363
  },
336
364
  order: {
337
365
  run: (args) => {
338
- const [taskKey, direction, targetTaskKey, ...extraArgs] = args;
339
-
340
- if (taskKey == null) {
341
- quit("Task key must be specified");
342
- }
366
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
367
+ /**
368
+ * The words every direction needs. Only whether they are there is checked here,
369
+ * since the direction decides whether a target task follows.
370
+ */
371
+ const leadingWords = ["<task-key>", "{top|up|down|bottom|before|after}"];
372
+ validatePositionals(positionals.slice(0, leadingWords.length), leadingWords);
343
373
 
344
- if (direction == null) {
345
- quit("Order direction must be specified");
346
- }
374
+ const taskKey = positionals[0]!;
375
+ const direction = positionals[1]!;
347
376
 
348
377
  switch (direction) {
349
378
  case "before":
350
379
  case "after": {
351
- if (targetTaskKey == null) {
352
- quit(`Target task must be specified for "${direction}"`);
353
- }
380
+ validatePositionals(positionals, [...leadingWords, "<target-task-key>"]);
354
381
 
355
- if (extraArgs.length > 0) {
356
- quit("Only one target task can be specified");
357
- }
358
-
359
- const orderedTask = task.order({ taskKey, direction, targetTaskKey }, currentActor());
360
- output(presentTask(orderedTask), formatTask);
382
+ const orderedTask = task.order(
383
+ { taskKey, direction, targetTaskKey: positionals[2]! },
384
+ currentActor(),
385
+ );
386
+ output(presentTask(orderedTask), formatTaskRow);
361
387
  return;
362
388
  }
363
389
  case "top":
364
390
  case "up":
365
391
  case "down":
366
392
  case "bottom": {
367
- if (targetTaskKey != null) {
368
- quit(`Order direction "${direction}" does not accept a target task`);
369
- }
393
+ validatePositionals(positionals, leadingWords);
370
394
 
371
395
  const orderedTask = task.order({ taskKey, direction }, currentActor());
372
- output(presentTask(orderedTask), formatTask);
396
+ output(presentTask(orderedTask), formatTaskRow);
373
397
  return;
374
398
  }
375
399
  default:
376
- quit(`Unknown order direction "${direction}"`);
400
+ throw new UsageError(`Unknown order direction "${direction}"`);
377
401
  }
378
402
  },
379
403
  help: `Usage: zinn task order <task-key> {top|up|down|bottom}
@@ -387,51 +411,59 @@ Example: zinn task order MDR-2 before MDR-1`,
387
411
  },
388
412
  archive: {
389
413
  run: (args: Array<string>) => {
390
- const taskKey = args[0];
391
-
392
- if (taskKey == null) {
393
- quit("Task key must be specified");
394
- }
395
-
396
- const archivedTask = task.archive(taskKey, currentActor());
397
- output(presentTask(archivedTask), formatTaskWithStatus);
414
+ const taskKeys = parseTaskKeys(args);
415
+ const archives = task.archiveMany(taskKeys, currentActor());
416
+ outputTaskChanges(
417
+ archives,
418
+ formatTaskListWithStatus,
419
+ (archivedTask) => `${archivedTask.key} was already archived`,
420
+ );
398
421
  },
399
- help: `Usage: zinn task archive <task-key>
422
+ help: `Usage: zinn task archive <task-key>...
400
423
 
401
- Archive a task so it no longer appears in active task lists.
424
+ Archive tasks so they no longer appear in active task lists.
425
+ Archiving an archived task does not do anything.
426
+ On bulk changes, if any task cannot be archived, the bulk operation is aborted.
402
427
 
403
- Example: zinn task archive MDR-1`,
428
+ With --json, one task prints an object and several print an array.
429
+ Each task's changed field is 'false' when it was already in the requested state.
430
+
431
+ Example: zinn task archive MDR-1 MDR-2`,
404
432
  },
405
433
  unarchive: {
406
434
  run: (args: Array<string>) => {
407
- const taskKey = args[0];
408
-
409
- if (taskKey == null) {
410
- quit("Task key must be specified");
411
- }
412
-
413
- const unarchivedTask = task.unarchive(taskKey, currentActor());
414
- output(presentTask(unarchivedTask), formatTaskWithStatus);
435
+ const taskKeys = parseTaskKeys(args);
436
+ const unarchives = task.unarchiveMany(taskKeys, currentActor());
437
+ outputTaskChanges(
438
+ unarchives,
439
+ formatTaskListWithStatus,
440
+ (unarchivedTask) => `${unarchivedTask.key} was already active`,
441
+ );
415
442
  },
416
- help: `Usage: zinn task unarchive <task-key>
443
+ help: `Usage: zinn task unarchive <task-key>...
444
+
445
+ Unarchive tasks at the bottom of their previous columns, in the order given.
446
+ Unarchiving an active task does not do anything.
447
+ On bulk changes, if any task cannot be unarchived, the bulk operation is aborted.
417
448
 
418
- Unarchive a task at the bottom of its previous column.
449
+ With --json, one task prints an object and several print an array.
450
+ Each task's changed field is 'false' when it was already in the requested state.
419
451
 
420
- Example: zinn task unarchive MDR-1`,
452
+ Example: zinn task unarchive MDR-1 MDR-2`,
421
453
  },
422
454
  delete: {
423
455
  run: (args: Array<string>) => {
424
- const { values, positionals } = parseArgs({
456
+ const { values, positionals, tokens } = parseArgs({
425
457
  args,
426
458
  options: { yes: { type: "boolean" } },
427
459
  allowPositionals: true,
428
460
  strict: true,
461
+ tokens: true,
429
462
  });
430
- const taskKey = positionals[0];
463
+ validateUniqueOptions(tokens);
464
+ validatePositionals(positionals, ["<task-key>"]);
431
465
 
432
- if (taskKey == null) {
433
- quit("Task key must be specified");
434
- }
466
+ const taskKey = positionals[0]!;
435
467
 
436
468
  try {
437
469
  const taskMatch = task.getByKey(taskKey);
@@ -443,12 +475,12 @@ Example: zinn task unarchive MDR-1`,
443
475
 
444
476
  if (canDelete) {
445
477
  task.delete(taskKey, currentActor());
446
- output(presented, (t) => `Deleted ${formatTask(t)}`);
478
+ output(presented, (t) => `Deleted ${formatTaskRow(t)}`);
447
479
  } else {
448
- output(presented, (t) => `Deletion cancelled for ${formatTask(t)}`);
480
+ output(presented, (t) => `Deletion cancelled for ${formatTaskRow(t)}`);
449
481
  }
450
482
  } catch (err: any) {
451
- quit(err?.message ?? "Something went wrong");
483
+ quit(failureMessage(err, "Something went wrong"));
452
484
  }
453
485
  },
454
486
  help: `Usage: zinn task delete <task-key> [--yes]
@@ -464,7 +496,7 @@ Example: zinn task delete MDR-1`,
464
496
  add: {
465
497
  run: (args) => {
466
498
  const props = parseTaskLabelArgs(args);
467
- output(presentTask(task.label.add(props, currentActor())), formatTask);
499
+ output(presentTask(task.label.add(props, currentActor())), formatTaskRow);
468
500
  },
469
501
  help: `Usage: zinn task label add <task-key> <label-name>...
470
502
 
@@ -474,7 +506,7 @@ Already attached labels are unchanged.`,
474
506
  remove: {
475
507
  run: (args) => {
476
508
  const props = parseTaskLabelArgs(args);
477
- output(presentTask(task.label.remove(props, currentActor())), formatTask);
509
+ output(presentTask(task.label.remove(props, currentActor())), formatTaskRow);
478
510
  },
479
511
  help: `Usage: zinn task label remove <task-key> <label-name>...
480
512
 
@@ -483,14 +515,68 @@ Remove existing labels from a task. Label names are matched case-insensitively.`
483
515
  },
484
516
  } satisfies RouteDef;
485
517
 
518
+ function parseTaskKeys(args: Array<string>) {
519
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
520
+ validatePositionals(positionals, ["<task-key>..."]);
521
+
522
+ return positionals;
523
+ }
524
+
525
+ /**
526
+ * Prints the changed tasks as rows, or as JSON: an object for one task and an array for several.
527
+ * JSON includes each task's `changed` flag, and each unchanged task also gets a note on stderr.
528
+ */
529
+ function outputTaskChanges(
530
+ changes: Array<TaskChange>,
531
+ formatTasks: (presentedTasks: Array<PresentedTask>) => string,
532
+ describeUnchanged: (presentedTask: PresentedTask) => string,
533
+ ) {
534
+ const presentedChanges = changes.map((change) => ({
535
+ ...presentTask(change.task),
536
+ changed: change.changed,
537
+ }));
538
+
539
+ if (presentedChanges.length === 1) {
540
+ output(presentedChanges[0]!, (presentedChange) => formatTasks([presentedChange]));
541
+ } else {
542
+ output(presentedChanges, formatTasks);
543
+ }
544
+
545
+ for (const presentedChange of presentedChanges) {
546
+ if (!presentedChange.changed) {
547
+ console.error(describeUnchanged(presentedChange));
548
+ }
549
+ }
550
+ }
551
+
486
552
  function parseTaskLabelArgs(args: string[]) {
487
553
  const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
488
- if (positionals.length < 2) {
489
- quit("Provide a task key and at least one label name");
490
- }
554
+ validatePositionals(positionals, ["<task-key>", "<label-name>..."]);
555
+
491
556
  return { taskKey: positionals[0]!, labelNames: positionals.slice(1) };
492
557
  }
493
558
 
559
+ type NewTaskRelationFlags = {
560
+ parent?: string;
561
+ "depends-on"?: Array<string>;
562
+ "duplicate-of"?: string;
563
+ related?: Array<string>;
564
+ };
565
+
566
+ // The new task is the source of each relation, so a flag names the type from its point of view.
567
+ function parseNewTaskRelations(flags: NewTaskRelationFlags) {
568
+ const targetsByType: Array<[TaskRelationType, Array<string>]> = [
569
+ ["subtask", flags.parent === undefined ? [] : [flags.parent]],
570
+ ["dependency", flags["depends-on"] ?? []],
571
+ ["duplicate", flags["duplicate-of"] === undefined ? [] : [flags["duplicate-of"]]],
572
+ ["related", flags.related ?? []],
573
+ ];
574
+
575
+ return targetsByType.flatMap(([relation_type, targetTaskKeys]) =>
576
+ targetTaskKeys.map((targetTaskKey) => ({ relation_type, targetTaskKey })),
577
+ );
578
+ }
579
+
494
580
  function parsePriority(value: string | undefined) {
495
581
  switch (value) {
496
582
  case undefined: