@zinn-dev/cli 0.37.0 → 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,4 +1,4 @@
1
- import type { TaskChange } from "@zinn-dev/core";
1
+ import type { TaskChange, TaskRelationType } from "@zinn-dev/core";
2
2
  import type { RouteDef } from "../types";
3
3
  import type { PresentedTask } from "../presentation/task-presentation";
4
4
 
@@ -10,9 +10,11 @@ import {
10
10
  failureMessage,
11
11
  output,
12
12
  quit,
13
- validatePositionalCount,
13
+ UsageError,
14
+ validatePositionals,
14
15
  validateUniqueOptions,
15
16
  } from "../lib";
17
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
16
18
  import { formatRelations, presentRelations, relationRouter } from "./relation-router";
17
19
  import { commentRouter, formatComments, presentComments } from "./comment-router";
18
20
  import { currentActor } from "../actor";
@@ -34,24 +36,23 @@ export const taskRouter = {
34
36
  description: { type: "string" },
35
37
  priority: { type: "string" },
36
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 },
37
44
  },
38
45
  allowPositionals: true,
39
46
  strict: true,
40
47
  tokens: true,
41
48
  });
42
- const projectKey = positionals[0];
43
- if (projectKey == null) {
44
- quit("A task needs to belong to a project");
45
- }
46
- validatePositionalCount(
47
- positionals,
48
- 1,
49
- "Only one project key can be specified; use --title and --description",
50
- );
49
+ validateUniqueOptions(tokens, ["label", "depends-on", "related"]);
50
+ validatePositionals(positionals, ["<project-key>"]);
51
+
52
+ const projectKey = positionals[0]!;
51
53
  if (values.title === undefined) {
52
54
  quit("A task needs at least a title: use --title");
53
55
  }
54
- validateUniqueOptions(tokens, ["label"]);
55
56
  const projectMatch = project.getByKey(projectKey);
56
57
  if (projectMatch == null) {
57
58
  quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist`);
@@ -63,20 +64,31 @@ export const taskRouter = {
63
64
  description: values.description ?? null,
64
65
  priority: parsePriority(values.priority),
65
66
  labelNames: values.label,
67
+ columnName: values.column,
68
+ relations: parseNewTaskRelations(values),
66
69
  },
67
70
  currentActor(),
68
71
  );
69
72
  output(presentTask(createdTask), formatTaskRow);
70
73
  },
71
- 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>]
72
75
 
73
- 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.
74
78
  Priority defaults to none (unassigned).
75
79
  Repeat --label to attach multiple existing labels. Unknown labels are errors.
76
80
  Label names are matched case-insensitively.
77
- 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.
78
87
 
79
- 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`,
80
92
  },
81
93
  list: {
82
94
  run: (args) => {
@@ -86,6 +98,7 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
86
98
  archived: { type: "boolean" },
87
99
  all: { type: "boolean" },
88
100
  label: { type: "string", multiple: true },
101
+ column: { type: "string" },
89
102
  },
90
103
  allowPositionals: true,
91
104
  strict: true,
@@ -93,30 +106,33 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
93
106
  });
94
107
 
95
108
  validateUniqueOptions(tokens, ["label"]);
109
+ validatePositionals(positionals, ["[<project-key>]"]);
96
110
 
97
111
  if (values.archived && values.all) {
98
112
  quit('Use either "--archived" or "--all", not both');
99
113
  }
100
114
 
101
115
  const projectKey = positionals[0];
102
-
103
- if (positionals.length > 1) {
104
- quit("Only one project key can be specified");
105
- }
106
-
107
116
  const archive = values.all ? "all" : values.archived ? "archived" : "active";
108
117
 
109
- 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
+ });
110
124
 
111
125
  output(tasks.map(presentTask), (presentedTasks) =>
112
126
  formatTaskList(presentedTasks, { showsStatus: values.all }),
113
127
  );
114
128
  },
115
- 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>]
116
130
 
117
131
  List active tasks by default.
118
132
  Use --archived to list archived tasks or --all to list both.
119
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.
120
136
 
