@zinn-dev/cli 0.39.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 +5 -2
- 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.ts → activity-router.js} +36 -46
- 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 -159
- package/src/presentation/activity-presentation.test.ts +0 -112
- package/src/presentation/activity-presentation.ts +0 -490
- 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/project.test.ts +0 -479
- package/src/project.ts +0 -53
- 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 -415
- 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 -649
- package/src/text-edit.ts +0 -68
- package/src/types.ts +0 -6
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const MINUTES_PER_HOUR = 60;
|
|
2
|
+
export function formatLocalTime(timestamp) {
|
|
3
|
+
const date = new Date(timestamp);
|
|
4
|
+
const offsetMinutes = -date.getTimezoneOffset();
|
|
5
|
+
const offsetSign = offsetMinutes >= 0 ? "+" : "-";
|
|
6
|
+
const absoluteOffsetMinutes = Math.abs(offsetMinutes);
|
|
7
|
+
const offsetHours = Math.floor(absoluteOffsetMinutes / MINUTES_PER_HOUR);
|
|
8
|
+
const remainingOffsetMinutes = absoluteOffsetMinutes % MINUTES_PER_HOUR;
|
|
9
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
10
|
+
return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
|
11
|
+
`${pad(date.getHours())}:${pad(date.getMinutes())} ` +
|
|
12
|
+
`${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`);
|
|
13
|
+
}
|
package/src/project.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
|
|
2
|
+
export declare function resolveProjectKey(typedKey: string | undefined, { required, allProjects, useDefault, }?: {
|
|
3
|
+
required?: boolean;
|
|
4
|
+
allProjects?: boolean;
|
|
5
|
+
useDefault?: boolean;
|
|
6
|
+
}): string | undefined;
|
package/src/project.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { project, resolveSettings } from "@zinn-dev/core";
|
|
3
|
+
import { UsageError } from "./lib.js";
|
|
4
|
+
/** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
|
|
5
|
+
export function resolveProjectKey(typedKey, { required = false, allProjects = false, useDefault = true, } = {}) {
|
|
6
|
+
if (allProjects) {
|
|
7
|
+
if (typedKey !== undefined) {
|
|
8
|
+
throw new UsageError("--all-projects cannot be combined with a project key");
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
if (typedKey !== undefined) {
|
|
13
|
+
return typedKey;
|
|
14
|
+
}
|
|
15
|
+
if (!useDefault) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const settings = resolveSettings({ cwd: process.cwd(), env: process.env, home: homedir() });
|
|
19
|
+
const defaultProject = settings.merged.defaultProject;
|
|
20
|
+
if (defaultProject === undefined) {
|
|
21
|
+
if (required) {
|
|
22
|
+
throw new UsageError("Missing argument <project-key>. Supply a key or configure defaultProject");
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const settingsFile = settings.local?.settings.defaultProject === undefined ? settings.global : settings.local;
|
|
27
|
+
if (project.getByKey(defaultProject) == null) {
|
|
28
|
+
throw new Error(`Default project "${defaultProject}" from settings file ${settingsFile.path} does not exist`);
|
|
29
|
+
}
|
|
30
|
+
return defaultProject;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const RELEASE_MODE = "published";
|
|
@@ -1,39 +1,31 @@
|
|
|
1
|
-
import type { RouteDef } from "../types";
|
|
2
|
-
|
|
3
1
|
import { parseArgs } from "node:util";
|
|
4
2
|
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
|
-
|
|
3
|
+
import { output, quit, validatePositionals, validateUniqueOptions } from "../lib.js";
|
|
4
|
+
import { formatActivityList, presentActivities } from "../presentation/activity-presentation.js";
|
|
8
5
|
export const activityRouter = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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]
|
|
6
|
+
list: {
|
|
7
|
+
run: (args) => {
|
|
8
|
+
const { values, positionals, tokens } = parseArgs({
|
|
9
|
+
args,
|
|
10
|
+
options: { task: { type: "string" }, limit: { type: "string" } },
|
|
11
|
+
allowPositionals: true,
|
|
12
|
+
strict: true,
|
|
13
|
+
tokens: true,
|
|
14
|
+
});
|
|
15
|
+
validateUniqueOptions(tokens);
|
|
16
|
+
validatePositionals(positionals, []);
|
|
17
|
+
// Safe integers can have one more digit than readable task numbers.
|
|
18
|
+
const limitPattern = new RegExp(`^${positiveIntegerPattern}\\d?$`);
|
|
19
|
+
if (values.limit !== undefined && !limitPattern.test(values.limit)) {
|
|
20
|
+
quit(activityLimitMessage);
|
|
21
|
+
}
|
|
22
|
+
const events = activity.getAll({
|
|
23
|
+
taskKey: values.task,
|
|
24
|
+
limit: values.limit === undefined ? undefined : Number(values.limit),
|
|
25
|
+
});
|
|
26
|
+
output(events, (items) => formatActivityList(presentActivities(items, { taskKey: values.task })));
|
|
27
|
+
},
|
|
28
|
+
help: `Usage: zinn activity list [--task <task-key>] [--limit <n>] [--json]
|
|
37
29
|
|
|
38
30
|
List recorded activity across the database, newest first.
|
|
39
31
|
By default, all matching events are returned. --limit takes a positive safe integer.
|
|
@@ -53,18 +45,16 @@ A project deletion event's entity_id is the project ID and removed task IDs are
|
|
|
53
45
|
Examples:
|
|
54
46
|
zinn activity list --limit 10
|
|
55
47
|
zinn activity list --task APP-2 --json`,
|
|
56
|
-
},
|
|
57
|
-
view: {
|
|
58
|
-
run: (args) => {
|
|
59
|
-
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
60
|
-
validatePositionals(positionals, ["<activity-id>"]);
|
|
61
|
-
output(activity.getById(positionals[0]!), (event) =>
|
|
62
|
-
formatActivityList(presentActivities([event], { showsFullIds: true }), {
|
|
63
|
-
showsDetails: true,
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
48
|
},
|
|
67
|
-
|
|
49
|
+
view: {
|
|
50
|
+
run: (args) => {
|
|
51
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
52
|
+
validatePositionals(positionals, ["<activity-id>"]);
|
|
53
|
+
output(activity.getById(positionals[0]), (event) => formatActivityList(presentActivities([event], { showsFullIds: true }), {
|
|
54
|
+
showsDetails: true,
|
|
55
|
+
}));
|
|
56
|
+
},
|
|
57
|
+
help: `Usage: zinn activity view <activity-id> [--json]
|
|
68
58
|
|
|
69
59
|
Show one recorded event with full activity/entity IDs, actor and complete changes.
|
|
70
60
|
Text and line breaks are preserved; unknown change fields remain available as raw JSON.
|
|
@@ -77,5 +67,5 @@ With --json, output is one full activity record, with parsed changes or null.
|
|
|
77
67
|
id identifies this event itself, while entity_type and entity_id identify its affected entity.
|
|
78
68
|
|
|
79
69
|
Example: zinn activity view 019abcdf-1234-7`,
|
|
80
|
-
|
|
81
|
-
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { backup } from "@zinn-dev/core";
|
|
3
|
+
import { output, validatePositionals } from "../lib.js";
|
|
4
|
+
import packageJson from "../../package.json" with { type: "json" };
|
|
5
|
+
export const backupCommand = {
|
|
6
|
+
run: (args) => {
|
|
7
|
+
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
8
|
+
validatePositionals(positionals, []);
|
|
9
|
+
const created = backup.create({ client: "cli", version: packageJson.version });
|
|
10
|
+
output(created, (b) => `Saved a backup to ${b.path}`);
|
|
11
|
+
},
|
|
12
|
+
help: `Usage: zinn backup
|
|
13
|
+
|
|
14
|
+
Save a copy of the database to ~/.zinn/backups/, or to backups/ in ZINN_DIR when it is set.
|
|
15
|
+
|
|
16
|
+
The copy includes recent writes and is safe to take while Zinn is in use.
|
|
17
|
+
Fails when there is no database yet. Existing backups are never overwritten.`,
|
|
18
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CommentWithKey } from "@zinn-dev/core";
|
|
2
|
+
type PresentedComment = Pick<CommentWithKey, "key" | "text" | "created_at" | "updated_at">;
|
|
3
|
+
export declare function presentComments(taskKey: string): PresentedComment[];
|
|
4
|
+
export declare function formatComment(commentMatch: PresentedComment): string;
|
|
5
|
+
export declare function formatComments(comments: Array<PresentedComment>): string;
|
|
6
|
+
export declare const commentRouter: {
|
|
7
|
+
create: {
|
|
8
|
+
run: (args: string[]) => void;
|
|
9
|
+
help: string;
|
|
10
|
+
};
|
|
11
|
+
list: {
|
|
12
|
+
run: (args: string[]) => void;
|
|
13
|
+
help: string;
|
|
14
|
+
};
|
|
15
|
+
edit: {
|
|
16
|
+
run: (args: string[]) => void;
|
|
17
|
+
help: string;
|
|
18
|
+
};
|
|
19
|
+
delete: {
|
|
20
|
+
run: (args: string[]) => Promise<void>;
|
|
21
|
+
help: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { comment } from "@zinn-dev/core";
|
|
3
|
+
import { confirmAction, output, quit, validatePositionals, validateUniqueOptions, } from "../lib.js";
|
|
4
|
+
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit.js";
|
|
5
|
+
import { currentActor } from "../actor.js";
|
|
6
|
+
import { formatRows } from "../presentation/row-layout.js";
|
|
7
|
+
import { formatLocalTime } from "../presentation/time.js";
|
|
8
|
+
function presentComment(commentMatch) {
|
|
9
|
+
return {
|
|
10
|
+
key: commentMatch.key,
|
|
11
|
+
text: commentMatch.text,
|
|
12
|
+
created_at: commentMatch.created_at,
|
|
13
|
+
updated_at: commentMatch.updated_at,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function presentComments(taskKey) {
|
|
17
|
+
return comment.getAll(taskKey).map(presentComment);
|
|
18
|
+
}
|
|
19
|
+
function commentRow(commentMatch, options) {
|
|
20
|
+
const createdAtCells = options.showsCreatedAt
|
|
21
|
+
? [{ text: formatLocalTime(commentMatch.created_at), style: "dim" }]
|
|
22
|
+
: [];
|
|
23
|
+
return [{ text: commentMatch.key }, ...createdAtCells, { text: commentMatch.text }];
|
|
24
|
+
}
|
|
25
|
+
export function formatComment(commentMatch) {
|
|
26
|
+
return formatRows([commentRow(commentMatch, { showsCreatedAt: false })], {
|
|
27
|
+
indentsContinuationLines: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function formatComments(comments) {
|
|
31
|
+
return formatRows(comments.map((commentMatch) => commentRow(commentMatch, { showsCreatedAt: true })), { indentsContinuationLines: true });
|
|
32
|
+
}
|
|
33
|
+
function parseTextArgs(args) {
|
|
34
|
+
const { values, positionals, tokens } = parseArgs({
|
|
35
|
+
args,
|
|
36
|
+
options: { text: { type: "string" } },
|
|
37
|
+
allowPositionals: true,
|
|
38
|
+
strict: true,
|
|
39
|
+
tokens: true,
|
|
40
|
+
});
|
|
41
|
+
validateUniqueOptions(tokens);
|
|
42
|
+
validatePositionals(positionals, ["<task-key>"]);
|
|
43
|
+
if (values.text === undefined) {
|
|
44
|
+
quit("Comment text must be specified with --text");
|
|
45
|
+
}
|
|
46
|
+
return { key: positionals[0], text: values.text };
|
|
47
|
+
}
|
|
48
|
+
function parseCommentEditArgs(args) {
|
|
49
|
+
const { values, positionals, tokens } = parseArgs({
|
|
50
|
+
args,
|
|
51
|
+
options: { text: { type: "string" }, ...textEditOptions },
|
|
52
|
+
allowPositionals: true,
|
|
53
|
+
strict: true,
|
|
54
|
+
tokens: true,
|
|
55
|
+
});
|
|
56
|
+
validateUniqueOptions(tokens);
|
|
57
|
+
validatePositionals(positionals, ["<comment-key>"]);
|
|
58
|
+
const text = resolveTextEdit(values.text, values, "--text");
|
|
59
|
+
if (text === undefined) {
|
|
60
|
+
quit("Comment text must be specified with --text");
|
|
61
|
+
}
|
|
62
|
+
return { key: positionals[0], text };
|
|
63
|
+
}
|
|
64
|
+
export const commentRouter = {
|
|
65
|
+
create: {
|
|
66
|
+
run: (args) => {
|
|
67
|
+
const props = parseTextArgs(args);
|
|
68
|
+
const created = comment.create({ taskKey: props.key, text: props.text }, currentActor());
|
|
69
|
+
output(presentComment(created), formatComment);
|
|
70
|
+
},
|
|
71
|
+
help: `Usage: zinn task comment create <task-key> --text <text>
|
|
72
|
+
|
|
73
|
+
Add a comment to a task. Comment text cannot be blank.
|
|
74
|
+
Archived tasks can be commented on.
|
|
75
|
+
|
|
76
|
+
Example: zinn task comment create MDR-1 --text "Ready for review"`,
|
|
77
|
+
},
|
|
78
|
+
list: {
|
|
79
|
+
run: (args) => {
|
|
80
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
81
|
+
validatePositionals(positionals, ["<task-key>"]);
|
|
82
|
+
output(presentComments(positionals[0]), formatComments);
|
|
83
|
+
},
|
|
84
|
+
help: `Usage: zinn task comment list <task-key>
|
|
85
|
+
|
|
86
|
+
List a task's comments by oldest first.
|
|
87
|
+
|
|
88
|
+
Example: zinn task comment list MDR-1`,
|
|
89
|
+
},
|
|
90
|
+
edit: {
|
|
91
|
+
run: (args) => {
|
|
92
|
+
const props = parseCommentEditArgs(args);
|
|
93
|
+
const edited = comment.edit({ commentKey: props.key, text: props.text }, currentActor());
|
|
94
|
+
output(presentComment(edited), formatComment);
|
|
95
|
+
},
|
|
96
|
+
help: `Usage: zinn task comment edit <comment-key> --text <text> ${textEditUsage}
|
|
97
|
+
|
|
98
|
+
Replace a comment's text. Comment text cannot be blank.
|
|
99
|
+
|
|
100
|
+
${textEditHelp("--text")}
|
|
101
|
+
|
|
102
|
+
Examples:
|
|
103
|
+
zinn task comment edit MDR-1#2 --text "Approved"
|
|
104
|
+
zinn task comment edit MDR-1#2 --text "Also approved." --append`,
|
|
105
|
+
},
|
|
106
|
+
delete: {
|
|
107
|
+
run: async (args) => {
|
|
108
|
+
const { values, positionals, tokens } = parseArgs({
|
|
109
|
+
args,
|
|
110
|
+
options: { yes: { type: "boolean" } },
|
|
111
|
+
allowPositionals: true,
|
|
112
|
+
strict: true,
|
|
113
|
+
tokens: true,
|
|
114
|
+
});
|
|
115
|
+
validateUniqueOptions(tokens);
|
|
116
|
+
validatePositionals(positionals, ["<comment-key>"]);
|
|
117
|
+
const commentMatch = comment.getByKey(positionals[0]);
|
|
118
|
+
const canDelete = await confirmAction(`Are you sure you want to delete ${commentMatch.key}?`, values.yes === true);
|
|
119
|
+
const presented = presentComment(commentMatch);
|
|
120
|
+
if (!canDelete) {
|
|
121
|
+
output(presented, (entry) => `Deletion cancelled for ${entry.key}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
comment.delete({ commentKey: commentMatch.key }, currentActor());
|
|
125
|
+
output(presented, (entry) => `Deleted ${entry.key}`);
|
|
126
|
+
},
|
|
127
|
+
help: `Usage: zinn task comment delete <comment-key> [--yes]
|
|
128
|
+
|
|
129
|
+
Permanently delete a comment after confirmation.
|
|
130
|
+
Use --yes to skip the confirmation prompt, for example in scripts or with --json.
|
|
131
|
+
|
|
132
|
+
Example: zinn task comment delete MDR-1#2`,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const labelRouter: {
|
|
2
|
+
create: {
|
|
3
|
+
run: (args: string[]) => void;
|
|
4
|
+
help: string;
|
|
5
|
+
};
|
|
6
|
+
list: {
|
|
7
|
+
run: (args: string[]) => void;
|
|
8
|
+
help: string;
|
|
9
|
+
};
|
|
10
|
+
edit: {
|
|
11
|
+
run: (args: string[]) => void;
|
|
12
|
+
help: string;
|
|
13
|
+
};
|
|
14
|
+
delete: {
|
|
15
|
+
run: (args: string[]) => Promise<void>;
|
|
16
|
+
help: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { label, labelCreateSchema, labelDeleteSchema, labelEditSchema } from "@zinn-dev/core";
|
|
3
|
+
import { confirmAction, output, quit, validatePositionals, validateUniqueOptions } from "../lib.js";
|
|
4
|
+
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit.js";
|
|
5
|
+
import { currentActor } from "../actor.js";
|
|
6
|
+
import { isColorEnabled } from "../presentation/color.js";
|
|
7
|
+
import { formatRows } from "../presentation/row-layout.js";
|
|
8
|
+
function presentLabel(labelMatch) {
|
|
9
|
+
return { name: labelMatch.name, color: labelMatch.color, description: labelMatch.description };
|
|
10
|
+
}
|
|
11
|
+
function formatLabel(presented) {
|
|
12
|
+
return formatLabelList([presented]);
|
|
13
|
+
}
|
|
14
|
+
function formatLabelList(presentedLabels) {
|
|
15
|
+
return formatRows(presentedLabels.map((presented) => {
|
|
16
|
+
const descriptionCells = presented.description == null ? [] : [{ text: presented.description }];
|
|
17
|
+
/**
|
|
18
|
+
* The colored name shows the color, and if the environment
|
|
19
|
+
* does not support color, it is explicitly printed instead
|
|
20
|
+
*/
|
|
21
|
+
if (isColorEnabled()) {
|
|
22
|
+
return [{ text: presented.name, style: presented.color }, ...descriptionCells];
|
|
23
|
+
}
|
|
24
|
+
return [{ text: presented.name }, { text: presented.color }, ...descriptionCells];
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
export const labelRouter = {
|
|
28
|
+
create: {
|
|
29
|
+
run: (args) => {
|
|
30
|
+
const { values, positionals, tokens } = parseArgs({
|
|
31
|
+
args,
|
|
32
|
+
options: { description: { type: "string" }, color: { type: "string" } },
|
|
33
|
+
allowPositionals: true,
|
|
34
|
+
strict: true,
|
|
35
|
+
tokens: true,
|
|
36
|
+
});
|
|
37
|
+
validateUniqueOptions(tokens);
|
|
38
|
+
validatePositionals(positionals, ["<name>"]);
|
|
39
|
+
const input = labelCreateSchema.parse({ name: positionals[0], ...values });
|
|
40
|
+
const created = label.create(input, currentActor());
|
|
41
|
+
output(presentLabel(created), formatLabel);
|
|
42
|
+
},
|
|
43
|
+
help: `Usage: zinn label create <name> [--description <text>] [--color <color>]
|
|
44
|
+
|
|
45
|
+
Create a global label. Names preserve casing, but uniqueness is case-insensitive.
|
|
46
|
+
Names are trimmed and cannot be blank or contain line breaks or control characters.
|
|
47
|
+
Description is optional.
|
|
48
|
+
|
|
49
|
+
Color defaults to white.
|
|
50
|
+
Valid colors: red, green, yellow, blue, magenta, cyan, white, gray.
|
|
51
|
+
|
|
52
|
+
Example: zinn label create bug --description "Unexpected behavior" --color red`,
|
|
53
|
+
},
|
|
54
|
+
list: {
|
|
55
|
+
run: (args) => {
|
|
56
|
+
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
57
|
+
validatePositionals(positionals, []);
|
|
58
|
+
output(label.getAll().map(presentLabel), formatLabelList);
|
|
59
|
+
},
|
|
60
|
+
help: `Usage: zinn label list
|
|
61
|
+
|
|
62
|
+
List all global label definitions.`,
|
|
63
|
+
},
|
|
64
|
+
edit: {
|
|
65
|
+
run: (args) => {
|
|
66
|
+
const { values, positionals, tokens } = parseArgs({
|
|
67
|
+
args,
|
|
68
|
+
options: {
|
|
69
|
+
name: { type: "string" },
|
|
70
|
+
description: { type: "string" },
|
|
71
|
+
...textEditOptions,
|
|
72
|
+
color: { type: "string" },
|
|
73
|
+
},
|
|
74
|
+
allowPositionals: true,
|
|
75
|
+
strict: true,
|
|
76
|
+
tokens: true,
|
|
77
|
+
});
|
|
78
|
+
validateUniqueOptions(tokens);
|
|
79
|
+
validatePositionals(positionals, ["<name>"]);
|
|
80
|
+
const input = labelEditSchema.parse({
|
|
81
|
+
labelName: positionals[0],
|
|
82
|
+
name: values.name,
|
|
83
|
+
description: resolveTextEdit(values.description, values, "--description"),
|
|
84
|
+
color: values.color,
|
|
85
|
+
});
|
|
86
|
+
const edited = label.edit(input, currentActor());
|
|
87
|
+
output(presentLabel(edited), formatLabel);
|
|
88
|
+
},
|
|
89
|
+
help: `Usage: zinn label edit <name> [--name <text>] [--description <text> ${textEditUsage}] [--color <color>]
|
|
90
|
+
|
|
91
|
+
Change specified fields.
|
|
92
|
+
Provide at least one edit flag. Use --description "" to clear the description.
|
|
93
|
+
|
|
94
|
+
${textEditHelp("--description")}
|
|
95
|
+
|
|
96
|
+
Names are matched and kept unique case-insensitively while preserving their casing.
|
|
97
|
+
Names are trimmed. Changing only the casing is allowed.
|
|
98
|
+
Editing does not affect task attachments or task timestamps.
|
|
99
|
+
|
|
100
|
+
Examples:
|
|
101
|
+
zinn label edit bug --name defect --color yellow
|
|
102
|
+
zinn label edit bug --description "Reported by users." --append`,
|
|
103
|
+
},
|
|
104
|
+
delete: {
|
|
105
|
+
run: async (args) => {
|
|
106
|
+
const { values, positionals, tokens } = parseArgs({
|
|
107
|
+
args,
|
|
108
|
+
options: { yes: { type: "boolean" } },
|
|
109
|
+
strict: true,
|
|
110
|
+
allowPositionals: true,
|
|
111
|
+
tokens: true,
|
|
112
|
+
});
|
|
113
|
+
validateUniqueOptions(tokens);
|
|
114
|
+
validatePositionals(positionals, ["<name>"]);
|
|
115
|
+
const props = labelDeleteSchema.parse({ name: positionals[0] });
|
|
116
|
+
const labelMatch = label.getByName(props.name);
|
|
117
|
+
if (labelMatch == null) {
|
|
118
|
+
quit(`A label with name "${props.name}" does not exist`);
|
|
119
|
+
}
|
|
120
|
+
const canDelete = await confirmAction(`Are you sure you want to delete label "${labelMatch.name}" and remove it from all tasks?`, values.yes === true);
|
|
121
|
+
if (!canDelete) {
|
|
122
|
+
output(presentLabel(labelMatch), (l) => `Deletion cancelled for label "${l.name}"`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const deleted = label.delete(props, currentActor());
|
|
126
|
+
output(presentLabel(deleted), (l) => `Deleted label "${l.name}"`);
|
|
127
|
+
},
|
|
128
|
+
help: `Usage: zinn label delete <name> [--yes]
|
|
129
|
+
|
|
130
|
+
Delete a label definition and remove it from all tasks after confirmation.
|
|
131
|
+
To remove a label from just one task, use zinn task label remove.
|
|
132
|
+
Label names are matched case-insensitively.
|
|
133
|
+
|
|
134
|
+
Use --yes to skip the confirmation prompt, for example in scripts or with --json.`,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { migrate, MigrationRefusedError, getStorage } from "@zinn-dev/core";
|
|
3
|
+
import { reportLockWait } from "../database.js";
|
|
4
|
+
import { output, validatePositionals } from "../lib.js";
|
|
5
|
+
import packageJson from "../../package.json" with { type: "json" };
|
|
6
|
+
export const migrateCommand = {
|
|
7
|
+
run: (args) => {
|
|
8
|
+
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
9
|
+
validatePositionals(positionals, []);
|
|
10
|
+
// Resolved before the try, so a store that cannot be resolved fails without the note about backups.
|
|
11
|
+
const { backupDirectory } = getStorage();
|
|
12
|
+
try {
|
|
13
|
+
const result = migrate.run({
|
|
14
|
+
client: "cli",
|
|
15
|
+
version: packageJson.version,
|
|
16
|
+
onWait: reportLockWait,
|
|
17
|
+
});
|
|
18
|
+
output(result, (r) => r.changed
|
|
19
|
+
? `Upgraded the database from schema version ${r.previousVersion} to ${r.finalVersion}. A backup was saved to ${r.backupPath}`
|
|
20
|
+
: `The database is already at schema version ${r.finalVersion}`);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
// A refusal attempted nothing, so only a failed upgrade points at the backups.
|
|
24
|
+
if (!(error instanceof MigrationRefusedError)) {
|
|
25
|
+
console.error(`The database is unchanged. Backups taken before each upgrade attempt are kept in ${backupDirectory}.`);
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
help: `Usage: zinn migrate
|
|
31
|
+
|
|
32
|
+
Upgrade an existing database to the latest schema version.
|
|
33
|
+
|
|
34
|
+
A backup is saved first, in the same place as \`zinn backup\`, and the upgrade is applied completely or not at all.
|
|
35
|
+
Does nothing when the database is already up to date.
|
|
36
|
+
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.`,
|
|
37
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const projectRouter: {
|
|
2
|
+
create: {
|
|
3
|
+
run: (args: Array<string>) => void;
|
|
4
|
+
help: string;
|
|
5
|
+
};
|
|
6
|
+
list: {
|
|
7
|
+
run: (args: Array<string>) => void;
|
|
8
|
+
help: string;
|
|
9
|
+
};
|
|
10
|
+
view: {
|
|
11
|
+
run: (args: Array<string>) => void;
|
|
12
|
+
help: string;
|
|
13
|
+
};
|
|
14
|
+
edit: {
|
|
15
|
+
run: (args: string[]) => void;
|
|
16
|
+
help: string;
|
|
17
|
+
};
|
|
18
|
+
delete: {
|
|
19
|
+
run: (args: Array<string>) => Promise<void>;
|
|
20
|
+
help: string;
|
|
21
|
+
};
|
|
22
|
+
column: {
|
|
23
|
+
create: {
|
|
24
|
+
run: (args: Array<string>) => void;
|
|
25
|
+
help: string;
|
|
26
|
+
};
|
|
27
|
+
list: {
|
|
28
|
+
run: (args: Array<string>) => void;
|
|
29
|
+
help: string;
|
|
30
|
+
};
|
|
31
|
+
edit: {
|
|
32
|
+
run: (args: Array<string>) => void;
|
|
33
|
+
help: string;
|
|
34
|
+
};
|
|
35
|
+
order: {
|
|
36
|
+
run: (args: Array<string>) => void;
|
|
37
|
+
help: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|