@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.
- package/README.md +47 -9
- package/index.d.ts +2 -0
- package/index.js +23 -0
- package/package.json +22 -18
- package/src/actor.d.ts +6 -0
- package/src/actor.js +62 -0
- package/src/database.d.ts +6 -0
- package/src/database.js +27 -0
- package/src/lib.d.ts +31 -0
- package/src/lib.js +137 -0
- package/src/presentation/activity-presentation.d.ts +23 -0
- package/src/presentation/activity-presentation.js +389 -0
- package/src/presentation/color.d.ts +9 -0
- package/src/presentation/color.js +21 -0
- package/src/presentation/column-presentation.d.ts +16 -0
- package/src/presentation/column-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +3 -0
- package/src/presentation/description-presentation.js +11 -0
- package/src/presentation/row-layout.d.ts +22 -0
- package/src/presentation/row-layout.js +58 -0
- package/src/presentation/section.d.ts +4 -0
- package/src/presentation/section.js +9 -0
- package/src/presentation/task-presentation.d.ts +17 -0
- package/src/presentation/task-presentation.js +62 -0
- package/src/presentation/time.d.ts +1 -0
- package/src/presentation/time.js +13 -0
- package/src/project.d.ts +6 -0
- package/src/project.js +31 -0
- package/src/release-identity.d.ts +2 -0
- package/src/release-identity.js +1 -0
- package/src/routes/activity-router.d.ts +10 -0
- package/src/routes/activity-router.js +71 -0
- package/src/routes/backup-router.d.ts +4 -0
- package/src/routes/backup-router.js +18 -0
- package/src/routes/comment-router.d.ts +24 -0
- package/src/routes/comment-router.js +134 -0
- package/src/routes/label-router.d.ts +18 -0
- package/src/routes/label-router.js +136 -0
- package/src/routes/migrate-router.d.ts +4 -0
- package/src/routes/migrate-router.js +37 -0
- package/src/routes/project-router.d.ts +40 -0
- package/src/routes/project-router.js +328 -0
- package/src/routes/reindex-router.d.ts +4 -0
- package/src/routes/reindex-router.js +21 -0
- package/src/routes/relation-router.d.ts +28 -0
- package/src/routes/relation-router.js +163 -0
- package/src/routes/restore-router.d.ts +4 -0
- package/src/routes/restore-router.js +71 -0
- package/src/routes/router.d.ts +6 -0
- package/src/routes/router.js +185 -0
- package/src/routes/routes.d.ts +170 -0
- package/src/routes/routes.js +19 -0
- package/src/routes/task-router.d.ts +84 -0
- package/src/routes/task-router.js +533 -0
- package/src/text-edit.d.ts +25 -0
- package/src/text-edit.js +45 -0
- package/src/types.d.ts +10 -0
- package/src/types.js +1 -0
- package/index.ts +0 -26
- package/release-stamp.json +0 -1
- package/src/actor.test.ts +0 -41
- package/src/actor.ts +0 -78
- package/src/database.test.ts +0 -70
- package/src/database.ts +0 -41
- package/src/lib.test.ts +0 -86
- package/src/lib.ts +0 -145
- package/src/presentation/activity-presentation.test.ts +0 -71
- package/src/presentation/activity-presentation.ts +0 -489
- package/src/presentation/color.ts +0 -29
- package/src/presentation/column-presentation.ts +0 -48
- package/src/presentation/description-presentation.ts +0 -18
- package/src/presentation/row-layout.ts +0 -77
- package/src/presentation/section.ts +0 -16
- package/src/presentation/task-presentation.ts +0 -92
- package/src/presentation/time.ts +0 -17
- package/src/routes/activity-router.ts +0 -77
- package/src/routes/backup-router.ts +0 -24
- package/src/routes/comment-router.ts +0 -171
- package/src/routes/label-router.ts +0 -168
- package/src/routes/migrate-router.test.ts +0 -31
- package/src/routes/migrate-router.ts +0 -48
- package/src/routes/project-router.ts +0 -387
- package/src/routes/reindex-router.ts +0 -27
- package/src/routes/relation-router.ts +0 -194
- package/src/routes/restore-router.test.ts +0 -44
- package/src/routes/restore-router.ts +0 -90
- package/src/routes/router.test.ts +0 -136
- package/src/routes/router.ts +0 -248
- package/src/routes/routes.ts +0 -20
- package/src/routes/task-router.ts +0 -594
- package/src/text-edit.ts +0 -68
- package/src/types.ts +0 -6
|
@@ -1,594 +0,0 @@
|
|
|
1
|
-
import type { TaskChange, TaskRelationType } from "@zinn-dev/core";
|
|
2
|
-
import type { RouteDef } from "../types";
|
|
3
|
-
import type { PresentedTask } from "../presentation/task-presentation";
|
|
4
|
-
|
|
5
|
-
import { parseArgs } from "node:util";
|
|
6
|
-
import { task, project, positiveIntegerPattern, searchLimitMessage } from "@zinn-dev/core";
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
confirmAction,
|
|
10
|
-
failureMessage,
|
|
11
|
-
output,
|
|
12
|
-
quit,
|
|
13
|
-
UsageError,
|
|
14
|
-
validatePositionals,
|
|
15
|
-
validateUniqueOptions,
|
|
16
|
-
} from "../lib";
|
|
17
|
-
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
|
|
18
|
-
import { formatRelations, presentRelations, relationRouter } from "./relation-router";
|
|
19
|
-
import { commentRouter, formatComments, presentComments } from "./comment-router";
|
|
20
|
-
import { currentActor } from "../actor";
|
|
21
|
-
import { formatSection } from "../presentation/section";
|
|
22
|
-
import {
|
|
23
|
-
formatTaskList,
|
|
24
|
-
formatTaskListWithStatus,
|
|
25
|
-
formatTaskRow,
|
|
26
|
-
presentTask,
|
|
27
|
-
} from "../presentation/task-presentation";
|
|
28
|
-
|
|
29
|
-
export const taskRouter = {
|
|
30
|
-
create: {
|
|
31
|
-
run: (args) => {
|
|
32
|
-
const { values, positionals, tokens } = parseArgs({
|
|
33
|
-
args,
|
|
34
|
-
options: {
|
|
35
|
-
title: { type: "string" },
|
|
36
|
-
description: { type: "string" },
|
|
37
|
-
priority: { type: "string" },
|
|
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 },
|
|
44
|
-
},
|
|
45
|
-
allowPositionals: true,
|
|
46
|
-
strict: true,
|
|
47
|
-
tokens: true,
|
|
48
|
-
});
|
|
49
|
-
validateUniqueOptions(tokens, ["label", "depends-on", "related"]);
|
|
50
|
-
validatePositionals(positionals, ["<project-key>"]);
|
|
51
|
-
|
|
52
|
-
const projectKey = positionals[0]!;
|
|
53
|
-
if (values.title === undefined) {
|
|
54
|
-
quit("A task needs at least a title: use --title");
|
|
55
|
-
}
|
|
56
|
-
const projectMatch = project.getByKey(projectKey);
|
|
57
|
-
if (projectMatch == null) {
|
|
58
|
-
quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist`);
|
|
59
|
-
}
|
|
60
|
-
const createdTask = task.create(
|
|
61
|
-
{
|
|
62
|
-
project_id: projectMatch.id,
|
|
63
|
-
title: values.title,
|
|
64
|
-
description: values.description ?? null,
|
|
65
|
-
priority: parsePriority(values.priority),
|
|
66
|
-
labelNames: values.label,
|
|
67
|
-
columnName: values.column,
|
|
68
|
-
relations: parseNewTaskRelations(values),
|
|
69
|
-
},
|
|
70
|
-
currentActor(),
|
|
71
|
-
);
|
|
72
|
-
output(presentTask(createdTask), formatTaskRow);
|
|
73
|
-
},
|
|
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>]
|
|
75
|
-
|
|
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.
|
|
78
|
-
Priority defaults to none (unassigned).
|
|
79
|
-
Repeat --label to attach multiple existing labels. Unknown labels are errors.
|
|
80
|
-
Label names are matched case-insensitively.
|
|
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.
|
|
87
|
-
|
|
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`,
|
|
92
|
-
},
|
|
93
|
-
list: {
|
|
94
|
-
run: (args) => {
|
|
95
|
-
const { values, positionals, tokens } = parseArgs({
|
|
96
|
-
args,
|
|
97
|
-
options: {
|
|
98
|
-
archived: { type: "boolean" },
|
|
99
|
-
all: { type: "boolean" },
|
|
100
|
-
label: { type: "string", multiple: true },
|
|
101
|
-
column: { type: "string" },
|
|
102
|
-
},
|
|
103
|
-
allowPositionals: true,
|
|
104
|
-
strict: true,
|
|
105
|
-
tokens: true,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
validateUniqueOptions(tokens, ["label"]);
|
|
109
|
-
validatePositionals(positionals, ["[<project-key>]"]);
|
|
110
|
-
|
|
111
|
-
if (values.archived && values.all) {
|
|
112
|
-
quit('Use either "--archived" or "--all", not both');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const projectKey = positionals[0];
|
|
116
|
-
const archive = values.all ? "all" : values.archived ? "archived" : "active";
|
|
117
|
-
|
|
118
|
-
const tasks = task.getAll({
|
|
119
|
-
projectKey,
|
|
120
|
-
archive,
|
|
121
|
-
labelNames: values.label,
|
|
122
|
-
columnName: values.column,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
output(tasks.map(presentTask), (presentedTasks) =>
|
|
126
|
-
formatTaskList(presentedTasks, { showsStatus: values.all }),
|
|
127
|
-
);
|
|
128
|
-
},
|
|
129
|
-
help: `Usage: zinn task list [<project-key>] [--archived|--all] [--label <name>] [--column <name>]
|
|
130
|
-
|
|
131
|
-
List active tasks by default.
|
|
132
|
-
Use --archived to list archived tasks or --all to list both.
|
|
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.
|
|
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.
|
|
140
|
-
|
|
141
|
-
Example: zinn task list MDR --label cli`,
|
|
142
|
-
},
|
|
143
|
-
search: {
|
|
144
|
-
run: (args) => {
|
|
145
|
-
const { values, positionals, tokens } = parseArgs({
|
|
146
|
-
args,
|
|
147
|
-
options: {
|
|
148
|
-
archived: { type: "boolean" },
|
|
149
|
-
all: { type: "boolean" },
|
|
150
|
-
limit: { type: "string" },
|
|
151
|
-
label: { type: "string", multiple: true },
|
|
152
|
-
},
|
|
153
|
-
allowPositionals: true,
|
|
154
|
-
strict: true,
|
|
155
|
-
tokens: true,
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
validateUniqueOptions(tokens, ["label"]);
|
|
159
|
-
validatePositionals(positionals, ["<query>", "[<project-key>]"]);
|
|
160
|
-
|
|
161
|
-
const query = positionals[0]!;
|
|
162
|
-
const projectKey = positionals[1];
|
|
163
|
-
|
|
164
|
-
if (values.archived && values.all) {
|
|
165
|
-
quit('Use either "--archived" or "--all", not both');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const archive = values.all ? "all" : values.archived ? "archived" : "active";
|
|
169
|
-
const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
|
|
170
|
-
|
|
171
|
-
if (values.limit !== undefined && !limitPattern.test(values.limit)) {
|
|
172
|
-
quit(searchLimitMessage);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const limit = values.limit === undefined ? undefined : Number(values.limit);
|
|
176
|
-
const result = task.search({
|
|
177
|
-
query,
|
|
178
|
-
projectKey,
|
|
179
|
-
archive,
|
|
180
|
-
limit,
|
|
181
|
-
labelNames: values.label,
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
output(result.tasks.map(presentTask), (presentedTasks) =>
|
|
185
|
-
formatTaskList(presentedTasks, { showsStatus: values.all }),
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
if (result.hiddenArchivedCount > 0) {
|
|
189
|
-
const count = result.hiddenArchivedCount;
|
|
190
|
-
const noun = count === 1 ? "match" : "matches";
|
|
191
|
-
console.error(`${count} archived ${noun} hidden, use --all to include them`);
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
help: `Usage: zinn task search <query> [<project-key>] [--archived|--all] [--limit <n>] [--label <name>]
|
|
195
|
-
|
|
196
|
-
Search task titles, descriptions, and comments. A comment match lists the task it belongs to.
|
|
197
|
-
Each word matches the start of a word, ignoring case and accents: e.g. "auth" finds "Authentication".
|
|
198
|
-
Every word must match. Quote a query with several words.
|
|
199
|
-
|
|
200
|
-
A query that is exactly a task key, such as MDR-1, lists that task first.
|
|
201
|
-
Other results are ordered by relevance, with title matches weighted highest.
|
|
202
|
-
Equally relevant tasks are ordered by project key, then task number.
|
|
203
|
-
|
|
204
|
-
By default, only active tasks are searched. Use --archived to search archived tasks or --all to search both.
|
|
205
|
-
When archived matches are hidden, a note is printed to say how many.
|
|
206
|
-
Use --limit to show at most <n> results.
|
|
207
|
-
Use --label to filter for tasks with a specific label, no case-sensitivity is applied for matching.
|
|
208
|
-
A search result's output matches that of 'task list'.
|
|
209
|
-
|
|
210
|
-
Example: zinn task search "refinement quota" MDR --limit 5`,
|
|
211
|
-
},
|
|
212
|
-
view: {
|
|
213
|
-
run: (args) => {
|
|
214
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
215
|
-
validatePositionals(positionals, ["<task-key>"]);
|
|
216
|
-
|
|
217
|
-
const taskMatch = task.getByKey(positionals[0]!);
|
|
218
|
-
const viewedTask = {
|
|
219
|
-
...presentTask(taskMatch),
|
|
220
|
-
relations: presentRelations(taskMatch),
|
|
221
|
-
comments: presentComments(taskMatch.key),
|
|
222
|
-
};
|
|
223
|
-
|
|
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
|
-
};
|
|
233
|
-
const relations = formatRelations(t.relations);
|
|
234
|
-
const comments = formatComments(t.comments);
|
|
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
|
-
}
|
|
243
|
-
|
|
244
|
-
if (relations.length > 0) {
|
|
245
|
-
sections.push(formatSection("Relations", relations, sectionOptions));
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (comments.length > 0) {
|
|
249
|
-
sections.push(formatSection("Comments", comments, sectionOptions));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return sections.join("\n\n");
|
|
253
|
-
});
|
|
254
|
-
},
|
|
255
|
-
help: `Usage: zinn task view <task-key>
|
|
256
|
-
|
|
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.
|
|
259
|
-
|
|
260
|
-
Example: zinn task view MDR-1`,
|
|
261
|
-
},
|
|
262
|
-
edit: {
|
|
263
|
-
run: (args) => {
|
|
264
|
-
const { values, positionals, tokens } = parseArgs({
|
|
265
|
-
args,
|
|
266
|
-
options: {
|
|
267
|
-
title: { type: "string" },
|
|
268
|
-
description: { type: "string" },
|
|
269
|
-
...textEditOptions,
|
|
270
|
-
priority: { type: "string" },
|
|
271
|
-
"add-label": { type: "string", multiple: true },
|
|
272
|
-
"remove-label": { type: "string", multiple: true },
|
|
273
|
-
},
|
|
274
|
-
allowPositionals: true,
|
|
275
|
-
strict: true,
|
|
276
|
-
tokens: true,
|
|
277
|
-
});
|
|
278
|
-
|
|
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");
|
|
284
|
-
|
|
285
|
-
const hasEditFlags =
|
|
286
|
-
values.title !== undefined ||
|
|
287
|
-
description !== undefined ||
|
|
288
|
-
values.priority !== undefined ||
|
|
289
|
-
values["add-label"] !== undefined ||
|
|
290
|
-
values["remove-label"] !== undefined;
|
|
291
|
-
|
|
292
|
-
if (!hasEditFlags) {
|
|
293
|
-
quit(
|
|
294
|
-
"Provide at least one edit flag: --title, --description, --priority, --add-label, or --remove-label",
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const editedTask = task.edit(
|
|
299
|
-
{
|
|
300
|
-
taskKey,
|
|
301
|
-
title: values.title,
|
|
302
|
-
description,
|
|
303
|
-
priority: parsePriority(values.priority),
|
|
304
|
-
addLabelNames: values["add-label"],
|
|
305
|
-
removeLabelNames: values["remove-label"],
|
|
306
|
-
},
|
|
307
|
-
currentActor(),
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
output(presentTask(editedTask), formatTaskRow);
|
|
311
|
-
},
|
|
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>]
|
|
313
|
-
|
|
314
|
-
Edit a task's title, description, priority, or label attachments.
|
|
315
|
-
Use --priority none to clear priority.
|
|
316
|
-
Provide at least one edit flag. Use --description "" to clear the description.
|
|
317
|
-
|
|
318
|
-
${textEditHelp("--description")}
|
|
319
|
-
|
|
320
|
-
Repeat --add-label or --remove-label for multiple existing labels.
|
|
321
|
-
Label names are matched case-insensitively.
|
|
322
|
-
Adding an attached label or removing an unattached label does not do anything.
|
|
323
|
-
Archived tasks can be edited.
|
|
324
|
-
|
|
325
|
-
The same label cannot be both added and removed.
|
|
326
|
-
Titles are trimmed and cannot be blank or contain line breaks or control characters.
|
|
327
|
-
|
|
328
|
-
Use --title="--example" for text beginning with a dash.
|
|
329
|
-
|
|
330
|
-
Examples:
|
|
331
|
-
zinn task edit MDR-1 --title "Meet the quarterly refinement quota"
|
|
332
|
-
zinn task edit MDR-1 --description "Bring waffles." --append`,
|
|
333
|
-
},
|
|
334
|
-
move: {
|
|
335
|
-
run: (args) => {
|
|
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
|
-
);
|
|
347
|
-
},
|
|
348
|
-
help: `Usage: zinn task move <task-key>... <target-column>
|
|
349
|
-
|
|
350
|
-
Move tasks to another column in their projects.
|
|
351
|
-
Moving a task to a different column lists it last in that column,
|
|
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.
|
|
354
|
-
|
|
355
|
-
Giving a task's current column as the target will not do anything, and a note says so.
|
|
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.
|
|
358
|
-
|
|
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"`,
|
|
363
|
-
},
|
|
364
|
-
order: {
|
|
365
|
-
run: (args) => {
|
|
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);
|
|
373
|
-
|
|
374
|
-
const taskKey = positionals[0]!;
|
|
375
|
-
const direction = positionals[1]!;
|
|
376
|
-
|
|
377
|
-
switch (direction) {
|
|
378
|
-
case "before":
|
|
379
|
-
case "after": {
|
|
380
|
-
validatePositionals(positionals, [...leadingWords, "<target-task-key>"]);
|
|
381
|
-
|
|
382
|
-
const orderedTask = task.order(
|
|
383
|
-
{ taskKey, direction, targetTaskKey: positionals[2]! },
|
|
384
|
-
currentActor(),
|
|
385
|
-
);
|
|
386
|
-
output(presentTask(orderedTask), formatTaskRow);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
case "top":
|
|
390
|
-
case "up":
|
|
391
|
-
case "down":
|
|
392
|
-
case "bottom": {
|
|
393
|
-
validatePositionals(positionals, leadingWords);
|
|
394
|
-
|
|
395
|
-
const orderedTask = task.order({ taskKey, direction }, currentActor());
|
|
396
|
-
output(presentTask(orderedTask), formatTaskRow);
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
default:
|
|
400
|
-
throw new UsageError(`Unknown order direction "${direction}"`);
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
help: `Usage: zinn task order <task-key> {top|up|down|bottom}
|
|
404
|
-
zinn task order <task-key> {before|after} <target-task-key>
|
|
405
|
-
|
|
406
|
-
Change a task's position within its current column.
|
|
407
|
-
Use top or bottom for either end, up or down for one position,
|
|
408
|
-
or before or after to place it relative to another task.
|
|
409
|
-
|
|
410
|
-
Example: zinn task order MDR-2 before MDR-1`,
|
|
411
|
-
},
|
|
412
|
-
archive: {
|
|
413
|
-
run: (args: Array<string>) => {
|
|
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
|
-
);
|
|
421
|
-
},
|
|
422
|
-
help: `Usage: zinn task archive <task-key>...
|
|
423
|
-
|
|
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.
|
|
427
|
-
|
|
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`,
|
|
432
|
-
},
|
|
433
|
-
unarchive: {
|
|
434
|
-
run: (args: Array<string>) => {
|
|
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
|
-
);
|
|
442
|
-
},
|
|
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.
|
|
448
|
-
|
|
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.
|
|
451
|
-
|
|
452
|
-
Example: zinn task unarchive MDR-1 MDR-2`,
|
|
453
|
-
},
|
|
454
|
-
delete: {
|
|
455
|
-
run: (args: Array<string>) => {
|
|
456
|
-
const { values, positionals, tokens } = parseArgs({
|
|
457
|
-
args,
|
|
458
|
-
options: { yes: { type: "boolean" } },
|
|
459
|
-
allowPositionals: true,
|
|
460
|
-
strict: true,
|
|
461
|
-
tokens: true,
|
|
462
|
-
});
|
|
463
|
-
validateUniqueOptions(tokens);
|
|
464
|
-
validatePositionals(positionals, ["<task-key>"]);
|
|
465
|
-
|
|
466
|
-
const taskKey = positionals[0]!;
|
|
467
|
-
|
|
468
|
-
try {
|
|
469
|
-
const taskMatch = task.getByKey(taskKey);
|
|
470
|
-
const canDelete = confirmAction(
|
|
471
|
-
`Are you sure you want to delete ${taskKey}?`,
|
|
472
|
-
values.yes === true,
|
|
473
|
-
);
|
|
474
|
-
const presented = presentTask(taskMatch);
|
|
475
|
-
|
|
476
|
-
if (canDelete) {
|
|
477
|
-
task.delete(taskKey, currentActor());
|
|
478
|
-
output(presented, (t) => `Deleted ${formatTaskRow(t)}`);
|
|
479
|
-
} else {
|
|
480
|
-
output(presented, (t) => `Deletion cancelled for ${formatTaskRow(t)}`);
|
|
481
|
-
}
|
|
482
|
-
} catch (err: any) {
|
|
483
|
-
quit(failureMessage(err, "Something went wrong"));
|
|
484
|
-
}
|
|
485
|
-
},
|
|
486
|
-
help: `Usage: zinn task delete <task-key> [--yes]
|
|
487
|
-
|
|
488
|
-
Permanently delete a task after confirmation.
|
|
489
|
-
Use --yes to skip the confirmation prompt, for example in scripts or with --json.
|
|
490
|
-
|
|
491
|
-
Example: zinn task delete MDR-1`,
|
|
492
|
-
},
|
|
493
|
-
relation: relationRouter,
|
|
494
|
-
comment: commentRouter,
|
|
495
|
-
label: {
|
|
496
|
-
add: {
|
|
497
|
-
run: (args) => {
|
|
498
|
-
const props = parseTaskLabelArgs(args);
|
|
499
|
-
output(presentTask(task.label.add(props, currentActor())), formatTaskRow);
|
|
500
|
-
},
|
|
501
|
-
help: `Usage: zinn task label add <task-key> <label-name>...
|
|
502
|
-
|
|
503
|
-
Add existing labels to a task. Label names are matched case-insensitively.
|
|
504
|
-
Already attached labels are unchanged.`,
|
|
505
|
-
},
|
|
506
|
-
remove: {
|
|
507
|
-
run: (args) => {
|
|
508
|
-
const props = parseTaskLabelArgs(args);
|
|
509
|
-
output(presentTask(task.label.remove(props, currentActor())), formatTaskRow);
|
|
510
|
-
},
|
|
511
|
-
help: `Usage: zinn task label remove <task-key> <label-name>...
|
|
512
|
-
|
|
513
|
-
Remove existing labels from a task. Label names are matched case-insensitively.`,
|
|
514
|
-
},
|
|
515
|
-
},
|
|
516
|
-
} satisfies RouteDef;
|
|
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
|
-
|
|
552
|
-
function parseTaskLabelArgs(args: string[]) {
|
|
553
|
-
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
554
|
-
validatePositionals(positionals, ["<task-key>", "<label-name>..."]);
|
|
555
|
-
|
|
556
|
-
return { taskKey: positionals[0]!, labelNames: positionals.slice(1) };
|
|
557
|
-
}
|
|
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
|
-
|
|
580
|
-
function parsePriority(value: string | undefined) {
|
|
581
|
-
switch (value) {
|
|
582
|
-
case undefined:
|
|
583
|
-
return undefined;
|
|
584
|
-
case "none":
|
|
585
|
-
return null;
|
|
586
|
-
case "low":
|
|
587
|
-
case "medium":
|
|
588
|
-
case "high":
|
|
589
|
-
case "urgent":
|
|
590
|
-
return value;
|
|
591
|
-
default:
|
|
592
|
-
quit("Priority must be low, medium, high, urgent, or none");
|
|
593
|
-
}
|
|
594
|
-
}
|
package/src/text-edit.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
}
|