121
137
  Each row shows a task's key, column, priority marker, title, and labels. --all adds an Active or Archived status after the key.
122
138
  Priority markers: - unassigned, L low, M medium, H high, U urgent.
@@ -139,17 +155,11 @@ Example: zinn task list MDR --label cli`,
139
155
  tokens: true,
140
156
  });
141
157
 
142
- const [query, projectKey] = positionals;
143
-
144
- if (query == null) {
145
- quit("A search query must be specified");
146
- }
147
-
148
- if (positionals.length > 2) {
149
- quit("Only one query and one project key can be specified; quote multi-word queries");
150
- }
151
-
152
158
  validateUniqueOptions(tokens, ["label"]);
159
+ validatePositionals(positionals, ["<query>", "[<project-key>]"]);
160
+
161
+ const query = positionals[0]!;
162
+ const projectKey = positionals[1];
153
163
 
154
164
  if (values.archived && values.all) {
155
165
  quit('Use either "--archived" or "--all", not both');
@@ -197,19 +207,14 @@ Use --limit to show at most <n> results.
197
207
  Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
198
208
  A search result's output matches that of 'task list'.
199
209
 
200
- Use -- before a query that begins with a dash.
201
-
202
210
  Example: zinn task search "refinement quota" MDR --limit 5`,
203
211
  },
