@zinn-dev/cli 0.12.0 → 0.13.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/index.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
+ import { isHelpFlag } from "./src/lib";
4
+
3
5
  const args = process.argv.slice(2);
4
6
 
5
- if (args.length === 0 || ["-h", "--help"].includes(args[0]!)) {
7
+ if (args.length === 0 || isHelpFlag(args[0]!)) {
6
8
  console.info(`ZINN - A kanban workflow in the terminal
7
9
 
8
10
  Usage: zinn <command>
9
11
 
10
12
  Options:
11
13
  -h, --help Show help
14
+ --json Print command output as JSON
12
15
 
13
16
  Commands:
14
17
  project create
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "A kanban workflow in the terminal.",
5
5
  "license": "MIT",
6
6
  "bugs": {
package/src/lib.ts CHANGED
@@ -1,9 +1,47 @@
1
1
  import type { parseArgs } from "node:util";
2
2
 
3
3
  type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
4
+ type OutputMode = "text" | "json";
5
+
6
+ let outputMode: OutputMode = "text";
7
+
8
+ export function setOutputMode(mode: OutputMode) {
9
+ outputMode = mode;
10
+ }
11
+
12
+ export function isJsonFlag(flag: string) {
13
+ return flag === "--json";
14
+ }
15
+
16
+ export function output<T>(data: T, transformToString: (data: T) => string) {
17
+ if (outputMode === "json") {
18
+ console.info(JSON.stringify(data, null, 2));
19
+ return;
20
+ }
21
+
22
+ const dataText = transformToString(data);
23
+
24
+ if (dataText.length > 0) {
25
+ console.info(dataText);
26
+ }
27
+ }
28
+
29
+ export function confirmAction(message: string) {
30
+ if (outputMode === "json") {
31
+ // FIXME: confirmations currently break JSON outputs with jq parse error
32
+ quit("Commands that ask for confirmation cannot be used with --json yet");
33
+ }
34
+
35
+ return confirm(message);
36
+ }
4
37
 
5
38
  export function quit(reason: string): never {
6
- console.error(reason);
39
+ if (outputMode === "json") {
40
+ console.error(JSON.stringify({ error: { message: reason } }, null, 2));
41
+ } else {
42
+ console.error(reason);
43
+ }
44
+
7
45
  process.exit(1);
8
46
  }
9
47
 
@@ -33,3 +71,7 @@ export function validateUniqueOptions(tokens: ParsedTokens, repeatableOptions: A
33
71
  parsedArgs.add(token.name);
34
72
  }
35
73
  }
74
+
75
+ export function isHelpFlag(flag: string) {
76
+ return ["-h", "--help"].includes(flag);
77
+ }
@@ -1,9 +1,26 @@
1
+ import type { Label } from "@zinn-dev/core";
1
2
  import type { RouteDef } from "../types";
2
3
 
3
4
  import { parseArgs } from "node:util";
4
5
  import { label, labelCreateSchema, labelDeleteSchema } from "@zinn-dev/core";
5
6
 
6
- import { quit, validatePositionalCount, validateUniqueOptions } from "../lib";
7
+ import {
8
+ confirmAction,
9
+ output,
10
+ quit,
11
+ validatePositionalCount,
12
+ validateUniqueOptions,
13
+ } from "../lib";
14
+
15
+ type PresentedLabel = Omit<Label, "id">;
16
+
17
+ function presentLabel(labelMatch: Label): PresentedLabel {
18
+ return { name: labelMatch.name, color: labelMatch.color, description: labelMatch.description };
19
+ }
20
+
21
+ function formatLabel(presented: PresentedLabel) {
22
+ return `${presented.name} | ${presented.color} | ${presented.description}`;
23
+ }
7
24
 
8
25
  export const labelRouter = {
9
26
  create: {
@@ -23,7 +40,7 @@ export const labelRouter = {
23
40
  const input = labelCreateSchema.parse({ name: positionals[0], ...values });
24
41
  const created = label.create(input);
25
42
 
26
- console.info(`${created.name} | ${created.color} | ${created.description}`);
43
+ output(presentLabel(created), formatLabel);
27
44
  },
28
45
  help: `Usage: zinn label create <name> [--description <text>] [--color <color>]
29
46
 
@@ -36,9 +53,7 @@ Example: zinn label create bug --description "Unexpected behavior" --color red`,
36
53
  list: {
37
54
  run: (args) => {
38
55
  parseArgs({ args, strict: true, allowPositionals: false });
39
- for (const entry of label.getAll()) {
40
- console.info(`${entry.name} | ${entry.color} | ${entry.description}`);
41
- }
56
+ output(label.getAll().map(presentLabel), (labels) => labels.map(formatLabel).join("\n"));
42
57
  },
43
58
  help: `Usage: zinn label list
44
59
 
@@ -55,16 +70,16 @@ List all global label definitions.`,
55
70
  quit(`A label with name "${props.name}" does not exist`);
56
71
  }
57
72
 
58
- const canDelete = confirm(
73
+ const canDelete = confirmAction(
59
74
  `Are you sure you want to delete label "${labelMatch.name}" and remove it from all tasks?`,
60
75
  );
61
76
  if (!canDelete) {
62
- console.info(`Deletion cancelled for label "${labelMatch.name}"`);
77
+ output(presentLabel(labelMatch), (l) => `Deletion cancelled for label "${l.name}"`);
63
78
  return;
64
79
  }
65
80
 
66
81
  const deleted = label.delete(props);
67
- console.info(`Deleted label "${deleted.name}"`);
82
+ output(presentLabel(deleted), (l) => `Deleted label "${l.name}"`);
68
83
  },
69
84
  help: `Usage: zinn label delete <name>
70
85
 
@@ -3,7 +3,23 @@ import type { RouteDef } from "../types";
3
3
  import { parseArgs } from "node:util";
4
4
 
5
5
  import { column, project } from "@zinn-dev/core";
6
- import { quit, validatePositionalCount, validateUniqueOptions } from "../lib";
6
+ import {
7
+ confirmAction,
8
+ output,
9
+ quit,
10
+ validatePositionalCount,
11
+ validateUniqueOptions,
12
+ } from "../lib";
13
+
14
+ type PresentedProject = { key: string; name: string };
15
+
16
+ function presentProject(projectMatch: PresentedProject): PresentedProject {
17
+ return { key: projectMatch.key, name: projectMatch.name };
18
+ }
19
+
20
+ function formatProject(presented: PresentedProject) {
21
+ return `${presented.key} | ${presented.name}`;
22
+ }
7
23
 
8
24
  export const projectRouter = {
9
25
  edit: {
@@ -31,7 +47,7 @@ export const projectRouter = {
31
47
  }
32
48
 
33
49
  const editedProject = project.edit({ projectKey, name: values.name });
34
- console.info(`${editedProject.key} | ${editedProject.name}`);
50
+ output(presentProject(editedProject), formatProject);
35
51
  },
36
52
  help: `Usage: zinn project edit <project-key> --name <text>
37
53
 
@@ -65,7 +81,7 @@ Example: zinn project edit MDR --name "Macrodata Refinement"`,
65
81
 
66
82
  try {
67
83
  const createdProject = project.create({ key: projectKey, name: values.name });
68
- console.info(`${createdProject.key} | ${createdProject.name}`);
84
+ output(presentProject(createdProject), formatProject);
69
85
  } catch (err: any) {
70
86
  quit(err?.message ?? "Something went wrong");
71
87
  }
@@ -83,16 +99,17 @@ Example: zinn project create MDR --name "Macrodata Refinement"`,
83
99
  list: {
84
100
  run: () => {
85
101
  const projects = project.getAll();
86
- if (projects.length === 0) {
87
- return;
88
- }
89
102
 
90
- const longestKeyLength = projects.reduce(
91
- (prev, current) => Math.max(prev, current.key.length),
92
- 0,
93
- );
103
+ output(projects.map(presentProject), (presentedProjects) => {
104
+ const longestKeyLength = presentedProjects.reduce(
105
+ (prev, current) => Math.max(prev, current.key.length),
106
+ 0,
107
+ );
94
108
 
95
- console.info(projects.map((p) => `${p.key.padEnd(longestKeyLength)} | ${p.name}`).join("\n"));
109
+ return presentedProjects
110
+ .map((p) => `${p.key.padEnd(longestKeyLength)} | ${p.name}`)
111
+ .join("\n");
112
+ });
96
113
  },
97
114
  help: `Usage: zinn project list
98
115
 
@@ -115,15 +132,15 @@ Example: zinn project list`,
115
132
  throw new Error(`Project with key "${projectKey}" does not exist!`);
116
133
  }
117
134
 
118
- const canDelete = confirm(
135
+ const canDelete = confirmAction(
119
136
  `Are you sure you want to delete ${projectMatch.key} and all of its columns and tasks?`,
120
137
  );
121
138
 
122
139
  if (canDelete) {
123
140
  const deletedProject = project.delete(projectKey);
124
- console.info(`Deleted ${deletedProject.key} | ${deletedProject.name}`);
141
+ output(presentProject(deletedProject), (p) => `Deleted ${formatProject(p)}`);
125
142
  } else {
126
- console.info(`Deletion cancelled for ${projectMatch.key} | ${projectMatch.name}`);
143
+ output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProject(p)}`);
127
144
  }
128
145
  } catch (err: any) {
129
146
  quit(err?.message ?? "Something went wrong");
@@ -148,8 +165,9 @@ Example: zinn project delete MDR`,
148
165
  try {
149
166
  const createdColumn = column.create({ projectKey, name: columnName });
150
167
  const columnProject = project.getById(createdColumn.project_id)!;
168
+ const presentedColumn = { project: columnProject.key, name: createdColumn.name };
151
169
 
152
- console.info(`${columnProject.key} | ${createdColumn.name}`);
170
+ output(presentedColumn, (c) => `${c.project} | ${c.name}`);
153
171
  } catch (err: any) {
154
172
  quit(err?.message ?? "Something went wrong");
155
173
  }
@@ -169,7 +187,8 @@ Example: zinn project column create MDR "Boardlog"`,
169
187
 
170
188
  // TODO: attach per-column task count
171
189
  // TODO: terminal formatting
172
- console.info(column.getAllByProjectKey(projectKey).map((c) => c.name));
190
+ const columns = column.getAllByProjectKey(projectKey).map((c) => ({ name: c.name }));
191
+ output(columns, (presentedColumns) => presentedColumns.map((c) => c.name).join("\n"));
173
192
  },
174
193
  help: `Usage: zinn project column list <project-key>
175
194
 
@@ -1,43 +1,75 @@
1
+ import type { RelationCreateInput } from "@zinn-dev/core";
1
2
  import type { RouteDef } from "../types";
2
3
 
3
4
  import { parseArgs } from "node:util";
4
5
  import { relation, relationCreateSchema, task } from "@zinn-dev/core";
5
- import { quit, validatePositionalCount, validateUniqueOptions } from "../lib";
6
+ import { output, quit, validatePositionalCount, validateUniqueOptions } from "../lib";
6
7
 
7
- export function formatRelations(taskKey: string) {
8
+ // TODO: maybe core should export it as a reusable if we need it in more places
9
+ type RelationType = RelationCreateInput["relation_type"];
10
+
11
+ type PresentedRelation = {
12
+ type: RelationType;
13
+ direction: "outgoing" | "incoming" | null;
14
+ task: { key: string; title: string; status: "Active" | "Archived" };
15
+ };
16
+
17
+ export function presentRelations(taskKey: string): Array<PresentedRelation> {
8
18
  const taskMatch = task.getByKey(taskKey);
9
19
 
10
- return relation
11
- .getAll(taskKey, { include: { tasks: true } })
20
+ return relation.getAll(taskKey, { include: { tasks: true } }).map((entry) => {
21
+ const isSource = entry.source_task_id === taskMatch.id;
22
+ const other = isSource ? entry.target : entry.source;
23
+ if (other == null) {
24
+ throw new Error("Connected task details were not included in the relation");
25
+ }
26
+
27
+ let direction: PresentedRelation["direction"] = null;
28
+ if (entry.relation_type !== "related") {
29
+ direction = isSource ? "outgoing" : "incoming";
30
+ }
31
+
32
+ return {
33
+ type: entry.relation_type,
34
+ direction,
35
+ task: {
36
+ key: other.key,
37
+ title: other.title,
38
+ status: other.archived_at == null ? "Active" : "Archived",
39
+ },
40
+ };
41
+ });
42
+ }
43
+
44
+ export function formatRelations(relations: Array<PresentedRelation>) {
45
+ return relations
12
46
  .map((entry) => {
13
- const isSource = entry.source_task_id === taskMatch.id;
14
- const other = isSource ? entry.target : entry.source;
15
- if (other == null) {
16
- throw new Error("Connected task details were not included in the relation");
17
- }
47
+ const isOutgoing = entry.direction === "outgoing";
18
48
 
19
49
  let label: string;
20
- switch (entry.relation_type) {
50
+ switch (entry.type) {
21
51
  case "related": {
22
52
  label = "Related to";
23
53
  break;
24
54
  }
25
55
  case "dependency": {
26
- label = isSource ? "Depends on" : "Depended on by";
56
+ label = isOutgoing ? "Depends on" : "Depended on by";
27
57
  break;
28
58
  }
29
59
  case "duplicate": {
30
- label = isSource ? "Duplicate of" : "Duplicated by";
60
+ label = isOutgoing ? "Duplicate of" : "Duplicated by";
31
61
  break;
32
62
  }
33
63
  }
34
64
 
35
- const archived = other.archived_at == null ? "" : " | Archived";
36
- return `${label} | ${other.key} | ${other.title}${archived}`;
65
+ const archived = entry.task.status === "Archived" ? " | Archived" : "";
66
+ return `${label} | ${entry.task.key} | ${entry.task.title}${archived}`;
37
67
  })
38
68
  .join("\n");
39
69
  }
40
70
 
71
+ type PresentedRelationChange = { type: RelationType; source: string; target: string };
72
+
41
73
  function parseRelationArgs(args: string[]) {
42
74
  const { values, positionals, tokens } = parseArgs({
43
75
  args,
@@ -70,7 +102,13 @@ export const relationRouter = {
70
102
 
71
103
  const source = task.getByKey(props.sourceTaskKey);
72
104
  const target = task.getByKey(props.targetTaskKey);
73
- console.info(`Deleted ${props.relation_type} relation from ${source.key} to ${target.key}`);
105
+ const deleted: PresentedRelationChange = {
106
+ type: props.relation_type,
107
+ source: source.key,
108
+ target: target.key,
109
+ };
110
+
111
+ output(deleted, (r) => `Deleted ${r.type} relation from ${r.source} to ${r.target}`);
74
112
  },
75
113
  help: `Usage: zinn task relation delete <source-task-key> <target-task-key> --type <type>
76
114
 
@@ -96,14 +134,21 @@ Example: zinn task relation delete APP-1 APP-2 --type dependency`,
96
134
 
97
135
  const source = task.getByKey(sourceTaskKey);
98
136
  const target = task.getByKey(targetTaskKey);
99
-
100
- const label = {
101
- related: "related to",
102
- dependency: "depends on",
103
- duplicate: "is a duplicate of",
104
- }[props.relation_type];
105
-
106
- console.info(`${source.key} ${label} ${target.key}`);
137
+ const created: PresentedRelationChange = {
138
+ type: props.relation_type,
139
+ source: source.key,
140
+ target: target.key,
141
+ };
142
+
143
+ output(created, (r) => {
144
+ const label = {
145
+ related: "related to",
146
+ dependency: "depends on",
147
+ duplicate: "is a duplicate of",
148
+ }[r.type];
149
+
150
+ return `${r.source} ${label} ${r.target}`;
151
+ });
107
152
  },
108
153
  help: `Usage: zinn task relation create <source-task-key> <target-task-key> --type <type>
109
154
 
@@ -121,11 +166,7 @@ Example: zinn task relation create APP-1 APP-2 --type dependency`,
121
166
  run: (args) => {
122
167
  const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
123
168
  validatePositionalCount(positionals, 1, "Provide exactly one task key");
124
- const output = formatRelations(positionals[0]!);
125
-
126
- if (output.length > 0) {
127
- console.info(output);
128
- }
169
+ output(presentRelations(positionals[0]!), formatRelations);
129
170
  },
130
171
  help: `Usage: zinn task relation list <task-key>
131
172
 
@@ -1,6 +1,6 @@
1
1
  import type { Command, ParsedRoute, RouteDef } from "../types";
2
2
 
3
- import { quit } from "../lib";
3
+ import { isHelpFlag, isJsonFlag, quit, setOutputMode } from "../lib";
4
4
 
5
5
  function getIsRunnable(obj: any): obj is Command {
6
6
  return Object.hasOwn(obj, "run");
@@ -45,8 +45,15 @@ export function parseRoutes(routesDef: RouteDef, prefix?: string) {
45
45
  return routeDefinitions;
46
46
  }
47
47
 
48
- function route(parsedRoutes: Array<ParsedRoute>, args: Array<string>) {
49
- const isHelpRequest = ["-h", "--help"].includes(args.at(-1) ?? "");
48
+ function route(parsedRoutes: Array<ParsedRoute>, rawArgs: Array<string>) {
49
+ // Stripped here so commands with strict `parseArgs` never see an unknown "--json" option
50
+ const args = rawArgs.filter((arg) => !isJsonFlag(arg));
51
+
52
+ if (args.length !== rawArgs.length) {
53
+ setOutputMode("json");
54
+ }
55
+
56
+ const isHelpRequest = isHelpFlag(args.at(-1) ?? "");
50
57
 
51
58
  if (isHelpRequest && args.length > 1) {
52
59
  const namespace = toCommand(args.slice(0, -1));
@@ -82,8 +89,7 @@ function route(parsedRoutes: Array<ParsedRoute>, args: Array<string>) {
82
89
  }
83
90
 
84
91
  const commandArgs = args.slice(nestingLevel);
85
- const isCommandHelpRequest =
86
- commandArgs.length === 1 && ["-h", "--help"].includes(commandArgs[0]!);
92
+ const isCommandHelpRequest = commandArgs.length === 1 && isHelpFlag(commandArgs[0]!);
87
93
 
88
94
  if (isCommandHelpRequest) {
89
95
  console.info(match.help);
@@ -1,10 +1,17 @@
1
+ import type { TaskPriority } from "@zinn-dev/core";
1
2
  import type { RouteDef } from "../types";
2
3
 
3
4
  import { parseArgs } from "node:util";
4
5
  import { task, project, column } from "@zinn-dev/core";
5
6
 
6
- import { quit, validatePositionalCount, validateUniqueOptions } from "../lib";
7
- import { formatRelations, relationRouter } from "./relation-router";
7
+ import {
8
+ confirmAction,
9
+ output,
10
+ quit,
11
+ validatePositionalCount,
12
+ validateUniqueOptions,
13
+ } from "../lib";
14
+ import { formatRelations, presentRelations, relationRouter } from "./relation-router";
8
15
  import { TASK_DESCRIPTION_PREVIEW_LENGTH } from "../constant";
9
16
 
10
17
  function formatTaskDescriptionPreview(description: string | null) {
@@ -21,25 +28,43 @@ function formatTaskDescriptionPreview(description: string | null) {
21
28
  return `${normalizedDescription.slice(0, TASK_DESCRIPTION_PREVIEW_LENGTH - 1).trimEnd()}…`;
22
29
  }
23
30
 
31
+ type PresentedTask = {
32
+ key: string;
33
+ status: "Active" | "Archived";
34
+ column: string;
35
+ title: string;
36
+ description: string | null;
37
+ priority: TaskPriority | null;
38
+ labels: Array<string>;
39
+ };
40
+
41
+ function presentTask(taskMatch: ReturnType<typeof task.getByKey>): PresentedTask {
42
+ return {
43
+ key: taskMatch.key,
44
+ status: taskMatch.archived_at == null ? "Active" : "Archived",
45
+ column: column.getById(taskMatch.column_id)!.name,
46
+ title: taskMatch.title,
47
+ description: taskMatch.description,
48
+ priority: taskMatch.priority,
49
+ labels: task.label.getAll(taskMatch.key).map((label) => label.name),
50
+ };
51
+ }
52
+
24
53
  // TODO: a CLI row formatter that accepts text columns and joins them with " | " would be useful
25
54
  // Reuse it across task list/view and other command output in a separate change.
26
- function formatTask(
27
- taskMatch: ReturnType<typeof task.getByKey>,
28
- options: { showsStatus?: boolean } = {},
29
- ) {
30
- const taskColumn = column.getById(taskMatch.column_id)!;
31
- const taskKey = taskMatch.key;
32
- const status = options.showsStatus
33
- ? ` | ${taskMatch.archived_at == null ? "Active" : "Archived"}`
34
- : "";
35
- const description = taskMatch.description == null ? "" : ` | ${taskMatch.description}`;
36
-
37
- const priority = taskMatch.priority == null ? "" : ` | Priority: ${taskMatch.priority}`;
38
- const labels = task.label.getAll(taskKey);
55
+ function formatTask(presented: PresentedTask, options: { showsStatus?: boolean } = {}) {
56
+ const status = options.showsStatus ? ` | ${presented.status}` : "";
57
+ const description = presented.description == null ? "" : ` | ${presented.description}`;
58
+
59
+ const priority = presented.priority == null ? "" : ` | Priority: ${presented.priority}`;
39
60
  const labelText =
40
- labels.length === 0 ? "" : ` | Labels: ${labels.map((label) => label.name).join(", ")}`;
61
+ presented.labels.length === 0 ? "" : ` | Labels: ${presented.labels.join(", ")}`;
62
+
63
+ return `${presented.key}${status} | ${presented.column} | ${presented.title}${description}${priority}${labelText}`;
64
+ }
41
65
 
42
- return `${taskKey}${status} | ${taskColumn.name} | ${taskMatch.title}${description}${priority}${labelText}`;
66
+ function formatTaskWithStatus(presented: PresentedTask) {
67
+ return formatTask(presented, { showsStatus: true });
43
68
  }
44
69
 
45
70
  export const taskRouter = {
@@ -91,7 +116,7 @@ export const taskRouter = {
91
116
  removeLabelNames: values["remove-label"],
92
117
  });
93
118
 
94
- console.info(formatTask(editedTask));
119
+ output(presentTask(editedTask), formatTask);
95
120
  },
96
121
  help: `Usage: zinn task edit <task-key> [--title <text>] [--description <text>] [--priority <low|medium|high|urgent|none>] [--add-label <name>] [--remove-label <name>]
97
122
 
@@ -148,7 +173,7 @@ Example: zinn task edit MDR-1 --title "Meet the quarterly refinement quota"`,
148
173
  priority: parsePriority(values.priority),
149
174
  labelNames: values.label,
150
175
  });
151
- console.info(formatTask(createdTask));
176
+ output(presentTask(createdTask), formatTask);
152
177
  },
153
178
  help: `Usage: zinn task create <project-key> --title <text> [--description <text>] [--priority <low|medium|high|urgent|none>] [--label <name>]
154
179
 
@@ -179,45 +204,27 @@ Example: zinn task create MDR --title "Refine the numbers" --description "Meet t
179
204
 
180
205
  const tasks = task.getAll({ projectKey, archive });
181
206
 
182
- if (tasks.length === 0) {
183
- return;
184
- }
185
-
186
- const presentableTasks = tasks.map((t) => {
187
- const taskColumn = column.getById(t.column_id)!;
188
- const taskKey = t.key;
189
-
190
- return {
191
- id: taskKey,
192
- status: t.archived_at == null ? "Active" : "Archived",
193
- title: t.title,
194
- description: t.description,
195
- priority: t.priority,
196
- column: taskColumn.name,
197
- };
198
- });
199
-
200
- const longestIdLength = presentableTasks.reduce(
201
- (prev, current) => Math.max(prev, current.id.length),
202
- 0,
203
- );
204
- const longestStatusLength = presentableTasks.reduce(
205
- (prev, current) => Math.max(prev, current.status.length),
206
- 0,
207
- );
207
+ output(tasks.map(presentTask), (presentedTasks) => {
208
+ const longestKeyLength = presentedTasks.reduce(
209
+ (prev, current) => Math.max(prev, current.key.length),
210
+ 0,
211
+ );
212
+ const longestStatusLength = presentedTasks.reduce(
213
+ (prev, current) => Math.max(prev, current.status.length),
214
+ 0,
215
+ );
208
216
 
209
- console.info(
210
- presentableTasks
217
+ return presentedTasks
211
218
  .map((t) => {
212
219
  // TODO: console output formatting for standardizied output
213
220
  const status = showsAll ? ` | ${t.status.padEnd(longestStatusLength)}` : "";
214
221
  const descriptionPreview = formatTaskDescriptionPreview(t.description);
215
222
  const description = t.description == null ? "" : ` | ${descriptionPreview}`;
216
223
  const priority = t.priority == null ? "" : ` | Priority: ${t.priority}`;
217
- return `${t.id.padEnd(longestIdLength)}${status} | ${t.column} | ${t.title}${description}${priority}`;
224
+ return `${t.key.padEnd(longestKeyLength)}${status} | ${t.column} | ${t.title}${description}${priority}`;
218
225
  })
219
- .join("\n"),
220
- );
226
+ .join("\n");
227
+ });
221
228
  },
222
229
  help: `Usage: zinn task list [project-key] [--archived | --all]
223
230
 
@@ -235,12 +242,14 @@ Example: zinn task list MDR --all`,
235
242
  }
236
243
 
237
244
  const taskMatch = task.getByKey(taskKey);
238
- console.info(formatTask(taskMatch));
245
+ const viewedTask = { ...presentTask(taskMatch), relations: presentRelations(taskKey) };
239
246
 
240
- const relations = formatRelations(taskKey);
241
- if (relations.length > 0) {
242
- console.info(`\nRelations:\n${relations}`);
243
- }
247
+ output(viewedTask, (t) => {
248
+ const relations = formatRelations(t.relations);
249
+ return relations.length > 0
250
+ ? `${formatTask(t)}\n\nRelations:\n${relations}`
251
+ : formatTask(t);
252
+ });
244
253
  },
245
254
  help: `Usage: zinn task view <task-key>
246
255
 
@@ -261,7 +270,7 @@ Example: zinn task view MDR-1`,
261
270
  }
262
271
 
263
272
  const movedTask = task.move({ taskKey, targetColumn });
264
- console.info(formatTask(movedTask));
273
+ output(presentTask(movedTask), formatTask);
265
274
  },
266
275
  help: `Usage: zinn task move <task-key> <target-column>
267
276
 
@@ -298,7 +307,7 @@ Example: zinn task move MDR-1 "In Progress"`,
298
307
  }
299
308
 
300
309
  const orderedTask = task.order({ taskKey, direction, targetTaskKey });
301
- console.info(formatTask(orderedTask));
310
+ output(presentTask(orderedTask), formatTask);
302
311
  return;
303
312
  }
304
313
  case "top":
@@ -310,7 +319,7 @@ Example: zinn task move MDR-1 "In Progress"`,
310
319
  }
311
320
 
312
321
  const orderedTask = task.order({ taskKey, direction });
313
- console.info(formatTask(orderedTask));
322
+ output(presentTask(orderedTask), formatTask);
314
323
  return;
315
324
  }
316
325
  default:
@@ -336,14 +345,14 @@ Example: zinn task order MDR-2 before MDR-1`,
336
345
 
337
346
  try {
338
347
  const taskMatch = task.getByKey(taskKey);
339
- const canDelete = confirm(`Are you sure you want to delete ${taskKey}?`);
348
+ const canDelete = confirmAction(`Are you sure you want to delete ${taskKey}?`);
349
+ const presented = presentTask(taskMatch);
340
350
 
341
351
  if (canDelete) {
342
- const formattedTask = formatTask(taskMatch);
343
352
  task.delete(taskKey);
344
- console.info(`Deleted ${formattedTask}`);
353
+ output(presented, (t) => `Deleted ${formatTask(t)}`);
345
354
  } else {
346
- console.info(`Deletion cancelled for ${formatTask(taskMatch)}`);
355
+ output(presented, (t) => `Deletion cancelled for ${formatTask(t)}`);
347
356
  }
348
357
  } catch (err: any) {
349
358
  quit(err?.message ?? "Something went wrong");
@@ -364,7 +373,7 @@ Example: zinn task delete MDR-1`,
364
373
  }
365
374
 
366
375
  const archivedTask = task.archive(taskKey);
367
- console.info(formatTask(archivedTask, { showsStatus: true }));
376
+ output(presentTask(archivedTask), formatTaskWithStatus);
368
377
  },
