@zinn-dev/cli 0.36.0 → 0.37.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 +132 -20
- package/index.ts +7 -1
- 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 +60 -0
- package/src/lib.ts +42 -0
- package/src/presentation/color.ts +1 -1
- package/src/presentation/column-presentation.ts +38 -0
- package/src/presentation/row-layout.ts +77 -0
- package/src/presentation/section.ts +16 -0
- package/src/presentation/task-presentation.ts +48 -62
- package/src/routes/comment-router.ts +18 -14
- package/src/routes/label-router.ts +22 -10
- package/src/routes/migrate-router.test.ts +31 -0
- package/src/routes/migrate-router.ts +46 -0
- package/src/routes/project-router.ts +56 -27
- package/src/routes/reindex-router.ts +26 -0
- package/src/routes/relation-router.ts +11 -6
- package/src/routes/restore-router.test.ts +44 -0
- package/src/routes/restore-router.ts +90 -0
- package/src/routes/router.test.ts +23 -0
- package/src/routes/router.ts +29 -6
- package/src/routes/routes.ts +6 -0
- package/src/routes/task-router.ts +126 -54
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { StyleFormat } from "./color";
|
|
2
|
+
|
|
3
|
+
import { styleOutputText } from "./color";
|
|
4
|
+
|
|
5
|
+
export type RowCell = { text: string; style?: StyleFormat };
|
|
6
|
+
|
|
7
|
+
const CELL_SEPARATOR = " | ";
|
|
8
|
+
const LINE_BREAK_PATTERN = /\r?\n/;
|
|
9
|
+
|
|
10
|
+
export function formatCell(cell: RowCell, width = cell.text.length) {
|
|
11
|
+
const paddedText = cell.text.padEnd(width);
|
|
12
|
+
|
|
13
|
+
if (cell.style == null) {
|
|
14
|
+
return paddedText;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return styleOutputText(cell.style, paddedText);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Rows that join extra text onto their last cell, such as a task's labels, put one there too, which is why it is exported.
|
|
22
|
+
*/
|
|
23
|
+
export function formatCellSeparator() {
|
|
24
|
+
return styleOutputText("dim", CELL_SEPARATOR);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function indentContinuationLines(text: string, indentWidth: number) {
|
|
28
|
+
return text.split(LINE_BREAK_PATTERN).join(`\n${" ".repeat(indentWidth)}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Lines rows up by padding each cell's text to its column's **widest** text.
|
|
33
|
+
* Widths use `String.length`, so emoji and CJK misalign.
|
|
34
|
+
* A row's last cell holds free text such as a title and is left unpadded.
|
|
35
|
+
*
|
|
36
|
+
* With `indentsContinuationLines`, a last cell that spans several lines starts each later line
|
|
37
|
+
* where the cell starts, below the padded cells before it. Without it, those lines are left as they are.
|
|
38
|
+
* Only a last cell may span lines: the widths do not account for line breaks.
|
|
39
|
+
*/
|
|
40
|
+
export function formatRows(
|
|
41
|
+
rows: Array<Array<RowCell>>,
|
|
42
|
+
options: { indentsContinuationLines?: boolean } = {},
|
|
43
|
+
) {
|
|
44
|
+
const columnWidths: Array<number> = [];
|
|
45
|
+
|
|
46
|
+
for (const row of rows) {
|
|
47
|
+
row.forEach((cell, columnIndex) => {
|
|
48
|
+
columnWidths[columnIndex] = Math.max(columnWidths[columnIndex] ?? 0, cell.text.length);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return rows
|
|
53
|
+
.map((row) => {
|
|
54
|
+
const lastCellIndex = row.length - 1;
|
|
55
|
+
const lastCellStartColumn = columnWidths
|
|
56
|
+
.slice(0, lastCellIndex)
|
|
57
|
+
.reduce((total, width) => total + width + CELL_SEPARATOR.length, 0);
|
|
58
|
+
|
|
59
|
+
return row
|
|
60
|
+
.map((cell, columnIndex) => {
|
|
61
|
+
if (columnIndex !== lastCellIndex) {
|
|
62
|
+
return formatCell(cell, columnWidths[columnIndex]!);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!options.indentsContinuationLines) {
|
|
66
|
+
return formatCell(cell);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return formatCell({
|
|
70
|
+
...cell,
|
|
71
|
+
text: indentContinuationLines(cell.text, lastCellStartColumn),
|
|
72
|
+
});
|
|
73
|
+
})
|
|
74
|
+
.join(formatCellSeparator());
|
|
75
|
+
})
|
|
76
|
+
.join("\n");
|
|
77
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { styleOutputText } from "./color";
|
|
2
|
+
|
|
3
|
+
/** A bold heading above its body, optionally preceded by a dim horizontal rule. */
|
|
4
|
+
export function formatSection(
|
|
5
|
+
heading: string,
|
|
6
|
+
body: string,
|
|
7
|
+
options: { separatorWidth?: number } = {},
|
|
8
|
+
) {
|
|
9
|
+
const section = `${styleOutputText("bold", `${heading}:`)}\n${body}`;
|
|
10
|
+
|
|
11
|
+
if (options.separatorWidth === undefined) {
|
|
12
|
+
return section;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return `${styleOutputText("dim", "-".repeat(options.separatorWidth))}\n${section}`;
|
|
16
|
+
}
|
|
@@ -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,29 @@ 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): RowCell {
|
|
19
24
|
if (priority == null) {
|
|
20
|
-
return "
|
|
25
|
+
return { text: EMPTY_CELL_MARKER, style: "dim" };
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
return priority[0]!.toUpperCase();
|
|
28
|
+
return { text: priority[0]!.toUpperCase() };
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (columnName === "Done") {
|
|
35
|
-
return styleOutputText("green", paddedColumnName);
|
|
36
|
-
}
|
|
31
|
+
/**
|
|
32
|
+
* `PresentedTask` carries label names only, so JSON stays a list of names.
|
|
33
|
+
* Text output looks the colors up from the label definitions instead.
|
|
34
|
+
*/
|
|
35
|
+
function getLabelColorsByName() {
|
|
36
|
+
return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
|
|
37
|
+
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
function formatLabelNames(labelNames: Array<string>, labelColorsByName: Map<string, LabelColor>) {
|
|
40
|
+
return labelNames
|
|
41
|
+
.map((labelName) => styleOutputText(labelColorsByName.get(labelName)!, labelName))
|
|
42
|
+
.join(LABEL_NAME_SEPARATOR);
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export function presentTask(taskMatch: TaskWithKey): PresentedTask {
|
|
@@ -50,56 +54,38 @@ export function presentTask(taskMatch: TaskWithKey): PresentedTask {
|
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
|
|
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)}`;
|
|
57
|
+
export function formatTaskRow(presented: PresentedTask) {
|
|
58
|
+
return formatTaskList([presented]);
|
|
72
59
|
}
|
|
73
60
|
|
|
74
61
|
export function formatTaskList(
|
|
75
62
|
presentedTasks: Array<PresentedTask>,
|
|
76
63
|
options: { showsStatus?: boolean } = {},
|
|
77
64
|
) {
|
|
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)}`
|
|
65
|
+
const labelColorsByName = getLabelColorsByName();
|
|
66
|
+
|
|
67
|
+
return formatRows(
|
|
68
|
+
presentedTasks.map((presentedTask) => {
|
|
69
|
+
const statusCells: Array<RowCell> = options.showsStatus
|
|
70
|
+
? [{ text: presentedTask.status }]
|
|
71
|
+
: [];
|
|
72
|
+
const hasLabels = presentedTask.labels.length > 0;
|
|
73
|
+
// The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
|
|
74
|
+
const labels = hasLabels
|
|
75
|
+
? `${formatCellSeparator()}${formatLabelNames(presentedTask.labels, labelColorsByName)}`
|
|
95
76
|
: "";
|
|
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
77
|
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
|
|
78
|
+
return [
|
|
79
|
+
{ text: presentedTask.key },
|
|
80
|
+
...statusCells,
|
|
81
|
+
columnNameCell(presentedTask.column),
|
|
82
|
+
taskPriorityCell(presentedTask.priority),
|
|
83
|
+
{ text: `${presentedTask.title}${labels}` },
|
|
84
|
+
];
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function formatTaskListWithStatus(presentedTasks: Array<PresentedTask>) {
|
|
90
|
+
return formatTaskList(presentedTasks, { showsStatus: true });
|
|
105
91
|
}
|
|
@@ -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";
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
validateUniqueOptions,
|
|
13
14
|
} from "../lib";
|
|
14
15
|
import { currentActor } from "../actor";
|
|
16
|
+
import { formatRows } from "../presentation/row-layout";
|
|
15
17
|
|
|
16
18
|
type PresentedComment = Pick<CommentWithKey, "key" | "text" | "created_at" | "updated_at">;
|
|
17
19
|
|
|
@@ -44,23 +46,25 @@ function formatCommentCreatedAt(createdAt: number) {
|
|
|
44
46
|
);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
function commentRow(commentMatch: PresentedComment, options: { showsCreatedAt: boolean }) {
|
|
50
|
+
const createdAtCells: Array<RowCell> = options.showsCreatedAt
|
|
51
|
+
? [{ text: formatCommentCreatedAt(commentMatch.created_at), style: "dim" }]
|
|
52
|
+
: [];
|
|
53
|
+
|
|
54
|
+
return [{ text: commentMatch.key }, ...createdAtCells, { text: commentMatch.text }];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function formatComment(commentMatch: PresentedComment) {
|
|
58
|
+
return formatRows([commentRow(commentMatch, { showsCreatedAt: false })], {
|
|
59
|
+
indentsContinuationLines: true,
|
|
60
|
+
});
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
export function formatComments(comments: Array<PresentedComment>) {
|
|
61
|
-
return
|
|
62
|
-
.map((commentMatch) =>
|
|
63
|
-
|
|
64
|
+
return formatRows(
|
|
65
|
+
comments.map((commentMatch) => commentRow(commentMatch, { showsCreatedAt: true })),
|
|
66
|
+
{ indentsContinuationLines: true },
|
|
67
|
+
);
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
|
|
@@ -1,4 +1,5 @@
|
|
|
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";
|
|
@@ -12,7 +13,8 @@ import {
|
|
|
12
13
|
validateUniqueOptions,
|
|
13
14
|
} from "../lib";
|
|
14
15
|
import { currentActor } from "../actor";
|
|
15
|
-
import { isColorEnabled
|
|
16
|
+
import { isColorEnabled } from "../presentation/color";
|
|
17
|
+
import { formatRows } from "../presentation/row-layout";
|
|
16
18
|
|
|
17
19
|
type PresentedLabel = Omit<Label, "id">;
|
|
18
20
|
|
|
@@ -21,16 +23,26 @@ function presentLabel(labelMatch: Label): PresentedLabel {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
function formatLabel(presented: PresentedLabel) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
? styleOutputText(presented.color, presented.name)
|
|
27
|
-
: `${presented.name} | ${presented.color}`;
|
|
26
|
+
return formatLabelList([presented]);
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
function formatLabelList(presentedLabels: Array<PresentedLabel>) {
|
|
30
|
+
return formatRows(
|
|
31
|
+
presentedLabels.map((presented) => {
|
|
32
|
+
const descriptionCells: Array<RowCell> =
|
|
33
|
+
presented.description == null ? [] : [{ text: presented.description }];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The colored name shows the color, and if the environment
|
|
37
|
+
* does not support color, it is explicitly printed instead
|
|
38
|
+
*/
|
|
39
|
+
if (isColorEnabled()) {
|
|
40
|
+
return [{ text: presented.name, style: presented.color }, ...descriptionCells];
|
|
41
|
+
}
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
return [{ text: presented.name }, { text: presented.color }, ...descriptionCells];
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
34
46
|
}
|
|
35
47
|
|
|
36
48
|
export const labelRouter = {
|
|
@@ -67,7 +79,7 @@ Example: zinn label create bug --description "Unexpected behavior" --color red`,
|
|
|
67
79
|
list: {
|
|
68
80
|
run: (args) => {
|
|
69
81
|
parseArgs({ args, strict: true, allowPositionals: false });
|
|
70
|
-
output(label.getAll().map(presentLabel),
|
|
82
|
+
output(label.getAll().map(presentLabel), formatLabelList);
|
|
71
83
|
},
|
|
72
84
|
help: `Usage: zinn label list
|
|
73
85
|
|
|
@@ -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,46 @@
|
|
|
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 } from "../lib";
|
|
8
|
+
import packageJson from "../../package.json";
|
|
9
|
+
|
|
10
|
+
export const migrateCommand = {
|
|
11
|
+
run: (args) => {
|
|
12
|
+
parseArgs({ args, strict: true, allowPositionals: false });
|
|
13
|
+
// Resolved before the try, so a store that cannot be resolved fails without the note about backups.
|
|
14
|
+
const { backupDirectory } = getStorage();
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const result = migrate.run({
|
|
18
|
+
client: "cli",
|
|
19
|
+
version: packageJson.version,
|
|
20
|
+
onWait: reportLockWait,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
output(result, (r) =>
|
|
24
|
+
r.changed
|
|
25
|
+
? `Upgraded the database from schema version ${r.previousVersion} to ${r.finalVersion}. A backup was saved to ${r.backupPath}`
|
|
26
|
+
: `The database is already at schema version ${r.finalVersion}`,
|
|
27
|
+
);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// A refusal attempted nothing, so only a failed upgrade points at the backups.
|
|
30
|
+
if (!(error instanceof MigrationRefusedError)) {
|
|
31
|
+
console.error(
|
|
32
|
+
`The database is unchanged. Backups taken before each upgrade attempt are kept in ${backupDirectory}.`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
help: `Usage: zinn migrate
|
|
40
|
+
|
|
41
|
+
Upgrade an existing database to the latest schema version.
|
|
42
|
+
|
|
43
|
+
A backup is saved first, in the same place as \`zinn backup\`, and the upgrade is applied completely or not at all.
|
|
44
|
+
Does nothing when the database is already up to date.
|
|
45
|
+
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.`,
|
|
46
|
+
} satisfies Command;
|
|
@@ -1,31 +1,53 @@
|
|
|
1
1
|
import type { RouteDef } from "../types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PresentedColumnTaskCount } from "../presentation/column-presentation";
|
|
3
3
|
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
|
|
6
|
-
import { column, project
|
|
6
|
+
import { column, project } from "@zinn-dev/core";
|
|
7
7
|
import {
|
|
8
8
|
confirmAction,
|
|
9
|
+
failureMessage,
|
|
9
10
|
output,
|
|
10
11
|
quit,
|
|
11
12
|
validatePositionalCount,
|
|
12
13
|
validateUniqueOptions,
|
|
13
14
|
} from "../lib";
|
|
14
|
-
import {
|
|
15
|
+
import { formatColumnTaskCounts } from "../presentation/column-presentation";
|
|
15
16
|
import { formatDescriptionPreview } from "../presentation/description-presentation";
|
|
17
|
+
import { formatCellSeparator, formatRows } from "../presentation/row-layout";
|
|
18
|
+
import { formatSection } from "../presentation/section";
|
|
16
19
|
import { currentActor } from "../actor";
|
|
17
20
|
|
|
18
21
|
type PresentedProject = { key: string; name: string; description: string | null };
|
|
19
|
-
type PresentedProjectView = PresentedProject & {
|
|
22
|
+
type PresentedProjectView = PresentedProject & {
|
|
23
|
+
columns: Array<PresentedColumnTaskCount>;
|
|
24
|
+
archivedTaskCount: number;
|
|
25
|
+
};
|
|
26
|
+
type ProjectRowOptions = { showsDescriptionPreview?: boolean };
|
|
20
27
|
|
|
21
28
|
function presentProject(projectMatch: PresentedProject): PresentedProject {
|
|
22
29
|
return { key: projectMatch.key, name: projectMatch.name, description: projectMatch.description };
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
function formatProject(presented: PresentedProject,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
function formatProject(presented: PresentedProject, options: ProjectRowOptions = {}) {
|
|
33
|
+
return formatProjectList([presented], options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function formatProjectList(
|
|
37
|
+
presentedProjects: Array<PresentedProject>,
|
|
38
|
+
{ showsDescriptionPreview = true }: ProjectRowOptions = {},
|
|
39
|
+
) {
|
|
40
|
+
return formatRows(
|
|
41
|
+
presentedProjects.map((presented) => {
|
|
42
|
+
const descriptionPreview = showsDescriptionPreview
|
|
43
|
+
? formatDescriptionPreview(presented.description)
|
|
44
|
+
: "";
|
|
45
|
+
const description =
|
|
46
|
+
descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
|
|
47
|
+
|
|
48
|
+
return [{ text: presented.key }, { text: `${presented.name}${description}` }];
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
29
51
|
}
|
|
30
52
|
|
|
31
53
|
type PresentedColumn = { project: string; name: string };
|
|
@@ -37,7 +59,7 @@ function presentColumn(columnMatch: { project_id: string; name: string }): Prese
|
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
function formatColumn(presented: PresentedColumn) {
|
|
40
|
-
return
|
|
62
|
+
return formatRows([[{ text: presented.project }, { text: presented.name }]]);
|
|
41
63
|
}
|
|
42
64
|
|
|
43
65
|
export const projectRouter = {
|
|
@@ -68,7 +90,7 @@ export const projectRouter = {
|
|
|
68
90
|
);
|
|
69
91
|
output(presentProject(createdProject), formatProject);
|
|
70
92
|
} catch (err: any) {
|
|
71
|
-
quit(err
|
|
93
|
+
quit(failureMessage(err, "Something went wrong"));
|
|
72
94
|
}
|
|
73
95
|
},
|
|
74
96
|
help: `Usage: zinn project create <project-key> [--name <text>] [--description <text>]
|
|
@@ -86,14 +108,7 @@ Example: zinn project create MDR --name "Macrodata Refinement"`,
|
|
|
86
108
|
run: () => {
|
|
87
109
|
const projects = project.getAll();
|
|
88
110
|
|
|
89
|
-
output(projects.map(presentProject),
|
|
90
|
-
const longestKeyLength = presentedProjects.reduce(
|
|
91
|
-
(prev, current) => Math.max(prev, current.key.length),
|
|
92
|
-
0,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
return presentedProjects.map((p) => formatProject(p, longestKeyLength)).join("\n");
|
|
96
|
-
});
|
|
111
|
+
output(projects.map(presentProject), formatProjectList);
|
|
97
112
|
},
|
|
98
113
|
help: `Usage: zinn project list
|
|
99
114
|
|
|
@@ -117,21 +132,36 @@ Example: zinn project list`,
|
|
|
117
132
|
quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist!`);
|
|
118
133
|
}
|
|
119
134
|
|
|
135
|
+
const taskCounts = column.getTaskCountsByProjectKey(projectMatch.key);
|
|
120
136
|
const presentedProject: PresentedProjectView = {
|
|
121
137
|
...presentProject(projectMatch),
|
|
122
|
-
|
|
138
|
+
columns: taskCounts.columns.map((columnCount) => ({
|
|
139
|
+
name: columnCount.column.name,
|
|
140
|
+
taskCount: columnCount.taskCount,
|
|
141
|
+
})),
|
|
142
|
+
archivedTaskCount: taskCounts.archivedTaskCount,
|
|
123
143
|
};
|
|
124
144
|
|
|
125
145
|
output(presentedProject, (viewedProject) => {
|
|
126
|
-
|
|
127
|
-
const
|
|
146
|
+
// The full description follows as its own section, so the row leaves out the preview.
|
|
147
|
+
const sections = [formatProject(viewedProject, { showsDescriptionPreview: false })];
|
|
148
|
+
|
|
149
|
+
if (viewedProject.description != null) {
|
|
150
|
+
sections.push(formatSection("Description", viewedProject.description));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const columnTaskCounts = formatColumnTaskCounts(viewedProject.columns, {
|
|
154
|
+
archivedTaskCount: viewedProject.archivedTaskCount,
|
|
155
|
+
});
|
|
156
|
+
sections.push(formatSection("Columns", columnTaskCounts));
|
|
128
157
|
|
|
129
|
-
return
|
|
158
|
+
return sections.join("\n\n");
|
|
130
159
|
});
|
|
131
160
|
},
|
|
132
161
|
help: `Usage: zinn project view <project-key>
|
|
133
162
|
|
|
134
|
-
Show a project
|
|
163
|
+
Show a project with its description and the number of tasks in each column.
|
|
164
|
+
The description prints in full, keeping its line breaks. Archived tasks are counted as one total.
|
|
135
165
|
|
|
136
166
|
Example: zinn project view MDR`,
|
|
137
167
|
},
|
|
@@ -169,7 +199,6 @@ Example: zinn project view MDR`,
|
|
|
169
199
|
|
|
170
200
|
Change the supplied project fields. At least one edit flag is required.
|
|
171
201
|
Use --description "" to clear the description.
|
|
172
|
-
Omitted fields are preserved. Unchanged values leave the timestamp unchanged.
|
|
173
202
|
|
|
174
203
|
Example: zinn project edit MDR --name "Macrodata Refinement"`,
|
|
175
204
|
},
|
|
@@ -206,7 +235,7 @@ Example: zinn project edit MDR --name "Macrodata Refinement"`,
|
|
|
206
235
|
output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProject(p)}`);
|
|
207
236
|
}
|
|
208
237
|
} catch (err: any) {
|
|
209
|
-
quit(err
|
|
238
|
+
quit(failureMessage(err, "Something went wrong"));
|
|
210
239
|
}
|
|
211
240
|
},
|
|
212
241
|
help: `Usage: zinn project delete <project-key> [--yes]
|
|
@@ -230,13 +259,13 @@ Example: zinn project delete MDR`,
|
|
|
230
259
|
const createdColumn = column.create({ projectKey, name: columnName }, currentActor());
|
|
231
260
|
output(presentColumn(createdColumn), formatColumn);
|
|
232
261
|
} catch (err: any) {
|
|
233
|
-
quit(err
|
|
262
|
+
quit(failureMessage(err, "Something went wrong"));
|
|
234
263
|
}
|
|
235
264
|
},
|
|
236
265
|
help: `Usage: zinn project column create <project-key> <column-name>
|
|
237
266
|
|
|
238
267
|
Add a column at the end of a project's board.
|
|
239
|
-
Names are trimmed,
|
|
268
|
+
Names are trimmed, cannot be blank or contain line breaks or control characters, and must be unique within the project regardless of casing.
|
|
240
269
|
|
|
241
270
|
Example: zinn project column create MDR "Boardlog"`,
|
|
242
271
|
},
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Command } from "../types";
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { reindex } from "@zinn-dev/core";
|
|
5
|
+
|
|
6
|
+
import { reportLockWait } from "../database";
|
|
7
|
+
import { output } from "../lib";
|
|
8
|
+
|
|
9
|
+
export const reindexCommand = {
|
|
10
|
+
run: (args) => {
|
|
11
|
+
parseArgs({ args, strict: true, allowPositionals: false });
|
|
12
|
+
|
|
13
|
+
const result = reindex.run({ onWait: reportLockWait });
|
|
14
|
+
|
|
15
|
+
output(result, (r) => {
|
|
16
|
+
const noun = r.taskCount === 1 ? "task" : "tasks";
|
|
17
|
+
return `Rebuilt the search index from ${r.taskCount} ${noun}`;
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
help: `Usage: zinn reindex
|
|
21
|
+
|
|
22
|
+
Rebuild the search index that \`zinn task search\` uses from the tasks and their comments, archived tasks included.
|
|
23
|
+
|
|
24
|
+
Only the index changes, completely or not at all, so no backup is saved.
|
|
25
|
+
Fails, leaving the database as it is, when there is no database yet or when this Zinn cannot change it, such as a database with a newer schema version.`,
|
|
26
|
+
} satisfies Command;
|
|
@@ -5,6 +5,7 @@ import { parseArgs } from "node:util";
|
|
|
5
5
|
import { relation, relationCreateSchema, task } from "@zinn-dev/core";
|
|
6
6
|
import { output, quit, validatePositionalCount, validateUniqueOptions } from "../lib";
|
|
7
7
|
import { currentActor } from "../actor";
|
|
8
|
+
import { formatCellSeparator, formatRows } from "../presentation/row-layout";
|
|
8
9
|
|
|
9
10
|
type PresentedRelation = {
|
|
10
11
|
type: TaskRelationType;
|
|
@@ -38,8 +39,8 @@ export function presentRelations(taskMatch: TaskWithKey): Array<PresentedRelatio
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export function formatRelations(relations: Array<PresentedRelation>) {
|
|
41
|
-
return
|
|
42
|
-
.map((entry) => {
|
|
42
|
+
return formatRows(
|
|
43
|
+
relations.map((entry) => {
|
|
43
44
|
const isOutgoing = entry.direction === "outgoing";
|
|
44
45
|
|
|
45
46
|
let label: string;
|
|
@@ -62,10 +63,14 @@ export function formatRelations(relations: Array<PresentedRelation>) {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
const archived = entry.task.status === "Archived" ?
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
|
|
67
|
+
return [
|
|
68
|
+
{ text: label },
|
|
69
|
+
{ text: entry.task.key },
|
|
70
|
+
{ text: `${entry.task.title}${archived}` },
|
|
71
|
+
];
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
type PresentedRelationChange = { type: TaskRelationType; source: string; target: string };
|