204
212
  view: {
205
213
  run: (args) => {
206
- const taskKey = args[0];
207
-
208
- if (taskKey == null) {
209
- quit("Task key must be specified");
210
- }
214
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
215
+ validatePositionals(positionals, ["<task-key>"]);
211
216
 
212
- const taskMatch = task.getByKey(taskKey);
217
+ const taskMatch = task.getByKey(positionals[0]!);
213
218
  const viewedTask = {
214
219
  ...presentTask(taskMatch),
215
220
  relations: presentRelations(taskMatch),
@@ -228,7 +233,9 @@ Example: zinn task search "refinement quota" MDR --limit 5`,
228
233
  const relations = formatRelations(t.relations);
229
234
  const comments = formatComments(t.comments);
230
235
  const isArchived = t.status === "Archived";
231
- const sections = [formatTaskList([t], { showsStatus: isArchived })];
236
+ const sections = [
237
+ formatTaskList([t], { showsStatus: isArchived, showsFullPriority: true }),
238
+ ];
232
239
 
233
240
  if (t.description != null) {
234
241
  sections.push(formatSection("Description", t.description, sectionOptions));
@@ -259,6 +266,7 @@ Example: zinn task view MDR-1`,
259
266
  options: {
260
267
  title: { type: "string" },
261
268
  description: { type: "string" },
269
+ ...textEditOptions,
262
270
  priority: { type: "string" },
263
271
  "add-label": { type: "string", multiple: true },
264
272
  "remove-label": { type: "string", multiple: true },
@@ -268,19 +276,15 @@ Example: zinn task view MDR-1`,
268
276
  tokens: true,
269
277
  });
270
278
 
271
- const taskKey = positionals[0];
272
-
273
- if (taskKey == null) {
274
- quit("Task key must be specified");
275
- }
276
-
277
- validatePositionalCount(positionals, 1, "Only one task key can be specified");
278
-
279
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");
280
284
 
281
285
  const hasEditFlags =
282
286
  values.title !== undefined ||
283
- values.description !== undefined ||
287
+ description !== undefined ||
284
288
  values.priority !== undefined ||
285
289
  values["add-label"] !== undefined ||
286
290
  values["remove-label"] !== undefined;
@@ -295,7 +299,7 @@ Example: zinn task view MDR-1`,
295
299
  {
296
300
  taskKey,
297
301
  title: values.title,
298
- description: values.description,
302
+ description,
299
303
  priority: parsePriority(values.priority),
300
304
  addLabelNames: values["add-label"],
301
305
  removeLabelNames: values["remove-label"],
@@ -305,38 +309,35 @@ Example: zinn task view MDR-1`,
305
309
 
306
310
  output(presentTask(editedTask), formatTaskRow);
307
311
  },
308
- 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>]
309
313
 
310
314
  Edit a task's title, description, priority, or label attachments.
311
315
  Use --priority none to clear priority.
312
316
  Provide at least one edit flag. Use --description "" to clear the description.
313
317
 
318
+ ${textEditHelp("--description")}
319
+
314
320
  Repeat --add-label or --remove-label for multiple existing labels.
315
321
  Label names are matched case-insensitively.
316
322
  Adding an attached label or removing an unattached label does not do anything.
317
323
  Archived tasks can be edited.
318
324
 
319
325
  The same label cannot be both added and removed.
320
- Titles cannot be blank.
326
+ Titles are trimmed and cannot be blank or contain line breaks or control characters.
321
327
 
322
328
  Use --title="--example" for text beginning with a dash.
323
329
 
324
- 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`,
325
333
  },
326
334
  move: {
327
335
  run: (args) => {
328
336
  const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
329
- const taskKeys = positionals.slice(0, -1);
330
- const targetColumn = positionals.at(-1);
331
-
332
- if (targetColumn == null) {
333
- quit("Task key must be specified");
334
- }
335
-
336
- if (taskKeys.length === 0) {
337
- quit("Target column must be specified");
338
- }
337
+ validatePositionals(positionals, ["<task-key>...", "<target-column>"]);
339
338
 
339
+ const taskKeys = positionals.slice(0, -1);
340
+ const targetColumn = positionals.at(-1)!;
340
341
  const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
341
342
  outputTaskChanges(
342
343
  moves,
@@ -362,28 +363,26 @@ Example: zinn task move MDR-1 MDR-2 "In Progress"`,
362
363
  },
363
364
  order: {
364
365
  run: (args) => {
365
- const [taskKey, direction, targetTaskKey, ...extraArgs] = args;
366
-
367
- if (taskKey == null) {
368
- quit("Task key must be specified");
369
- }
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);
370
373
 
371
- if (direction == null) {
372
- quit("Order direction must be specified");
373
- }
374
+ const taskKey = positionals[0]!;
375
+ const direction = positionals[1]!;
374
376
 
375
377
  switch (direction) {
376
378
  case "before":
377
379
  case "after": {
378
- if (targetTaskKey == null) {
379
- quit(`Target task must be specified for "${direction}"`);
380
- }
381
-
382
- if (extraArgs.length > 0) {
383
- quit("Only one target task can be specified");
384
- }
380
+ validatePositionals(positionals, [...leadingWords, "<target-task-key>"]);
385
381
 
386
- const orderedTask = task.order({ taskKey, direction, targetTaskKey }, currentActor());
382
+ const orderedTask = task.order(
383
+ { taskKey, direction, targetTaskKey: positionals[2]! },
384
+ currentActor(),
385
+ );
387
386
  output(presentTask(orderedTask), formatTaskRow);
388
387
  return;
389
388
  }
@@ -391,16 +390,14 @@ Example: zinn task move MDR-1 MDR-2 "In Progress"`,
391
390
  case "up":
392
391
  case "down":
393
392
  case "bottom": {
394
- if (targetTaskKey != null) {
395
- quit(`Order direction "${direction}" does not accept a target task`);
396
- }
393
+ validatePositionals(positionals, leadingWords);
397
394
 
398
395
  const orderedTask = task.order({ taskKey, direction }, currentActor());
399
396
  output(presentTask(orderedTask), formatTaskRow);
400
397
  return;
401
398
  }
402
399
  default:
403
- quit(`Unknown order direction "${direction}"`);
400
+ throw new UsageError(`Unknown order direction "${direction}"`);
404
401
  }
405
402
  },
406
403
  help: `Usage: zinn task order <task-key> {top|up|down|bottom}
@@ -456,17 +453,17 @@ Example: zinn task unarchive MDR-1 MDR-2`,
456
453
  },
457
454
  delete: {
458
455
  run: (args: Array<string>) => {
459
- const { values, positionals } = parseArgs({
456
+ const { values, positionals, tokens } = parseArgs({
460
457
  args,
461
458
  options: { yes: { type: "boolean" } },
462
459
  allowPositionals: true,
463
460
  strict: true,
461
+ tokens: true,
464
462
  });
465
- const taskKey = positionals[0];
463
+ validateUniqueOptions(tokens);
464
+ validatePositionals(positionals, ["<task-key>"]);
466
465
 
467
- if (taskKey == null) {
468
- quit("Task key must be specified");
469
- }
466
+ const taskKey = positionals[0]!;
470
467
 
471
468
  try {
472
469
  const taskMatch = task.getByKey(taskKey);
@@ -520,10 +517,7 @@ Remove existing labels from a task. Label names are matched case-insensitively.`
520
517
 
521
518
  function parseTaskKeys(args: Array<string>) {
522
519
  const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
523
-
524
- if (positionals.length === 0) {
525
- quit("Task key must be specified");
526
- }
520
+ validatePositionals(positionals, ["<task-key>..."]);
527
521
 
528
522
  return positionals;
529
523
  }
@@ -557,12 +551,32 @@ function outputTaskChanges(
557
551
 
558
552
  function parseTaskLabelArgs(args: string[]) {
559
553
  const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
560
- if (positionals.length < 2) {
561
- quit("Provide a task key and at least one label name");
562
- }
554
+ validatePositionals(positionals, ["<task-key>", "<label-name>..."]);
555
+
563
556
  return { taskKey: positionals[0]!, labelNames: positionals.slice(1) };
564
557
  }
565
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
+
566
580
  function parsePriority(value: string | undefined) {
567
581
  switch (value) {
568
582
  case undefined:
@@ -0,0 +1,68 @@
1
+ import type { TextEdit } from "@zinn-dev/core";
2
+
3
+ import { quit } from "./lib";
4
+
5
+ /** The flags that change how a text flag (--description, --text) is applied to the stored text. */
6
+ export const textEditOptions = {
7
+ append: { type: "boolean" },
8
+ replacing: { type: "string" },
9
+ all: { type: "boolean" },
10
+ } as const;
11
+
12
+ type TextEditFlags = {
13
+ append?: boolean | undefined;
14
+ replacing?: string | undefined;
15
+ all?: boolean | undefined;
16
+ };
17
+
18
+ /** The usage form of the text-edit flags, to follow the text flag in a usage line. */
19
+ export const textEditUsage = "[--append|--replacing <old> [--all]]";
20
+
21
+ /** Help paragraph for the text-edit flags of a command whose text flag is `textFlag`. */
22
+ export function textEditHelp(textFlag: "--description" | "--text") {
23
+ return `With --append, the ${textFlag} text is added as a new paragraph.
24
+ With --replacing <old>, it replaces the one exact, case-sensitive match of <old>
25
+ --all replaces every match.
26
+
27
+ No match, or several matches without --all, fails without changing anything.
28
+ An empty ${textFlag} with --replacing deletes the match.`;
29
+ }
30
+
31
+ /** The value to send to core for a text flag: the full text, or one edit object. */
32
+ export function resolveTextEdit(
33
+ text: string | undefined,
34
+ flags: TextEditFlags,
35
+ textFlag: "--description" | "--text",
36
+ ): string | TextEdit | undefined {
37
+ const isAppending = flags.append === true;
38
+ const isReplacing = flags.replacing !== undefined;
39
+
40
+ if (isAppending && isReplacing) {
41
+ quit(`Option "--append" cannot be used with "--replacing"`);
42
+ }
43
+
44
+ if ((isAppending || isReplacing) && text === undefined) {
45
+ const modifier = isAppending ? "--append" : "--replacing";
46
+ quit(`Option "${modifier}" needs "${textFlag}"`);
47
+ }
48
+
49
+ if (flags.all === true && !isReplacing) {
50
+ quit(`Option "--all" needs "--replacing"`);
51
+ }
52
+
53
+ if (text === undefined) {
54
+ return undefined;
55
+ }
56
+
57
+ if (isAppending) {
58
+ return { append: text };
59
+ }
60
+
61
+ if (flags.replacing !== undefined) {
62
+ return flags.all === true
63
+ ? { find: flags.replacing, replace: text, all: true }
64
+ : { find: flags.replacing, replace: text };
65
+ }
66
+
67
+ return text;
68
+ }