@zinn-dev/cli 0.16.0 → 0.17.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 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
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "A kanban workflow in the terminal.",
5
5
  "license": "MIT",
6
6
  "bugs": {
@@ -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
+ }
@@ -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,8 +1,7 @@
1
- import type { TaskPriority } from "@zinn-dev/core";
2
1
  import type { RouteDef } from "../types";
3
2
 
4
- import { parseArgs, styleText } from "node:util";
5
- import { task, project, column } from "@zinn-dev/core";
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,14 @@ import {
12
11
  validateUniqueOptions,
13
12
  } from "../lib";
14
13
  import { formatRelations, presentRelations, relationRouter } from "./relation-router";
15
- import { TASK_DESCRIPTION_PREVIEW_LENGTH } from "../constant";
16
14
  import { currentActor } from "../actor";
17
-
18
- function formatTaskDescriptionPreview(description: string | null) {
19
- if (description == null) {
20
- return "";
21
- }
22
-
23
- const normalizedDescription = description.replace(/\s+/g, " ").trim();
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
- }
15
+ import {
16
+ formatTask,
17
+ formatTaskList,
18
+ formatTaskMove,
19
+ formatTaskWithStatus,
20
+ presentTask,
21
+ } from "../presentation/task-presentation";
101
22
 
102
23
  export const taskRouter = {
103
24
  edit: {
@@ -242,34 +163,9 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
242
163
 
243
164
  const tasks = task.getAll({ projectKey, archive });
244
165
 
245
- output(tasks.map(presentTask), (presentedTasks) => {
246
- const longestKeyLength = presentedTasks.reduce(
247
- (prev, current) => Math.max(prev, current.key.length),
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
- });
166
+ output(tasks.map(presentTask), (presentedTasks) =>
167
+ formatTaskList(presentedTasks, { showsStatus: showsAll }),
168
+ );
273
169
  },
274
170
  help: `Usage: zinn task list [project-key] [--archived | --all]
275
171