369
378
  help: `Usage: zinn task archive <task-key>
370
379
 
@@ -381,7 +390,7 @@ Example: zinn task archive MDR-1`,
381
390
  }
382
391
 
383
392
  const unarchivedTask = task.unarchive(taskKey);
384
- console.info(formatTask(unarchivedTask, { showsStatus: true }));
393
+ output(presentTask(unarchivedTask), formatTaskWithStatus);
385
394
  },
386
395
  help: `Usage: zinn task unarchive <task-key>
387
396
 
@@ -394,7 +403,7 @@ Example: zinn task unarchive MDR-1`,
394
403
  add: {
395
404
  run: (args) => {
396
405
  const props = parseTaskLabelArgs(args);
397
- console.info(formatTask(task.label.add(props)));
406
+ output(presentTask(task.label.add(props)), formatTask);
398
407
  },
399
408
  help: `Usage: zinn task label add <task-key> <label-name> [label-name ...]
400
409
 
@@ -403,7 +412,7 @@ Add existing labels to a task. Already attached labels are unchanged.`,
403
412
  remove: {
404
413
  run: (args) => {
405
414
  const props = parseTaskLabelArgs(args);
406
- console.info(formatTask(task.label.remove(props)));
415
+ output(presentTask(task.label.remove(props)), formatTask);
407
416
  },
408
417
  help: `Usage: zinn task label remove <task-key> <label-name> [label-name ...]
409
418