@zinn-dev/cli 0.16.0 → 0.18.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 +25 -1
- package/index.ts +5 -0
- package/package.json +2 -2
- package/src/presentation/task-presentation.ts +118 -0
- package/src/routes/comment-router.ts +121 -0
- package/src/routes/project-router.ts +38 -1
- package/src/routes/relation-router.ts +4 -6
- package/src/routes/task-router.ts +31 -121
package/README.md
CHANGED
|
@@ -28,9 +28,12 @@ You can list projects or inspect a project's columns with:
|
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
30
|
zinn project list
|
|
31
|
+
zinn project view MDR
|
|
31
32
|
zinn project column list MDR
|
|
32
33
|
```
|
|
33
34
|
|
|
35
|
+
`project view` prints the project and its unarchived tasks. It's the same list as you would get with `zinn task list <project-key>`.
|
|
36
|
+
|
|
34
37
|
Rename a project:
|
|
35
38
|
|
|
36
39
|
```sh
|
|
@@ -124,6 +127,27 @@ Note that a deletion happens _without_ confirmation.
|
|
|
124
127
|
|
|
125
128
|
Use `task relation create --help` to discover types.
|
|
126
129
|
|
|
130
|
+
## Task comments
|
|
131
|
+
|
|
132
|
+
Add and list comments on a task:
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
zinn task comment create MDR-1 --text "Ready for review"
|
|
136
|
+
zinn task comment list MDR-1
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Comments receive keys per task like `MDR-1#1`.
|
|
140
|
+
`task view` includes the task's comments.
|
|
141
|
+
|
|
142
|
+
Edit or delete a comment using its key:
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
zinn task comment edit MDR-1#1 --text "Approved"
|
|
146
|
+
zinn task comment delete MDR-1#1
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Deletion asks for confirmation. Comments can be added to archived tasks. Comment mutations are recorded in the activity log without changing the task's modification timestamp.
|
|
150
|
+
|
|
127
151
|
## Edit tasks
|
|
128
152
|
|
|
129
153
|
Edit a task's title, description, priority, or labels:
|
|
@@ -214,7 +238,7 @@ Use `none` to clear priority. Omitting `--priority` on edits preserves it. Task
|
|
|
214
238
|
|
|
215
239
|
## Activity
|
|
216
240
|
|
|
217
|
-
Zinn keeps an activity log of changes made to a task like creating, editing, moving, reordering, archiving, unarchiving and deleting it, its labels and its
|
|
241
|
+
Zinn keeps an activity log of changes made to a task like creating, editing, moving, reordering, archiving, unarchiving and deleting it, its labels, its relations, and its comments. Each log also says _who_ made the change.
|
|
218
242
|
Note that this data is not yet surfaced by any command yet.
|
|
219
243
|
|
|
220
244
|
When a coding agent performs a mutation with `zinn`, the change is recorded under that agent's name.
|
package/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ Options:
|
|
|
16
16
|
Commands:
|
|
17
17
|
project create
|
|
18
18
|
project list
|
|
19
|
+
project view
|
|
19
20
|
project delete
|
|
20
21
|
project column create
|
|
21
22
|
project column list
|
|
@@ -31,6 +32,10 @@ Commands:
|
|
|
31
32
|
task relation create
|
|
32
33
|
task relation list
|
|
33
34
|
task relation delete
|
|
35
|
+
task comment create
|
|
36
|
+
task comment list
|
|
37
|
+
task comment edit
|
|
38
|
+
task comment delete
|
|
34
39
|
task label add
|
|
35
40
|
task label remove
|
|
36
41
|
label create
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zinn-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "A kanban workflow in the terminal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bugs": {
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@zinn-dev/core": "0.
|
|
45
|
+
"@zinn-dev/core": "0.13.0"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { TaskPriority, TaskWithKey } from "@zinn-dev/core";
|
|
2
|
+
|
|
3
|
+
import { styleText } from "node:util";
|
|
4
|
+
import { column, task } from "@zinn-dev/core";
|
|
5
|
+
|
|
6
|
+
import { TASK_DESCRIPTION_PREVIEW_LENGTH } from "../constant";
|
|
7
|
+
|
|
8
|
+
function formatTaskDescriptionPreview(description: string | null) {
|
|
9
|
+
if (description == null) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const normalizedDescription = description.replace(/\s+/g, " ").trim();
|
|
14
|
+
|
|
15
|
+
if (normalizedDescription.length <= TASK_DESCRIPTION_PREVIEW_LENGTH) {
|
|
16
|
+
return normalizedDescription;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return `${normalizedDescription.slice(0, TASK_DESCRIPTION_PREVIEW_LENGTH - 1).trimEnd()}…`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type PresentedTask = {
|
|
23
|
+
key: string;
|
|
24
|
+
status: "Active" | "Archived";
|
|
25
|
+
column: string;
|
|
26
|
+
title: string;
|
|
27
|
+
description: string | null;
|
|
28
|
+
priority: TaskPriority | null;
|
|
29
|
+
labels: Array<string>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function formatTaskPriorityMarker(priority: TaskPriority | null) {
|
|
33
|
+
if (priority == null) {
|
|
34
|
+
return "-";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return priority[0]!.toUpperCase();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function formatTaskColumn(columnName: string, width = columnName.length) {
|
|
41
|
+
const paddedColumnName = columnName.padEnd(width);
|
|
42
|
+
|
|
43
|
+
// TODO: Derive column colors from column roles once roles exist instead of relying on names.
|
|
44
|
+
if (columnName === "Backlog") {
|
|
45
|
+
return styleText("gray", paddedColumnName);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (columnName === "Done") {
|
|
49
|
+
return styleText("green", paddedColumnName);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return paddedColumnName;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function presentTask(taskMatch: TaskWithKey): PresentedTask {
|
|
56
|
+
return {
|
|
57
|
+
key: taskMatch.key,
|
|
58
|
+
status: taskMatch.archived_at == null ? "Active" : "Archived",
|
|
59
|
+
column: column.getById(taskMatch.column_id)!.name,
|
|
60
|
+
title: taskMatch.title,
|
|
61
|
+
description: taskMatch.description,
|
|
62
|
+
priority: taskMatch.priority,
|
|
63
|
+
labels: task.label.getAll(taskMatch.key).map((label) => label.name),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function formatTask(presented: PresentedTask, options: { showsStatus?: boolean } = {}) {
|
|
68
|
+
const status = options.showsStatus ? ` | ${presented.status}` : "";
|
|
69
|
+
const column = formatTaskColumn(presented.column);
|
|
70
|
+
const description = presented.description == null ? "" : ` | ${presented.description}`;
|
|
71
|
+
|
|
72
|
+
const priority = presented.priority == null ? "" : ` | Priority: ${presented.priority}`;
|
|
73
|
+
const labelText =
|
|
74
|
+
presented.labels.length === 0 ? "" : ` | Labels: ${presented.labels.join(", ")}`;
|
|
75
|
+
|
|
76
|
+
return `${presented.key}${status} | ${column} | ${presented.title}${description}${priority}${labelText}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function formatTaskWithStatus(presented: PresentedTask) {
|
|
80
|
+
return formatTask(presented, { showsStatus: true });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function formatTaskMove(presented: PresentedTask) {
|
|
84
|
+
return `${presented.key} | ${formatTaskColumn(presented.column)}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function formatTaskList(
|
|
88
|
+
presentedTasks: Array<PresentedTask>,
|
|
89
|
+
options: { showsStatus?: boolean } = {},
|
|
90
|
+
) {
|
|
91
|
+
const longestKeyLength = presentedTasks.reduce(
|
|
92
|
+
(previousLength, currentTask) => Math.max(previousLength, currentTask.key.length),
|
|
93
|
+
0,
|
|
94
|
+
);
|
|
95
|
+
const longestColumnNameLength = presentedTasks.reduce(
|
|
96
|
+
(previousLength, currentTask) => Math.max(previousLength, currentTask.column.length),
|
|
97
|
+
0,
|
|
98
|
+
);
|
|
99
|
+
const longestStatusLength = presentedTasks.reduce(
|
|
100
|
+
(previousLength, currentTask) => Math.max(previousLength, currentTask.status.length),
|
|
101
|
+
0,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return presentedTasks
|
|
105
|
+
.map((presentedTask) => {
|
|
106
|
+
const status = options.showsStatus
|
|
107
|
+
? ` | ${presentedTask.status.padEnd(longestStatusLength)}`
|
|
108
|
+
: "";
|
|
109
|
+
const descriptionPreview = formatTaskDescriptionPreview(presentedTask.description);
|
|
110
|
+
const description =
|
|
111
|
+
presentedTask.description == null ? "" : ` | ${descriptionPreview}`;
|
|
112
|
+
const priority = formatTaskPriorityMarker(presentedTask.priority);
|
|
113
|
+
const column = formatTaskColumn(presentedTask.column, longestColumnNameLength);
|
|
114
|
+
|
|
115
|
+
return `${presentedTask.key.padEnd(longestKeyLength)}${status} | ${column} | ${priority} | ${presentedTask.title}${description}`;
|
|
116
|
+
})
|
|
117
|
+
.join("\n");
|
|
118
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { CommentWithKey } from "@zinn-dev/core";
|
|
2
|
+
import type { RouteDef } from "../types";
|
|
3
|
+
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { comment } from "@zinn-dev/core";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
confirmAction,
|
|
9
|
+
output,
|
|
10
|
+
quit,
|
|
11
|
+
validatePositionalCount,
|
|
12
|
+
validateUniqueOptions,
|
|
13
|
+
} from "../lib";
|
|
14
|
+
import { currentActor } from "../actor";
|
|
15
|
+
|
|
16
|
+
type PresentedComment = Pick<CommentWithKey, "key" | "text" | "created_at" | "updated_at">;
|
|
17
|
+
|
|
18
|
+
function presentComment(commentMatch: CommentWithKey): PresentedComment {
|
|
19
|
+
return {
|
|
20
|
+
key: commentMatch.key,
|
|
21
|
+
text: commentMatch.text,
|
|
22
|
+
created_at: commentMatch.created_at,
|
|
23
|
+
updated_at: commentMatch.updated_at,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function presentComments(taskKey: string) {
|
|
28
|
+
return comment.getAll(taskKey).map(presentComment);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function formatComment(commentMatch: PresentedComment) {
|
|
32
|
+
const continuationIndent = " ".repeat(`${commentMatch.key} | `.length);
|
|
33
|
+
const text = commentMatch.text.split(/\r?\n/).join(`\n${continuationIndent}`);
|
|
34
|
+
return `${commentMatch.key} | ${text}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function formatComments(comments: Array<PresentedComment>) {
|
|
38
|
+
return comments.map(formatComment).join("\n");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
|
|
42
|
+
const { values, positionals, tokens } = parseArgs({
|
|
43
|
+
args,
|
|
44
|
+
options: { text: { type: "string" } },
|
|
45
|
+
allowPositionals: true,
|
|
46
|
+
strict: true,
|
|
47
|
+
tokens: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
validatePositionalCount(positionals, 1, `Exactly one ${entityName} key is required`);
|
|
51
|
+
validateUniqueOptions(tokens);
|
|
52
|
+
|
|
53
|
+
if (values.text === undefined) {
|
|
54
|
+
quit("Comment text must be specified with --text");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return { key: positionals[0]!, text: values.text };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const commentRouter = {
|
|
61
|
+
create: {
|
|
62
|
+
run: (args) => {
|
|
63
|
+
const props = parseTextArgs(args, "task");
|
|
64
|
+
const created = comment.create({ taskKey: props.key, text: props.text }, currentActor());
|
|
65
|
+
output(presentComment(created), formatComment);
|
|
66
|
+
},
|
|
67
|
+
help: `Usage: zinn task comment create <task-key> --text <text>
|
|
68
|
+
|
|
69
|
+
Add a comment to a task. Comment text cannot be blank.
|
|
70
|
+
Archived tasks can be commented on.
|
|
71
|
+
|
|
72
|
+
Example: zinn task comment create MDR-1 --text "Ready for review"`,
|
|
73
|
+
},
|
|
74
|
+
list: {
|
|
75
|
+
run: (args) => {
|
|
76
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
77
|
+
validatePositionalCount(positionals, 1, "Exactly one task key is required");
|
|
78
|
+
output(presentComments(positionals[0]!), formatComments);
|
|
79
|
+
},
|
|
80
|
+
help: `Usage: zinn task comment list <task-key>
|
|
81
|
+
|
|
82
|
+
List a task's comments by oldest first.
|
|
83
|
+
|
|
84
|
+
Example: zinn task comment list MDR-1`,
|
|
85
|
+
},
|
|
86
|
+
edit: {
|
|
87
|
+
run: (args) => {
|
|
88
|
+
const props = parseTextArgs(args, "comment");
|
|
89
|
+
const edited = comment.edit({ commentKey: props.key, text: props.text }, currentActor());
|
|
90
|
+
output(presentComment(edited), formatComment);
|
|
91
|
+
},
|
|
92
|
+
help: `Usage: zinn task comment edit <comment-key> --text <text>
|
|
93
|
+
|
|
94
|
+
Replace a comment's text. Comment text cannot be blank.
|
|
95
|
+
|
|
96
|
+
Example: zinn task comment edit MDR-1#2 --text "Approved"`,
|
|
97
|
+
},
|
|
98
|
+
delete: {
|
|
99
|
+
run: (args) => {
|
|
100
|
+
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
101
|
+
validatePositionalCount(positionals, 1, "Exactly one comment key is required");
|
|
102
|
+
|
|
103
|
+
const commentMatch = comment.getByKey(positionals[0]!);
|
|
104
|
+
const canDelete = confirmAction(`Are you sure you want to delete ${commentMatch.key}?`);
|
|
105
|
+
const presented = presentComment(commentMatch);
|
|
106
|
+
|
|
107
|
+
if (!canDelete) {
|
|
108
|
+
output(presented, (entry) => `Deletion cancelled for ${entry.key}`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
comment.delete({ commentKey: commentMatch.key }, currentActor());
|
|
113
|
+
output(presented, (entry) => `Deleted ${entry.key}`);
|
|
114
|
+
},
|
|
115
|
+
help: `Usage: zinn task comment delete <comment-key>
|
|
116
|
+
|
|
117
|
+
Permanently delete a comment after confirmation.
|
|
118
|
+
|
|
119
|
+
Example: zinn task comment delete MDR-1#2`,
|
|
120
|
+
},
|
|
121
|
+
} satisfies RouteDef;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { RouteDef } from "../types";
|
|
2
|
+
import type { PresentedTask } from "../presentation/task-presentation";
|
|
2
3
|
|
|
3
4
|
import { parseArgs } from "node:util";
|
|
4
5
|
|
|
5
|
-
import { column, project } from "@zinn-dev/core";
|
|
6
|
+
import { column, project, task } from "@zinn-dev/core";
|
|
6
7
|
import {
|
|
7
8
|
confirmAction,
|
|
8
9
|
output,
|
|
@@ -10,8 +11,10 @@ import {
|
|
|
10
11
|
validatePositionalCount,
|
|
11
12
|
validateUniqueOptions,
|
|
12
13
|
} from "../lib";
|
|
14
|
+
import { formatTaskList, presentTask } from "../presentation/task-presentation";
|
|
13
15
|
|
|
14
16
|
type PresentedProject = { key: string; name: string };
|
|
17
|
+
type PresentedProjectView = PresentedProject & { tasks: Array<PresentedTask> };
|
|
15
18
|
|
|
16
19
|
function presentProject(projectMatch: PresentedProject): PresentedProject {
|
|
17
20
|
return { key: projectMatch.key, name: projectMatch.name };
|
|
@@ -116,6 +119,40 @@ Example: zinn project create MDR --name "Macrodata Refinement"`,
|
|
|
116
119
|
List projects and their keys.
|
|
117
120
|
|
|
118
121
|
Example: zinn project list`,
|
|
122
|
+
},
|
|
123
|
+
view: {
|
|
124
|
+
run: (args: Array<string>) => {
|
|
125
|
+
const projectKey = args[0];
|
|
126
|
+
|
|
127
|
+
if (projectKey == null) {
|
|
128
|
+
quit("Project key must be specified");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
validatePositionalCount(args, 1, "Only one project key can be specified");
|
|
132
|
+
|
|
133
|
+
const projectMatch = project.getByKey(projectKey);
|
|
134
|
+
|
|
135
|
+
if (projectMatch == null) {
|
|
136
|
+
quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist!`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const presentedProject: PresentedProjectView = {
|
|
140
|
+
...presentProject(projectMatch),
|
|
141
|
+
tasks: task.getAll({ projectKey, archive: "active" }).map(presentTask),
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
output(presentedProject, (viewedProject) => {
|
|
145
|
+
const projectHeader = formatProject(viewedProject);
|
|
146
|
+
const taskList = formatTaskList(viewedProject.tasks);
|
|
147
|
+
|
|
148
|
+
return taskList.length === 0 ? projectHeader : `${projectHeader}\n\n${taskList}`;
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
help: `Usage: zinn project view <project-key>
|
|
152
|
+
|
|
153
|
+
Show a project and its active tasks in board order.
|
|
154
|
+
|
|
155
|
+
Example: zinn project view MDR`,
|
|
119
156
|
},
|
|
120
157
|
delete: {
|
|
121
158
|
run: (args: Array<string>) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RelationCreateInput } from "@zinn-dev/core";
|
|
1
|
+
import type { RelationCreateInput, TaskWithKey } from "@zinn-dev/core";
|
|
2
2
|
import type { RouteDef } from "../types";
|
|
3
3
|
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
@@ -15,10 +15,8 @@ type PresentedRelation = {
|
|
|
15
15
|
task: { key: string; title: string; status: "Active" | "Archived" };
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export function presentRelations(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return relation.getAll(taskKey, { include: { tasks: true } }).map((entry) => {
|
|
18
|
+
export function presentRelations(taskMatch: TaskWithKey): Array<PresentedRelation> {
|
|
19
|
+
return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
|
|
22
20
|
const isSource = entry.source_task_id === taskMatch.id;
|
|
23
21
|
const other = isSource ? entry.target : entry.source;
|
|
24
22
|
if (other == null) {
|
|
@@ -167,7 +165,7 @@ Example: zinn task relation create APP-1 APP-2 --type dependency`,
|
|
|
167
165
|
run: (args) => {
|
|
168
166
|
const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
|
|
169
167
|
validatePositionalCount(positionals, 1, "Provide exactly one task key");
|
|
170
|
-
output(presentRelations(positionals[0]!), formatRelations);
|
|
168
|
+
output(presentRelations(task.getByKey(positionals[0]!)), formatRelations);
|
|
171
169
|
},
|
|
172
170
|
help: `Usage: zinn task relation list <task-key>
|
|
173
171
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { TaskPriority } from "@zinn-dev/core";
|
|
2
1
|
import type { RouteDef } from "../types";
|
|
3
2
|
|
|
4
|
-
import { parseArgs
|
|
5
|
-
import { task, project
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { task, project } from "@zinn-dev/core";
|
|
6
5
|
|
|
7
6
|
import {
|
|
8
7
|
confirmAction,
|
|
@@ -12,92 +11,15 @@ import {
|
|
|
12
11
|
validateUniqueOptions,
|
|
13
12
|
} from "../lib";
|
|
14
13
|
import { formatRelations, presentRelations, relationRouter } from "./relation-router";
|
|
15
|
-
import {
|
|
14
|
+
import { commentRouter, formatComments, presentComments } from "./comment-router";
|
|
16
15
|
import { currentActor } from "../actor";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (normalizedDescription.length <= TASK_DESCRIPTION_PREVIEW_LENGTH) {
|
|
26
|
-
return normalizedDescription;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return `${normalizedDescription.slice(0, TASK_DESCRIPTION_PREVIEW_LENGTH - 1).trimEnd()}…`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type PresentedTask = {
|
|
33
|
-
key: string;
|
|
34
|
-
status: "Active" | "Archived";
|
|
35
|
-
column: string;
|
|
36
|
-
title: string;
|
|
37
|
-
description: string | null;
|
|
38
|
-
priority: TaskPriority | null;
|
|
39
|
-
labels: Array<string>;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
function formatTaskPriorityMarker(priority: TaskPriority | null) {
|
|
43
|
-
if (priority == null) {
|
|
44
|
-
return "-";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return priority[0]!.toUpperCase();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function formatTaskColumn(columnName: string, width = columnName.length) {
|
|
51
|
-
const paddedColumnName = columnName.padEnd(width);
|
|
52
|
-
|
|
53
|
-
// TODO: Derive column colors from column roles once roles exist instead of relying on names.
|
|
54
|
-
if (columnName === "Backlog") {
|
|
55
|
-
return styleText("gray", paddedColumnName);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (columnName === "Done") {
|
|
59
|
-
return styleText("green", paddedColumnName);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return paddedColumnName;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function presentTask(taskMatch: ReturnType<typeof task.getByKey>): PresentedTask {
|
|
66
|
-
return {
|
|
67
|
-
key: taskMatch.key,
|
|
68
|
-
status: taskMatch.archived_at == null ? "Active" : "Archived",
|
|
69
|
-
column: column.getById(taskMatch.column_id)!.name,
|
|
70
|
-
title: taskMatch.title,
|
|
71
|
-
description: taskMatch.description,
|
|
72
|
-
priority: taskMatch.priority,
|
|
73
|
-
labels: task.label.getAll(taskMatch.key).map((label) => label.name),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// TODO: a CLI row formatter that accepts text columns and joins them with " | " would be useful
|
|
78
|
-
// Reuse it across task list/view and other command output in a separate change.
|
|
79
|
-
function formatTask(
|
|
80
|
-
presented: PresentedTask,
|
|
81
|
-
options: { showsStatus?: boolean } = {},
|
|
82
|
-
) {
|
|
83
|
-
const status = options.showsStatus ? ` | ${presented.status}` : "";
|
|
84
|
-
const column = formatTaskColumn(presented.column);
|
|
85
|
-
const description = presented.description == null ? "" : ` | ${presented.description}`;
|
|
86
|
-
|
|
87
|
-
const priority = presented.priority == null ? "" : ` | Priority: ${presented.priority}`;
|
|
88
|
-
const labelText =
|
|
89
|
-
presented.labels.length === 0 ? "" : ` | Labels: ${presented.labels.join(", ")}`;
|
|
90
|
-
|
|
91
|
-
return `${presented.key}${status} | ${column} | ${presented.title}${description}${priority}${labelText}`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function formatTaskWithStatus(presented: PresentedTask) {
|
|
95
|
-
return formatTask(presented, { showsStatus: true });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function formatTaskMove(presented: PresentedTask) {
|
|
99
|
-
return `${presented.key} | ${formatTaskColumn(presented.column)}`;
|
|
100
|
-
}
|
|
16
|
+
import {
|
|
17
|
+
formatTask,
|
|
18
|
+
formatTaskList,
|
|
19
|
+
formatTaskMove,
|
|
20
|
+
formatTaskWithStatus,
|
|
21
|
+
presentTask,
|
|
22
|
+
} from "../presentation/task-presentation";
|
|
101
23
|
|
|
102
24
|
export const taskRouter = {
|
|
103
25
|
edit: {
|
|
@@ -242,34 +164,9 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
|
|
|
242
164
|
|
|
243
165
|
const tasks = task.getAll({ projectKey, archive });
|
|
244
166
|
|
|
245
|
-
output(tasks.map(presentTask), (presentedTasks) =>
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
0,
|
|
249
|
-
);
|
|
250
|
-
const longestColumnNameLength = presentedTasks.reduce(
|
|
251
|
-
(previousLength, currentTask) =>
|
|
252
|
-
Math.max(previousLength, currentTask.column.length),
|
|
253
|
-
0,
|
|
254
|
-
);
|
|
255
|
-
const longestStatusLength = presentedTasks.reduce(
|
|
256
|
-
(prev, current) => Math.max(prev, current.status.length),
|
|
257
|
-
0,
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
return presentedTasks
|
|
261
|
-
.map((t) => {
|
|
262
|
-
// TODO: console output formatting for standardizied output
|
|
263
|
-
const status = showsAll ? ` | ${t.status.padEnd(longestStatusLength)}` : "";
|
|
264
|
-
const descriptionPreview = formatTaskDescriptionPreview(t.description);
|
|
265
|
-
const description = t.description == null ? "" : ` | ${descriptionPreview}`;
|
|
266
|
-
const priority = formatTaskPriorityMarker(t.priority);
|
|
267
|
-
const column = formatTaskColumn(t.column, longestColumnNameLength);
|
|
268
|
-
|
|
269
|
-
return `${t.key.padEnd(longestKeyLength)}${status} | ${column} | ${priority} | ${t.title}${description}`;
|
|
270
|
-
})
|
|
271
|
-
.join("\n");
|
|
272
|
-
});
|
|
167
|
+
output(tasks.map(presentTask), (presentedTasks) =>
|
|
168
|
+
formatTaskList(presentedTasks, { showsStatus: showsAll }),
|
|
169
|
+
);
|
|
273
170
|
},
|
|
274
171
|
help: `Usage: zinn task list [project-key] [--archived | --all]
|
|
275
172
|
|
|
@@ -288,20 +185,32 @@ Example: zinn task list MDR --all`,
|
|
|
288
185
|
}
|
|
289
186
|
|
|
290
187
|
const taskMatch = task.getByKey(taskKey);
|
|
291
|
-
const viewedTask = {
|
|
188
|
+
const viewedTask = {
|
|
189
|
+
...presentTask(taskMatch),
|
|
190
|
+
relations: presentRelations(taskMatch),
|
|
191
|
+
comments: presentComments(taskMatch.key),
|
|
192
|
+
};
|
|
292
193
|
|
|
293
194
|
output(viewedTask, (t) => {
|
|
294
195
|
const relations = formatRelations(t.relations);
|
|
196
|
+
const comments = formatComments(t.comments);
|
|
295
197
|
const formattedTask = formatTask(t);
|
|
198
|
+
const sections = [formattedTask];
|
|
199
|
+
|
|
200
|
+
if (relations.length > 0) {
|
|
201
|
+
sections.push(`Relations:\n${relations}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (comments.length > 0) {
|
|
205
|
+
sections.push(`Comments:\n${comments}`);
|
|
206
|
+
}
|
|
296
207
|
|
|
297
|
-
return
|
|
298
|
-
? `${formattedTask}\n\nRelations:\n${relations}`
|
|
299
|
-
: formattedTask;
|
|
208
|
+
return sections.join("\n\n");
|
|
300
209
|
});
|
|
301
210
|
},
|
|
302
211
|
help: `Usage: zinn task view <task-key>
|
|
303
212
|
|
|
304
|
-
Show a task with its current column, description, priority, labels, and
|
|
213
|
+
Show a task with its current column, description, priority, labels, relations, and comments.
|
|
305
214
|
|
|
306
215
|
Example: zinn task view MDR-1`,
|
|
307
216
|
},
|
|
@@ -449,6 +358,7 @@ Unarchive a task at the bottom of its previous column.
|
|
|
449
358
|
Example: zinn task unarchive MDR-1`,
|
|
450
359
|
},
|
|
451
360
|
relation: relationRouter,
|
|
361
|
+
comment: commentRouter,
|
|
452
362
|
label: {
|
|
453
363
|
add: {
|
|
454
364
|
run: (args) => {
|