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