@zinn-dev/cli 0.37.0 → 0.39.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 +198 -85
- package/index.ts +1 -15
- package/package.json +2 -2
- package/src/lib.test.ts +28 -2
- package/src/lib.ts +52 -15
- package/src/presentation/activity-presentation.test.ts +112 -0
- package/src/presentation/activity-presentation.ts +490 -0
- package/src/presentation/column-presentation.ts +19 -9
- package/src/presentation/description-presentation.ts +7 -4
- package/src/presentation/task-presentation.ts +5 -4
- package/src/presentation/time.ts +17 -0
- package/src/project.test.ts +479 -0
- package/src/project.ts +53 -0
- package/src/routes/activity-router.ts +81 -0
- package/src/routes/backup-router.ts +3 -2
- package/src/routes/comment-router.ts +39 -27
- package/src/routes/label-router.ts +25 -17
- package/src/routes/migrate-router.ts +4 -2
- package/src/routes/project-router.ts +110 -88
- package/src/routes/reindex-router.ts +3 -2
- package/src/routes/relation-router.ts +9 -7
- package/src/routes/restore-router.ts +2 -2
- package/src/routes/router.test.ts +18 -0
- package/src/routes/router.ts +108 -22
- package/src/routes/routes.ts +2 -0
- package/src/routes/task-router.ts +172 -103
- package/src/text-edit.ts +68 -0
|
@@ -9,11 +9,13 @@ import {
|
|
|
9
9
|
confirmAction,
|
|
10
10
|
output,
|
|
11
11
|
quit,
|
|
12
|
-
|
|
12
|
+
validatePositionals,
|
|
13
13
|
validateUniqueOptions,
|
|
14
14
|
} from "../lib";
|
|
15
|
+
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
|
|
15
16
|
import { currentActor } from "../actor";
|
|
16
17
|
import { formatRows } from "../presentation/row-layout";
|
|
18
|
+
import { formatLocalTime } from "../presentation/time";
|
|
17
19
|
|
|
18
20
|
type PresentedComment = Pick<CommentWithKey, "key" | "text" | "created_at" | "updated_at">;
|
|
19
21
|
|
|
@@ -30,25 +32,9 @@ export function presentComments(taskKey: string) {
|
|
|
30
32
|
return comment.getAll(taskKey).map(presentComment);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function formatCommentCreatedAt(createdAt: number) {
|
|
34
|
-
const date = new Date(createdAt);
|
|
35
|
-
const offsetMinutes = -date.getTimezoneOffset();
|
|
36
|
-
const offsetSign = offsetMinutes >= 0 ? "+" : "-";
|
|
37
|
-
const absoluteOffsetMinutes = Math.abs(offsetMinutes);
|
|
38
|
-
const offsetHours = Math.floor(absoluteOffsetMinutes / 60);
|
|
39
|
-
const remainingOffsetMinutes = absoluteOffsetMinutes % 60;
|
|
40
|
-
const pad = (value: number) => String(value).padStart(2, "0");
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
|
44
|
-
`${pad(date.getHours())}:${pad(date.getMinutes())} ` +
|
|
45
|
-
`${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
35
|
function commentRow(commentMatch: PresentedComment, options: { showsCreatedAt: boolean }) {
|
|
50
36
|
const createdAtCells: Array<RowCell> = options.showsCreatedAt
|
|
51
|
-
? [{ text:
|
|
37
|
+
? [{ text: formatLocalTime(commentMatch.created_at), style: "dim" }]
|
|
52
38
|
: [];
|
|
53
39
|
|
|
54
40
|
return [{ text: commentMatch.key }, ...createdAtCells, { text: commentMatch.text }];
|
|
@@ -67,7 +53,7 @@ export function formatComments(comments: Array<PresentedComment>) {
|
|
|
67
53
|
);
|
|
68
54
|
}
|
|
69
55
|
|
|
70
|
-
function parseTextArgs(args: Array<string
|
|
56
|
+
function parseTextArgs(args: Array<string>) {
|
|
71
57
|
const { values, positionals, tokens } = parseArgs({
|
|
72
58
|
args,
|
|
73
59
|
options: { text: { type: "string" } },
|
|
@@ -76,8 +62,8 @@ function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
|
|
|
76
62
|
tokens: true,
|
|
77
63
|
});
|
|
78
64
|
|
|
79
|
-
validatePositionalCount(positionals, 1, `Exactly one ${entityName} key is required`);
|
|
80
65
|
validateUniqueOptions(tokens);
|
|
66
|
+
validatePositionals(positionals, ["<task-key>"]);
|
|
81
67
|
|
|
82
68
|
if (values.text === undefined) {
|
|
83
69
|
quit("Comment text must be specified with --text");
|
|
@@ -86,10 +72,30 @@ function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
|
|
|
86
72
|
return { key: positionals[0]!, text: values.text };
|
|
87
73
|
}
|
|
88
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
|
+
|
|
89
95
|
export const commentRouter = {
|
|
90
96
|
create: {
|
|
91
97
|
run: (args) => {
|
|
92
|
-
const props = parseTextArgs(args
|
|
98
|
+
const props = parseTextArgs(args);
|
|
93
99
|
const created = comment.create({ taskKey: props.key, text: props.text }, currentActor());
|
|
94
100
|
output(presentComment(created), formatComment);
|
|
95
101
|
},
|
|
@@ -103,7 +109,7 @@ Example: zinn task comment create MDR-1 --text "Ready for review"`,
|
|
|
103
109
|
list: {
|
|
104
110
|
run: (args) => {
|
|
105
111
|
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
106
|
-
|
|
112
|
+
validatePositionals(positionals, ["<task-key>"]);
|
|
107
113
|
output(presentComments(positionals[0]!), formatComments);
|
|
108
114
|
},
|
|
109
115
|
help: `Usage: zinn task comment list <task-key>
|
|
@@ -114,25 +120,31 @@ Example: zinn task comment list MDR-1`,
|
|
|
114
120
|
},
|
|
115
121
|
edit: {
|
|
116
122
|
run: (args) => {
|
|
117
|
-
const props =
|
|
123
|
+
const props = parseCommentEditArgs(args);
|
|
118
124
|
const edited = comment.edit({ commentKey: props.key, text: props.text }, currentActor());
|
|
119
125
|
output(presentComment(edited), formatComment);
|
|
120
126
|
},
|
|
121
|
-
help: `Usage: zinn task comment edit <comment-key> --text <text>
|
|
127
|
+
help: `Usage: zinn task comment edit <comment-key> --text <text> ${textEditUsage}
|
|
122
128
|
|
|
123
129
|
Replace a comment's text. Comment text cannot be blank.
|
|
124
130
|
|
|
125
|
-
|
|
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`,
|
|
126
136
|
},
|
|
127
137
|
delete: {
|
|
128
138
|
run: (args) => {
|
|
129
|
-
const { values, positionals } = parseArgs({
|
|
139
|
+
const { values, positionals, tokens } = parseArgs({
|
|
130
140
|
args,
|
|
131
141
|
options: { yes: { type: "boolean" } },
|
|
132
142
|
allowPositionals: true,
|
|
133
143
|
strict: true,
|
|
144
|
+
tokens: true,
|
|
134
145
|
});
|
|
135
|
-
|
|
146
|
+
validateUniqueOptions(tokens);
|
|
147
|
+
validatePositionals(positionals, ["<comment-key>"]);
|
|
136
148
|
|
|
137
149
|
const commentMatch = comment.getByKey(positionals[0]!);
|
|
138
150
|
const canDelete = confirmAction(
|
|
@@ -5,13 +5,8 @@ import type { RouteDef } from "../types";
|
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import { label, labelCreateSchema, labelDeleteSchema, labelEditSchema } from "@zinn-dev/core";
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
output,
|
|
11
|
-
quit,
|
|
12
|
-
validatePositionalCount,
|
|
13
|
-
validateUniqueOptions,
|
|
14
|
-
} from "../lib";
|
|
8
|
+
import { confirmAction, output, quit, validatePositionals, validateUniqueOptions } from "../lib";
|
|
9
|
+
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
|
|
15
10
|
import { currentActor } from "../actor";
|
|
16
11
|
import { isColorEnabled } from "../presentation/color";
|
|
17
12
|
import { formatRows } from "../presentation/row-layout";
|
|
@@ -56,9 +51,8 @@ export const labelRouter = {
|
|
|
56
51
|
tokens: true,
|
|
57
52
|
});
|
|
58
53
|
|
|
59
|
-
validatePositionalCount(positionals, 1, "Exactly one label name is required");
|
|
60
|
-
|
|
61
54
|
validateUniqueOptions(tokens);
|
|
55
|
+
validatePositionals(positionals, ["<name>"]);
|
|
62
56
|
|
|
63
57
|
const input = labelCreateSchema.parse({ name: positionals[0], ...values });
|
|
64
58
|
const created = label.create(input, currentActor());
|
|
@@ -68,7 +62,7 @@ export const labelRouter = {
|
|
|
68
62
|
help: `Usage: zinn label create <name> [--description <text>] [--color <color>]
|
|
69
63
|
|
|
70
64
|
Create a global label. Names preserve casing, but uniqueness is case-insensitive.
|
|
71
|
-
Names are trimmed and cannot be blank.
|
|
65
|
+
Names are trimmed and cannot be blank or contain line breaks or control characters.
|
|
72
66
|
Description is optional.
|
|
73
67
|
|
|
74
68
|
Color defaults to white.
|
|
@@ -78,7 +72,9 @@ Example: zinn label create bug --description "Unexpected behavior" --color red`,
|
|
|
78
72
|
},
|
|
79
73
|
list: {
|
|
80
74
|
run: (args) => {
|
|
81
|
-
parseArgs({ args, strict: true, allowPositionals:
|
|
75
|
+
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
76
|
+
validatePositionals(positionals, []);
|
|
77
|
+
|
|
82
78
|
output(label.getAll().map(presentLabel), formatLabelList);
|
|
83
79
|
},
|
|
84
80
|
help: `Usage: zinn label list
|
|
@@ -92,6 +88,7 @@ List all global label definitions.`,
|
|
|
92
88
|
options: {
|
|
93
89
|
name: { type: "string" },
|
|
94
90
|
description: { type: "string" },
|
|
91
|
+
...textEditOptions,
|
|
95
92
|
color: { type: "string" },
|
|
96
93
|
},
|
|
97
94
|
allowPositionals: true,
|
|
@@ -99,35 +96,46 @@ List all global label definitions.`,
|
|
|
99
96
|
tokens: true,
|
|
100
97
|
});
|
|
101
98
|
|
|
102
|
-
validatePositionalCount(positionals, 1, "Exactly one label name is required");
|
|
103
99
|
validateUniqueOptions(tokens);
|
|
100
|
+
validatePositionals(positionals, ["<name>"]);
|
|
104
101
|
|
|
105
|
-
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
|
+
});
|
|
106
108
|
const edited = label.edit(input, currentActor());
|
|
107
109
|
|
|
108
110
|
output(presentLabel(edited), formatLabel);
|
|
109
111
|
},
|
|
110
|
-
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>]
|
|
111
113
|
|
|
112
114
|
Change specified fields.
|
|
113
115
|
Provide at least one edit flag. Use --description "" to clear the description.
|
|
114
116
|
|
|
117
|
+
${textEditHelp("--description")}
|
|
118
|
+
|
|
115
119
|
Names are matched and kept unique case-insensitively while preserving their casing.
|
|
116
120
|
Names are trimmed. Changing only the casing is allowed.
|
|
117
121
|
Editing does not affect task attachments or task timestamps.
|
|
118
122
|
|
|
119
|
-
|
|
123
|
+
Examples:
|
|
124
|
+
zinn label edit bug --name defect --color yellow
|
|
125
|
+
zinn label edit bug --description "Reported by users." --append`,
|
|
120
126
|
},
|
|
121
127
|
delete: {
|
|
122
128
|
run: (args) => {
|
|
123
|
-
const { values, positionals } = parseArgs({
|
|
129
|
+
const { values, positionals, tokens } = parseArgs({
|
|
124
130
|
args,
|
|
125
131
|
options: { yes: { type: "boolean" } },
|
|
126
132
|
strict: true,
|
|
127
133
|
allowPositionals: true,
|
|
134
|
+
tokens: true,
|
|
128
135
|
});
|
|
129
136
|
|
|
130
|
-
|
|
137
|
+
validateUniqueOptions(tokens);
|
|
138
|
+
validatePositionals(positionals, ["<name>"]);
|
|
131
139
|
|
|
132
140
|
const props = labelDeleteSchema.parse({ name: positionals[0] });
|
|
133
141
|
const labelMatch = label.getByName(props.name);
|
|
@@ -4,12 +4,14 @@ import { parseArgs } from "node:util";
|
|
|
4
4
|
import { migrate, MigrationRefusedError, getStorage } from "@zinn-dev/core";
|
|
5
5
|
|
|
6
6
|
import { reportLockWait } from "../database";
|
|
7
|
-
import { output } from "../lib";
|
|
7
|
+
import { output, validatePositionals } from "../lib";
|
|
8
8
|
import packageJson from "../../package.json";
|
|
9
9
|
|
|
10
10
|
export const migrateCommand = {
|
|
11
11
|
run: (args) => {
|
|
12
|
-
parseArgs({ args, strict: true, allowPositionals:
|
|
12
|
+
const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
|
|
13
|
+
validatePositionals(positionals, []);
|
|
14
|
+
|
|
13
15
|
// Resolved before the try, so a store that cannot be resolved fails without the note about backups.
|
|
14
16
|
const { backupDirectory } = getStorage();
|
|
15
17
|
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import type { RouteDef } from "../types";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
PresentedColumn,
|
|
4
|
+
PresentedColumnTaskCount,
|
|
5
|
+
} from "../presentation/column-presentation";
|
|
3
6
|
|
|
4
7
|
import { parseArgs } from "node:util";
|
|
5
8
|
|
|
6
9
|
import { column, project } from "@zinn-dev/core";
|
|
7
10
|
import {
|
|
11
|
+
canPrompt,
|
|
8
12
|
confirmAction,
|
|
9
13
|
failureMessage,
|
|
10
14
|
output,
|
|
11
15
|
quit,
|
|
12
|
-
|
|
16
|
+
UsageError,
|
|
17
|
+
validatePositionals,
|
|
13
18
|
validateUniqueOptions,
|
|
14
19
|
} from "../lib";
|
|
15
|
-
import {
|
|
20
|
+
import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
|
|
21
|
+
import { formatColumnList } from "../presentation/column-presentation";
|
|
16
22
|
import { formatDescriptionPreview } from "../presentation/description-presentation";
|
|
17
23
|
import { formatCellSeparator, formatRows } from "../presentation/row-layout";
|
|
18
24
|
import { formatSection } from "../presentation/section";
|
|
19
25
|
import { currentActor } from "../actor";
|
|
26
|
+
import { resolveProjectKey } from "../project";
|
|
20
27
|
|
|
21
28
|
type PresentedProject = { key: string; name: string; description: string | null };
|
|
22
29
|
type PresentedProjectView = PresentedProject & {
|
|
@@ -50,8 +57,6 @@ function formatProjectList(
|
|
|
50
57
|
);
|
|
51
58
|
}
|
|
52
59
|
|
|
53
|
-
type PresentedColumn = { project: string; name: string };
|
|
54
|
-
|
|
55
60
|
function presentColumn(columnMatch: { project_id: string; name: string }): PresentedColumn {
|
|
56
61
|
const columnProject = project.getById(columnMatch.project_id)!;
|
|
57
62
|
|
|
@@ -59,7 +64,7 @@ function presentColumn(columnMatch: { project_id: string; name: string }): Prese
|
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
function formatColumn(presented: PresentedColumn) {
|
|
62
|
-
return
|
|
67
|
+
return formatColumnList([presented], { showsProject: true });
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
export const projectRouter = {
|
|
@@ -73,15 +78,10 @@ export const projectRouter = {
|
|
|
73
78
|
tokens: true,
|
|
74
79
|
});
|
|
75
80
|
|
|
76
|
-
const projectKey = positionals[0];
|
|
77
|
-
|
|
78
|
-
if (projectKey == null) {
|
|
79
|
-
quit("Project key must be specified");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
validatePositionalCount(positionals, 1, "Only one project key can be specified");
|
|
83
|
-
|
|
84
81
|
validateUniqueOptions(tokens);
|
|
82
|
+
validatePositionals(positionals, ["<project-key>"]);
|
|
83
|
+
|
|
84
|
+
const projectKey = positionals[0]!;
|
|
85
85
|
|
|
86
86
|
try {
|
|
87
87
|
const createdProject = project.create(
|
|
@@ -99,13 +99,16 @@ Create a project with the default columns.
|
|
|
99
99
|
Project keys are stored in uppercase.
|
|
100
100
|
|
|
101
101
|
An omitted name defaults to the uppercase project key.
|
|
102
|
-
Names cannot be blank.
|
|
102
|
+
Names are trimmed and cannot be blank or contain line breaks or control characters.
|
|
103
103
|
Descriptions may contain multiple lines. If omitted, they are saved as null.
|
|
104
104
|
|
|
105
105
|
Example: zinn project create MDR --name "Macrodata Refinement"`,
|
|
106
106
|
},
|
|
107
107
|
list: {
|
|
108
|
-
run: () => {
|
|
108
|
+
run: (args: Array<string>) => {
|
|
109
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
110
|
+
validatePositionals(positionals, []);
|
|
111
|
+
|
|
109
112
|
const projects = project.getAll();
|
|
110
113
|
|
|
111
114
|
output(projects.map(presentProject), formatProjectList);
|
|
@@ -118,14 +121,10 @@ Example: zinn project list`,
|
|
|
118
121
|
},
|
|
119
122
|
view: {
|
|
120
123
|
run: (args: Array<string>) => {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
if (projectKey == null) {
|
|
124
|
-
quit("Project key must be specified");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
validatePositionalCount(args, 1, "Only one project key can be specified");
|
|
124
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
125
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
128
126
|
|
|
127
|
+
const projectKey = resolveProjectKey(positionals[0], { required: true })!;
|
|
129
128
|
const projectMatch = project.getByKey(projectKey);
|
|
130
129
|
|
|
131
130
|
if (projectMatch == null) {
|
|
@@ -150,7 +149,8 @@ Example: zinn project list`,
|
|
|
150
149
|
sections.push(formatSection("Description", viewedProject.description));
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
const columnTaskCounts =
|
|
152
|
+
const columnTaskCounts = formatColumnList(viewedProject.columns, {
|
|
153
|
+
showsTaskCounts: true,
|
|
154
154
|
archivedTaskCount: viewedProject.archivedTaskCount,
|
|
155
155
|
});
|
|
156
156
|
sections.push(formatSection("Columns", columnTaskCounts));
|
|
@@ -158,9 +158,11 @@ Example: zinn project list`,
|
|
|
158
158
|
return sections.join("\n\n");
|
|
159
159
|
});
|
|
160
160
|
},
|
|
161
|
-
help: `Usage: zinn project view <project-key>
|
|
161
|
+
help: `Usage: zinn project view [<project-key>]
|
|
162
162
|
|
|
163
163
|
Show a project with its description and the number of tasks in each column.
|
|
164
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
165
|
+
If no default project is set, the key is required.
|
|
164
166
|
The description prints in full, keeping its line breaks. Archived tasks are counted as one total.
|
|
165
167
|
|
|
166
168
|
Example: zinn project view MDR`,
|
|
@@ -169,52 +171,55 @@ Example: zinn project view MDR`,
|
|
|
169
171
|
run: (args) => {
|
|
170
172
|
const { values, positionals, tokens } = parseArgs({
|
|
171
173
|
args,
|
|
172
|
-
options: { name: { type: "string" }, description: { type: "string" } },
|
|
174
|
+
options: { name: { type: "string" }, description: { type: "string" }, ...textEditOptions },
|
|
173
175
|
allowPositionals: true,
|
|
174
176
|
strict: true,
|
|
175
177
|
tokens: true,
|
|
176
178
|
});
|
|
177
179
|
|
|
178
|
-
const projectKey = positionals[0];
|
|
179
|
-
|
|
180
|
-
if (projectKey == null) {
|
|
181
|
-
quit("Project key must be specified");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
validatePositionalCount(positionals, 1, "Only one project key can be specified");
|
|
185
|
-
|
|
186
180
|
validateUniqueOptions(tokens);
|
|
181
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
182
|
+
|
|
183
|
+
const projectKey = resolveProjectKey(positionals[0], { required: true })!;
|
|
184
|
+
const description = resolveTextEdit(values.description, values, "--description");
|
|
187
185
|
|
|
188
|
-
if (values.name === undefined &&
|
|
186
|
+
if (values.name === undefined && description === undefined) {
|
|
189
187
|
quit("Provide an edit flag: --name or --description");
|
|
190
188
|
}
|
|
191
189
|
|
|
192
190
|
const editedProject = project.edit(
|
|
193
|
-
{ projectKey, name: values.name, description
|
|
191
|
+
{ projectKey, name: values.name, description },
|
|
194
192
|
currentActor(),
|
|
195
193
|
);
|
|
196
194
|
output(presentProject(editedProject), formatProject);
|
|
197
195
|
},
|
|
198
|
-
help: `Usage: zinn project edit <project-key> [--name <text>] [--description <text>]
|
|
196
|
+
help: `Usage: zinn project edit [<project-key>] [--name <text>] [--description <text> ${textEditUsage}]
|
|
199
197
|
|
|
200
198
|
Change the supplied project fields. At least one edit flag is required.
|
|
199
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
200
|
+
If no default project is set, the key is required.
|
|
201
201
|
Use --description "" to clear the description.
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
${textEditHelp("--description")}
|
|
204
|
+
|
|
205
|
+
Examples:
|
|
206
|
+
zinn project edit MDR --name "Macrodata Refinement"
|
|
207
|
+
zinn project edit MDR --description "database" --replacing "board" --all`,
|
|
204
208
|
},
|
|
205
209
|
delete: {
|
|
206
210
|
run: (args: Array<string>) => {
|
|
207
|
-
const { values, positionals } = parseArgs({
|
|
211
|
+
const { values, positionals, tokens } = parseArgs({
|
|
208
212
|
args,
|
|
209
213
|
options: { yes: { type: "boolean" } },
|
|
210
214
|
allowPositionals: true,
|
|
211
215
|
strict: true,
|
|
216
|
+
tokens: true,
|
|
212
217
|
});
|
|
213
|
-
|
|
218
|
+
validateUniqueOptions(tokens);
|
|
219
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
214
220
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
221
|
+
const typedProjectKey = positionals[0];
|
|
222
|
+
const projectKey = resolveProjectKey(typedProjectKey, { required: true })!;
|
|
218
223
|
|
|
219
224
|
try {
|
|
220
225
|
const projectMatch = project.getByKey(projectKey);
|
|
@@ -223,9 +228,24 @@ Example: zinn project edit MDR --name "Macrodata Refinement"`,
|
|
|
223
228
|
throw new Error(`Project with key "${projectKey}" does not exist!`);
|
|
224
229
|
}
|
|
225
230
|
|
|
231
|
+
// Like `gh repo delete`: --yes never skips the prompt for a project the command did not name
|
|
232
|
+
const isYesIgnored = values.yes === true && typedProjectKey === undefined;
|
|
233
|
+
if (isYesIgnored && !canPrompt()) {
|
|
234
|
+
quit(
|
|
235
|
+
`Cannot delete the default project ${projectMatch.key} without a terminal. Type its key to use --yes: zinn project delete ${projectMatch.key} --yes`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (isYesIgnored) {
|
|
240
|
+
console.error("Warning: --yes is ignored because no project key was typed");
|
|
241
|
+
}
|
|
242
|
+
|
|
226
243
|
const canDelete = confirmAction(
|
|
227
244
|
`Are you sure you want to delete ${projectMatch.key} and all of its columns and tasks?`,
|
|
228
|
-
values.yes === true,
|
|
245
|
+
values.yes === true && typedProjectKey !== undefined,
|
|
246
|
+
typedProjectKey === undefined
|
|
247
|
+
? "Project deletion with --json needs a typed <project-key> and --yes"
|
|
248
|
+
: undefined,
|
|
229
249
|
);
|
|
230
250
|
|
|
231
251
|
if (canDelete) {
|
|
@@ -238,22 +258,24 @@ Example: zinn project edit MDR --name "Macrodata Refinement"`,
|
|
|
238
258
|
quit(failureMessage(err, "Something went wrong"));
|
|
239
259
|
}
|
|
240
260
|
},
|
|
241
|
-
help: `Usage: zinn project delete <project-key> [--yes]
|
|
261
|
+
help: `Usage: zinn project delete [<project-key>] [--yes]
|
|
242
262
|
|
|
243
263
|
Permanently delete a project and all of its columns and tasks after confirmation.
|
|
244
|
-
|
|
264
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
265
|
+
If no default project is set, the key is required.
|
|
266
|
+
With the default, confirmation is always required: --yes is ignored, and without a terminal the command refuses.
|
|
267
|
+
Use a typed project key and --yes to skip the prompt, including with --json.
|
|
245
268
|
|
|
246
269
|
Example: zinn project delete MDR`,
|
|
247
270
|
},
|
|
248
271
|
column: {
|
|
249
272
|
create: {
|
|
250
273
|
run: (args: Array<string>) => {
|
|
251
|
-
const
|
|
252
|
-
|
|
274
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
275
|
+
validatePositionals(positionals, ["<project-key>", "<column-name>"]);
|
|
253
276
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
277
|
+
const projectKey = positionals[0]!;
|
|
278
|
+
const columnName = positionals[1]!;
|
|
257
279
|
|
|
258
280
|
try {
|
|
259
281
|
const createdColumn = column.create({ projectKey, name: columnName }, currentActor());
|
|
@@ -271,19 +293,26 @@ Example: zinn project column create MDR "Boardlog"`,
|
|
|
271
293
|
},
|
|
272
294
|
list: {
|
|
273
295
|
run: (args: Array<string>) => {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
quit("Project key needs to be specified to list columns");
|
|
277
|
-
}
|
|
296
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
297
|
+
validatePositionals(positionals, ["[<project-key>]"]);
|
|
278
298
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const columns =
|
|
282
|
-
|
|
299
|
+
const projectKey = resolveProjectKey(positionals[0], { required: true })!;
|
|
300
|
+
const taskCounts = column.getTaskCountsByProjectKey(projectKey);
|
|
301
|
+
const columns = taskCounts.columns.map((columnCount) => ({
|
|
302
|
+
name: columnCount.column.name,
|
|
303
|
+
taskCount: columnCount.taskCount,
|
|
304
|
+
}));
|
|
305
|
+
output(columns, (presentedColumns) =>
|
|
306
|
+
formatColumnList(presentedColumns, {
|
|
307
|
+
showsTaskCounts: true,
|
|
308
|
+
}),
|
|
309
|
+
);
|
|
283
310
|
},
|
|
284
|
-
help: `Usage: zinn project column list <project-key>
|
|
311
|
+
help: `Usage: zinn project column list [<project-key>]
|
|
285
312
|
|
|
286
|
-
List a project's columns in board order.
|
|
313
|
+
List a project's columns in board order with their unarchived task counts.
|
|
314
|
+
An omitted project key uses defaultProject from settings, if present.
|
|
315
|
+
If no default project is set, the key is required.
|
|
287
316
|
|
|
288
317
|
Example: zinn project column list MDR`,
|
|
289
318
|
},
|
|
@@ -297,12 +326,8 @@ Example: zinn project column list MDR`,
|
|
|
297
326
|
tokens: true,
|
|
298
327
|
});
|
|
299
328
|
|
|
300
|
-
validatePositionalCount(
|
|
301
|
-
positionals,
|
|
302
|
-
2,
|
|
303
|
-
"Both the project key and the column name must be specified",
|
|
304
|
-
);
|
|
305
329
|
validateUniqueOptions(tokens);
|
|
330
|
+
validatePositionals(positionals, ["<project-key>", "<column-name>"]);
|
|
306
331
|
|
|
307
332
|
if (values.name === undefined) {
|
|
308
333
|
quit("Provide an edit flag: --name");
|
|
@@ -331,31 +356,30 @@ Example: zinn project column edit MDR "In Progress" --name "Refining"`,
|
|
|
331
356
|
},
|
|
332
357
|
order: {
|
|
333
358
|
run: (args: Array<string>) => {
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
359
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
360
|
+
/**
|
|
361
|
+
* The words every direction needs. Only whether they are there is checked here,
|
|
362
|
+
* since the direction decides whether a target column follows.
|
|
363
|
+
*/
|
|
364
|
+
const leadingWords = [
|
|
365
|
+
"<project-key>",
|
|
366
|
+
"<column-name>",
|
|
367
|
+
"{first|previous|next|last|before|after}",
|
|
368
|
+
];
|
|
369
|
+
validatePositionals(positionals.slice(0, leadingWords.length), leadingWords);
|
|
370
|
+
|
|
371
|
+
const projectKey = positionals[0]!;
|
|
372
|
+
const columnName = positionals[1]!;
|
|
373
|
+
const direction = positionals[2]!;
|
|
344
374
|
let orderedColumn: ReturnType<typeof column.order>;
|
|
345
375
|
|
|
346
376
|
switch (direction) {
|
|
347
377
|
case "before":
|
|
348
378
|
case "after": {
|
|
349
|
-
|
|
350
|
-
quit(`Target column must be specified for "${direction}"`);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (extraArgs.length > 0) {
|
|
354
|
-
quit("Only one target column can be specified");
|
|
355
|
-
}
|
|
379
|
+
validatePositionals(positionals, [...leadingWords, "<target-column-name>"]);
|
|
356
380
|
|
|
357
381
|
orderedColumn = column.order(
|
|
358
|
-
{ projectKey, columnName, direction, targetColumnName },
|
|
382
|
+
{ projectKey, columnName, direction, targetColumnName: positionals[3]! },
|
|
359
383
|
currentActor(),
|
|
360
384
|
);
|
|
361
385
|
break;
|
|
@@ -364,15 +388,13 @@ Example: zinn project column edit MDR "In Progress" --name "Refining"`,
|
|
|
364
388
|
case "previous":
|
|
365
389
|
case "next":
|
|
366
390
|
case "last": {
|
|
367
|
-
|
|
368
|
-
quit(`Order direction "${direction}" does not accept a target column`);
|
|
369
|
-
}
|
|
391
|
+
validatePositionals(positionals, leadingWords);
|
|
370
392
|
|
|
371
393
|
orderedColumn = column.order({ projectKey, columnName, direction }, currentActor());
|
|
372
394
|
break;
|
|
373
395
|
}
|
|
374
396
|
default:
|
|
375
|
-
|
|
397
|
+
throw new UsageError(`Unknown order direction "${direction}"`);
|
|
376
398
|
}
|
|
377
399
|
|
|
378
400
|
// TODO: maybe also print the new full column state?
|
|
@@ -4,11 +4,12 @@ import { parseArgs } from "node:util";
|
|
|
4
4
|
import { reindex } from "@zinn-dev/core";
|
|
5
5
|
|
|
6
6
|
import { reportLockWait } from "../database";
|
|
7
|
-
import { output } from "../lib";
|
|
7
|
+
import { output, validatePositionals } from "../lib";
|
|
8
8
|
|
|
9
9
|
export const reindexCommand = {
|
|
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 result = reindex.run({ onWait: reportLockWait });
|
|
14
15
|
|