@zinn-dev/cli 0.40.0 → 0.42.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.
Files changed (84) hide show
  1. package/README.md +11 -561
  2. package/index.js +24 -13
  3. package/package.json +8 -2
  4. package/skills/zinn/SKILL.md +63 -0
  5. package/src/actor.d.ts +2 -1
  6. package/src/actor.js +78 -11
  7. package/src/capabilities-schema.d.ts +162 -0
  8. package/src/capabilities-schema.js +59 -0
  9. package/src/capabilities.d.ts +29 -0
  10. package/src/capabilities.js +30 -0
  11. package/src/column-hint.d.ts +3 -0
  12. package/src/column-hint.js +225 -0
  13. package/src/database.d.ts +1 -1
  14. package/src/database.js +5 -8
  15. package/src/errors.d.ts +158 -0
  16. package/src/errors.js +226 -0
  17. package/src/input.d.ts +227 -0
  18. package/src/input.js +192 -0
  19. package/src/lib.d.ts +71 -8
  20. package/src/lib.js +275 -18
  21. package/src/presentation/activity-presentation.d.ts +9 -1
  22. package/src/presentation/activity-presentation.js +120 -23
  23. package/src/presentation/capabilities-presentation.d.ts +2 -0
  24. package/src/presentation/capabilities-presentation.js +3 -0
  25. package/src/presentation/column-presentation.d.ts +9 -5
  26. package/src/presentation/column-presentation.js +10 -0
  27. package/src/presentation/comment-presentation.d.ts +15 -0
  28. package/src/presentation/comment-presentation.js +29 -0
  29. package/src/presentation/description-presentation.d.ts +17 -0
  30. package/src/presentation/description-presentation.js +26 -4
  31. package/src/presentation/info-presentation.d.ts +4 -0
  32. package/src/presentation/info-presentation.js +96 -0
  33. package/src/presentation/label-presentation.d.ts +8 -0
  34. package/src/presentation/label-presentation.js +28 -0
  35. package/src/presentation/project-presentation.d.ts +7 -0
  36. package/src/presentation/project-presentation.js +19 -0
  37. package/src/presentation/relation-presentation.d.ts +7 -0
  38. package/src/presentation/relation-presentation.js +73 -0
  39. package/src/presentation/task-presentation.d.ts +4 -12
  40. package/src/presentation/task-presentation.js +22 -18
  41. package/src/project.d.ts +18 -3
  42. package/src/project.js +37 -12
  43. package/src/result-schemas.d.ts +1194 -0
  44. package/src/result-schemas.js +279 -0
  45. package/src/results.d.ts +40 -0
  46. package/src/results.js +36 -0
  47. package/src/routes/activity-router.d.ts +104 -0
  48. package/src/routes/activity-router.js +155 -34
  49. package/src/routes/aliases.d.ts +2 -0
  50. package/src/routes/aliases.js +11 -0
  51. package/src/routes/backup-router.d.ts +17 -0
  52. package/src/routes/backup-router.js +15 -3
  53. package/src/routes/capabilities-router.d.ts +21 -0
  54. package/src/routes/capabilities-router.js +34 -0
  55. package/src/routes/comment-router.d.ts +210 -8
  56. package/src/routes/comment-router.js +189 -65
  57. package/src/routes/info-router.d.ts +21 -0
  58. package/src/routes/info-router.js +29 -0
  59. package/src/routes/label-router.d.ts +217 -2
  60. package/src/routes/label-router.js +189 -62
  61. package/src/routes/migrate-router.d.ts +17 -0
  62. package/src/routes/migrate-router.js +17 -5
  63. package/src/routes/project-router.d.ts +373 -2
  64. package/src/routes/project-router.js +322 -132
  65. package/src/routes/reindex-router.d.ts +17 -0
  66. package/src/routes/reindex-router.js +15 -3
  67. package/src/routes/relation-router.d.ts +110 -14
  68. package/src/routes/relation-router.js +122 -79
  69. package/src/routes/restore-router.d.ts +29 -0
  70. package/src/routes/restore-router.js +31 -14
  71. package/src/routes/router.d.ts +1 -1
  72. package/src/routes/router.js +80 -32
  73. package/src/routes/routes.d.ts +1781 -8
  74. package/src/routes/routes.js +9 -1
  75. package/src/routes/task-router.d.ts +946 -4
  76. package/src/routes/task-router.js +524 -260
  77. package/src/routes/whoami-router.d.ts +21 -0
  78. package/src/routes/whoami-router.js +31 -0
  79. package/src/text-edit.d.ts +28 -6
  80. package/src/text-edit.js +40 -23
  81. package/src/text-input.d.ts +47 -0
  82. package/src/text-input.js +187 -0
  83. package/src/types.d.ts +37 -0
  84. package/src/types.js +9 -1
@@ -1,57 +1,178 @@
1
+ import { jsonResult } from "../results.js";
1
2
  import { parseArgs } from "node:util";
2
- import { column, project } from "@zinn-dev/core";
3
- import { canPrompt, confirmAction, failureMessage, output, quit, UsageError, validatePositionals, validateUniqueOptions, } from "../lib.js";
4
- import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit.js";
5
- import { formatColumnList } from "../presentation/column-presentation.js";
6
- import { formatDescriptionPreview } from "../presentation/description-presentation.js";
7
- import { formatCellSeparator, formatRows } from "../presentation/row-layout.js";
3
+ import { column, project, columnOrderSchema, projectCreateSchema, projectEditSchema, } from "@zinn-dev/core";
4
+ import { CliError } from "../errors.js";
5
+ import { generateCommandUsage, getOptionInputs, noInput, violatesConstraint } from "../input.js";
6
+ import { confirmationDescription, canPrompt, confirmAction, dashValueHelp, diagnostic, output, outputChanges, quit, validatePositionals, validateOrderForms, requireStringOption, validateUniqueOptions, } from "../lib.js";
7
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditConstraints, } from "../text-edit.js";
8
+ import { checkFieldsBeforeText, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
9
+ import { formatColumnList, presentColumn } from "../presentation/column-presentation.js";
10
+ import { formatProjectList, presentProject } from "../presentation/project-presentation.js";
8
11
  import { formatSection } from "../presentation/section.js";
9
12
  import { currentActor } from "../actor.js";
10
- import { resolveProjectKey } from "../project.js";
11
- function presentProject(projectMatch) {
12
- return { key: projectMatch.key, name: projectMatch.name, description: projectMatch.description };
13
- }
14
- function formatProject(presented, options = {}) {
15
- return formatProjectList([presented], options);
16
- }
17
- function formatProjectList(presentedProjects, { showsDescriptionPreview = true } = {}) {
18
- return formatRows(presentedProjects.map((presented) => {
19
- const descriptionPreview = showsDescriptionPreview
20
- ? formatDescriptionPreview(presented.description)
21
- : "";
22
- const description = descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
23
- return [{ text: presented.key }, { text: `${presented.name}${description}` }];
24
- }));
25
- }
26
- function presentColumn(columnMatch) {
27
- const columnProject = project.getById(columnMatch.project_id);
28
- return { project: columnProject.key, name: columnMatch.name };
29
- }
30
- function formatColumn(presented) {
31
- return formatColumnList([presented], { showsProject: true });
32
- }
13
+ import { checkDefaultProject, chooseProjectKey, resolveProjectKey, requiredProjectDescription, } from "../project.js";
14
+ const projectEditConstraint = {
15
+ kind: "atLeastOne",
16
+ members: ["option:name", "option:description", "option:description-file"],
17
+ };
18
+ const projectInputs = {
19
+ create: {
20
+ options: {
21
+ name: { type: "string", value: { kind: "text", name: "text" } },
22
+ description: { type: "string", value: { kind: "text", name: "text" } },
23
+ "description-file": textFileOption,
24
+ },
25
+ forms: [
26
+ {
27
+ id: "default",
28
+ positionals: [{ name: "project-key", min: 1, max: 1, value: { kind: "project-key" } }],
29
+ },
30
+ ],
31
+ constraints: [textSourceConstraint("--description")],
32
+ },
33
+ list: noInput,
34
+ view: {
35
+ options: {},
36
+ forms: [
37
+ {
38
+ id: "default",
39
+ positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
40
+ },
41
+ ],
42
+ constraints: [],
43
+ notes: [requiredProjectDescription],
44
+ },
45
+ edit: {
46
+ options: {
47
+ name: { type: "string", value: { kind: "text", name: "text" } },
48
+ description: { type: "string", value: { kind: "text", name: "text" } },
49
+ "description-file": textFileOption,
50
+ ...textEditOptions,
51
+ },
52
+ forms: [
53
+ {
54
+ id: "default",
55
+ positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
56
+ },
57
+ ],
58
+ constraints: [
59
+ textSourceConstraint("--description"),
60
+ ...textEditConstraints("--description"),
61
+ projectEditConstraint,
62
+ ],
63
+ notes: [requiredProjectDescription, textEditHelp("--description")],
64
+ },
65
+ delete: {
66
+ options: { yes: { type: "boolean" } },
67
+ forms: [
68
+ {
69
+ id: "default",
70
+ positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
71
+ },
72
+ ],
73
+ constraints: [],
74
+ notes: [requiredProjectDescription],
75
+ },
76
+ column_create: {
77
+ options: {},
78
+ forms: [
79
+ {
80
+ id: "default",
81
+ positionals: [
82
+ { name: "project-key", min: 1, max: 1, value: { kind: "project-key" } },
83
+ { name: "column-name", min: 1, max: 1, value: { kind: "column-name" } },
84
+ ],
85
+ },
86
+ ],
87
+ constraints: [],
88
+ },
89
+ column_list: {
90
+ options: {},
91
+ forms: [
92
+ {
93
+ id: "default",
94
+ positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
95
+ },
96
+ ],
97
+ constraints: [],
98
+ notes: [requiredProjectDescription],
99
+ },
100
+ column_edit: {
101
+ options: { name: { type: "string", required: true, value: { kind: "text", name: "text" } } },
102
+ forms: [
103
+ {
104
+ id: "default",
105
+ positionals: [
106
+ { name: "project-key", min: 1, max: 1, value: { kind: "project-key" } },
107
+ { name: "column-name", min: 1, max: 1, value: { kind: "column-name" } },
108
+ ],
109
+ },
110
+ ],
111
+ constraints: [],
112
+ },
113
+ column_order: {
114
+ options: {},
115
+ forms: [
116
+ {
117
+ id: "absolute",
118
+ positionals: [
119
+ { name: "project-key", min: 1, max: 1, value: { kind: "project-key" } },
120
+ { name: "column-name", min: 1, max: 1, value: { kind: "column-name" } },
121
+ {
122
+ name: "direction",
123
+ min: 1,
124
+ max: 1,
125
+ value: { kind: "enum", choices: columnOrderSchema.options[0].shape.direction.options },
126
+ },
127
+ ],
128
+ },
129
+ {
130
+ id: "relative",
131
+ positionals: [
132
+ { name: "project-key", min: 1, max: 1, value: { kind: "project-key" } },
133
+ { name: "column-name", min: 1, max: 1, value: { kind: "column-name" } },
134
+ {
135
+ name: "direction",
136
+ min: 1,
137
+ max: 1,
138
+ value: { kind: "enum", choices: columnOrderSchema.options[1].shape.direction.options },
139
+ },
140
+ { name: "target-column-name", min: 1, max: 1, value: { kind: "column-name" } },
141
+ ],
142
+ },
143
+ ],
144
+ constraints: [],
145
+ },
146
+ };
33
147
  export const projectRouter = {
34
148
  create: {
35
- run: (args) => {
149
+ summary: "Create a project with the default columns.",
150
+ effects: { domain: "create", storage: "normal-open" },
151
+ confirmation: { kind: "none" },
152
+ input: projectInputs.create,
153
+ results: [jsonResult("Project")],
154
+ run: async (args) => {
36
155
  const { values, positionals, tokens } = parseArgs({
37
156
  args,
38
- options: { name: { type: "string" }, description: { type: "string" } },
157
+ options: projectInputs.create.options,
39
158
  allowPositionals: true,
40
159
  strict: true,
41
160
  tokens: true,
42
161
  });
43
- validateUniqueOptions(tokens);
44
- validatePositionals(positionals, ["<project-key>"]);
162
+ validateUniqueOptions(tokens, projectInputs.create.options);
163
+ validatePositionals(positionals, projectInputs.create.forms[0]);
45
164
  const projectKey = positionals[0];
165
+ checkFieldsBeforeText(projectCreateSchema, { key: projectKey, name: values.name });
166
+ const description = await resolveTextInput(values.description, values["description-file"], "--description");
46
167
  try {
47
- const createdProject = project.create({ key: projectKey, name: values.name, description: values.description }, currentActor());
48
- output(presentProject(createdProject), formatProject);
168
+ const createdProject = project.create({ key: projectKey, name: values.name, description }, currentActor());
169
+ output(presentProject(createdProject), (entry) => formatProjectList([entry]));
49
170
  }
50
171
  catch (err) {
51
- quit(failureMessage(err, "Something went wrong"));
172
+ throw err;
52
173
  }
53
174
  },
54
- help: `Usage: zinn project create <project-key> [--name <text>] [--description <text>]
175
+ help: `${generateCommandUsage("project create", projectInputs.create)}
55
176
 
56
177
  Create a project with the default columns.
57
178
  Project keys are stored in uppercase.
@@ -59,35 +180,59 @@ Project keys are stored in uppercase.
59
180
  An omitted name defaults to the uppercase project key.
60
181
  Names are trimmed and cannot be blank or contain line breaks or control characters.
61
182
  Descriptions may contain multiple lines. If omitted, they are saved as null.
183
+ ${textFileHelp("--description")}
62
184
 
63
- Example: zinn project create MDR --name "Macrodata Refinement"`,
185
+ ${dashValueHelp("--description")}
186
+
187
+ Example: zinn project create MDR --name 'Macrodata Refinement'`,
64
188
  },
65
189
  list: {
190
+ summary: "List projects, their keys, and truncated description previews.",
191
+ effects: { domain: "read", storage: "normal-open" },
192
+ confirmation: { kind: "none" },
193
+ input: projectInputs.list,
194
+ results: [jsonResult("ProjectList")],
66
195
  run: (args) => {
67
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
68
- validatePositionals(positionals, []);
196
+ const { positionals } = parseArgs({
197
+ options: projectInputs.list.options,
198
+ args,
199
+ allowPositionals: true,
200
+ strict: true,
201
+ });
202
+ validatePositionals(positionals, projectInputs.list.forms[0]);
69
203
  const projects = project.getAll();
70
204
  output(projects.map(presentProject), formatProjectList);
71
205
  },
72
- help: `Usage: zinn project list
206
+ help: `${generateCommandUsage("project list", projectInputs.list)}
73
207
 
74
208
  List projects, their keys, and truncated description previews.
75
209
 
76
210
  Example: zinn project list`,
77
211
  },
78
212
  view: {
213
+ summary: "Show a project with its description and the number of tasks in each column.",
214
+ effects: { domain: "read", storage: "normal-open" },
215
+ confirmation: { kind: "none" },
216
+ input: projectInputs.view,
217
+ results: [jsonResult("ProjectView")],
79
218
  run: (args) => {
80
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
81
- validatePositionals(positionals, ["[<project-key>]"]);
219
+ const { positionals } = parseArgs({
220
+ options: projectInputs.view.options,
221
+ args,
222
+ allowPositionals: true,
223
+ strict: true,
224
+ });
225
+ validatePositionals(positionals, projectInputs.view.forms[0]);
82
226
  const projectKey = resolveProjectKey(positionals[0], { required: true });
83
227
  const projectMatch = project.getByKey(projectKey);
84
228
  if (projectMatch == null) {
85
- quit(`Project with key "${project.standardizeKey(projectKey)}" does not exist!`);
229
+ throw new CliError(`Project with key "${project.standardizeKey(projectKey)}" does not exist!`, "not_found", { entity: "project", key: project.standardizeKey(projectKey), source: "explicit" });
86
230
  }
87
231
  const taskCounts = column.getTaskCountsByProjectKey(projectMatch.key);
88
232
  const presentedProject = {
89
233
  ...presentProject(projectMatch),
90
234
  columns: taskCounts.columns.map((columnCount) => ({
235
+ id: columnCount.column.id,
91
236
  name: columnCount.column.name,
92
237
  taskCount: columnCount.taskCount,
93
238
  })),
@@ -95,7 +240,7 @@ Example: zinn project list`,
95
240
  };
96
241
  output(presentedProject, (viewedProject) => {
97
242
  // The full description follows as its own section, so the row leaves out the preview.
98
- const sections = [formatProject(viewedProject, { showsDescriptionPreview: false })];
243
+ const sections = [formatProjectList([viewedProject], { showsDescriptionPreview: false })];
99
244
  if (viewedProject.description != null) {
100
245
  sections.push(formatSection("Description", viewedProject.description));
101
246
  }
@@ -107,127 +252,174 @@ Example: zinn project list`,
107
252
  return sections.join("\n\n");
108
253
  });
109
254
  },
110
- help: `Usage: zinn project view [<project-key>]
255
+ help: `${generateCommandUsage("project view", projectInputs.view)}
111
256
 
112
257
  Show a project with its description and the number of tasks in each column.
113
- An omitted project key uses defaultProject from settings, if present.
114
- If no default project is set, the key is required.
258
+ ${requiredProjectDescription}
115
259
  The description prints in full, keeping its line breaks. Archived tasks are counted as one total.
116
260
 
117
261
  Example: zinn project view MDR`,
118
262
  },
119
263
  edit: {
120
- run: (args) => {
264
+ summary: "Change the supplied project fields. At least one edit flag is required.",
265
+ effects: { domain: "update", storage: "normal-open" },
266
+ confirmation: { kind: "none" },
267
+ input: projectInputs.edit,
268
+ results: [jsonResult("ProjectChange")],
269
+ run: async (args) => {
121
270
  const { values, positionals, tokens } = parseArgs({
122
271
  args,
123
- options: { name: { type: "string" }, description: { type: "string" }, ...textEditOptions },
272
+ options: projectInputs.edit.options,
124
273
  allowPositionals: true,
125
274
  strict: true,
126
275
  tokens: true,
127
276
  });
128
- validateUniqueOptions(tokens);
129
- validatePositionals(positionals, ["[<project-key>]"]);
130
- const projectKey = resolveProjectKey(positionals[0], { required: true });
131
- const description = resolveTextEdit(values.description, values, "--description");
132
- if (values.name === undefined && description === undefined) {
133
- quit("Provide an edit flag: --name or --description");
277
+ validateUniqueOptions(tokens, projectInputs.edit.options);
278
+ validatePositionals(positionals, projectInputs.edit.forms[0]);
279
+ const projectChoice = chooseProjectKey(positionals[0], { required: true });
280
+ checkFieldsBeforeText(projectEditSchema, {
281
+ projectKey: projectChoice.key,
282
+ name: values.name,
283
+ });
284
+ const description = await resolveTextEdit(values, "--description");
285
+ // Without a text source nothing was read, so this usage error still comes before any input
286
+ if (violatesConstraint(projectEditConstraint, getOptionInputs(values))) {
287
+ quit("Provide an edit flag: --name, --description or --description-file", undefined, {
288
+ field: [],
289
+ });
134
290
  }
135
- const editedProject = project.edit({ projectKey, name: values.name, description }, currentActor());
136
- output(presentProject(editedProject), formatProject);
291
+ checkDefaultProject(projectChoice);
292
+ const editedProject = project.edit({ projectKey: projectChoice.key, name: values.name, description }, currentActor());
293
+ outputChanges([editedProject], (change) => presentProject(change.project), formatProjectList, (entry) => `Project ${entry.key} was unchanged`);
137
294
  },
138
- help: `Usage: zinn project edit [<project-key>] [--name <text>] [--description <text> ${textEditUsage}]
295
+ help: `${generateCommandUsage("project edit", projectInputs.edit)}
139
296
 
140
297
  Change the supplied project fields. At least one edit flag is required.
141
- An omitted project key uses defaultProject from settings, if present.
142
- If no default project is set, the key is required.
143
- Use --description "" to clear the description.
298
+ With --json, changed is false when all supplied values already match.
299
+ ${requiredProjectDescription}
300
+ Use --description '' to clear the description.
301
+ ${textFileHelp("--description")}
144
302
 
145
303
  ${textEditHelp("--description")}
146
304
 
305
+ ${dashValueHelp("--description")}
306
+
147
307
  Examples:
148
- zinn project edit MDR --name "Macrodata Refinement"
149
- zinn project edit MDR --description "database" --replacing "board" --all`,
308
+ zinn project edit MDR --name 'Macrodata Refinement'
309
+ zinn project edit MDR --description database --replacing board --all`,
150
310
  },
151
311
  delete: {
312
+ summary: "Permanently delete a project and all of its columns and tasks after confirmation.",
313
+ effects: { domain: "delete", storage: "normal-open" },
314
+ confirmation: {
315
+ kind: "project-delete",
316
+ description: `${confirmationDescription} When the project key is omitted, deleting the configured default project always requires a terminal prompt; --yes is ignored.`,
317
+ },
318
+ input: projectInputs.delete,
319
+ results: [jsonResult("Project")],
152
320
  run: async (args) => {
153
321
  const { values, positionals, tokens } = parseArgs({
154
322
  args,
155
- options: { yes: { type: "boolean" } },
323
+ options: projectInputs.delete.options,
156
324
  allowPositionals: true,
157
325
  strict: true,
158
326
  tokens: true,
159
327
  });
160
- validateUniqueOptions(tokens);
161
- validatePositionals(positionals, ["[<project-key>]"]);
328
+ validateUniqueOptions(tokens, projectInputs.delete.options);
329
+ validatePositionals(positionals, projectInputs.delete.forms[0]);
162
330
  const typedProjectKey = positionals[0];
163
331
  const projectKey = resolveProjectKey(typedProjectKey, { required: true });
164
332
  try {
165
333
  const projectMatch = project.getByKey(projectKey);
166
334
  if (projectMatch == null) {
167
- throw new Error(`Project with key "${projectKey}" does not exist!`);
335
+ throw new CliError(`Project with key "${projectKey}" does not exist!`, "not_found", {
336
+ entity: "project",
337
+ key: projectKey,
338
+ source: "explicit",
339
+ });
168
340
  }
169
341
  // Like `gh repo delete`: --yes never skips the prompt for a project the command did not name
170
342
  const isYesIgnored = values.yes === true && typedProjectKey === undefined;
171
343
  if (isYesIgnored && !canPrompt()) {
172
- quit(`Cannot delete the default project ${projectMatch.key} without a terminal. Type its key to use --yes: zinn project delete ${projectMatch.key} --yes`);
344
+ quit(`Cannot delete the default project ${projectMatch.key} without a terminal. Type its key to use --yes: zinn project delete ${projectMatch.key} --yes`, undefined, { argument: "project-key", reason: "confirmation_required" });
173
345
  }
174
346
  if (isYesIgnored) {
175
- console.error("Warning: --yes is ignored because no project key was typed");
347
+ diagnostic("Warning: --yes is ignored because no project key was typed");
176
348
  }
177
349
  const canDelete = await confirmAction(`Are you sure you want to delete ${projectMatch.key} and all of its columns and tasks?`, values.yes === true && typedProjectKey !== undefined, typedProjectKey === undefined
178
350
  ? "Project deletion with --json needs a typed <project-key> and --yes"
179
351
  : undefined);
180
352
  if (canDelete) {
181
353
  const deletedProject = project.delete(projectKey, currentActor());
182
- output(presentProject(deletedProject), (p) => `Deleted ${formatProject(p)}`);
354
+ output(presentProject(deletedProject), (p) => `Deleted ${formatProjectList([p])}`);
183
355
  }
184
356
  else {
185
- output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProject(p)}`);
357
+ output(presentProject(projectMatch), (p) => `Deletion cancelled for ${formatProjectList([p])}`);
186
358
  }
187
359
  }
188
360
  catch (err) {
189
- quit(failureMessage(err, "Something went wrong"));
361
+ throw err;
190
362
  }
191
363
  },
192
- help: `Usage: zinn project delete [<project-key>] [--yes]
364
+ help: `${generateCommandUsage("project delete", projectInputs.delete)}
193
365
 
194
366
  Permanently delete a project and all of its columns and tasks after confirmation.
195
- An omitted project key uses defaultProject from settings, if present.
196
- If no default project is set, the key is required.
197
- With the default, confirmation is always required: --yes is ignored, and without a terminal the command refuses.
367
+ ${requiredProjectDescription}
368
+ When the project key is omitted, confirmation is always required: --yes is ignored, and without a terminal the command refuses.
198
369
  Use a typed project key and --yes to skip the prompt, including with --json.
199
370
 
200
371
  Example: zinn project delete MDR`,
201
372
  },
202
373
  column: {
203
374
  create: {
375
+ summary: "Add a column at the end of a project's board.",
376
+ effects: { domain: "create", storage: "normal-open" },
377
+ confirmation: { kind: "none" },
378
+ input: projectInputs.column_create,
379
+ results: [jsonResult("Column")],
204
380
  run: (args) => {
205
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
206
- validatePositionals(positionals, ["<project-key>", "<column-name>"]);
381
+ const { positionals } = parseArgs({
382
+ options: projectInputs.column_create.options,
383
+ args,
384
+ allowPositionals: true,
385
+ strict: true,
386
+ });
387
+ validatePositionals(positionals, projectInputs.column_create.forms[0]);
207
388
  const projectKey = positionals[0];
208
389
  const columnName = positionals[1];
209
390
  try {
210
391
  const createdColumn = column.create({ projectKey, name: columnName }, currentActor());
211
- output(presentColumn(createdColumn), formatColumn);
392
+ output(presentColumn(createdColumn), (entry) => formatColumnList([entry], { showsProject: true }));
212
393
  }
213
394
  catch (err) {
214
- quit(failureMessage(err, "Something went wrong"));
395
+ throw err;
215
396
  }
216
397
  },
217
- help: `Usage: zinn project column create <project-key> <column-name>
398
+ help: `${generateCommandUsage("project column create", projectInputs.column_create)}
218
399
 
219
400
  Add a column at the end of a project's board.
220
401
  Names are trimmed, cannot be blank or contain line breaks or control characters, and must be unique within the project regardless of casing.
221
402
 
222
- Example: zinn project column create MDR "Boardlog"`,
403
+ Example: zinn project column create MDR Boardlog`,
223
404
  },
224
405
  list: {
406
+ summary: "List a project's columns in board order with their unarchived task counts.",
407
+ effects: { domain: "read", storage: "normal-open" },
408
+ confirmation: { kind: "none" },
409
+ input: projectInputs.column_list,
410
+ results: [jsonResult("ColumnList")],
225
411
  run: (args) => {
226
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
227
- validatePositionals(positionals, ["[<project-key>]"]);
412
+ const { positionals } = parseArgs({
413
+ options: projectInputs.column_list.options,
414
+ args,
415
+ allowPositionals: true,
416
+ strict: true,
417
+ });
418
+ validatePositionals(positionals, projectInputs.column_list.forms[0]);
228
419
  const projectKey = resolveProjectKey(positionals[0], { required: true });
229
420
  const taskCounts = column.getTaskCountsByProjectKey(projectKey);
230
421
  const columns = taskCounts.columns.map((columnCount) => ({
422
+ id: columnCount.column.id,
231
423
  name: columnCount.column.name,
232
424
  taskCount: columnCount.taskCount,
233
425
  }));
@@ -235,94 +427,92 @@ Example: zinn project column create MDR "Boardlog"`,
235
427
  showsTaskCounts: true,
236
428
  }));
237
429
  },
238
- help: `Usage: zinn project column list [<project-key>]
430
+ help: `${generateCommandUsage("project column list", projectInputs.column_list)}
239
431
 
240
432
  List a project's columns in board order with their unarchived task counts.
241
- An omitted project key uses defaultProject from settings, if present.
242
- If no default project is set, the key is required.
433
+ ${requiredProjectDescription}
243
434
 
244
435
  Example: zinn project column list MDR`,
245
436
  },
246
437
  edit: {
438
+ summary: "Rename a column.",
439
+ effects: { domain: "update", storage: "normal-open" },
440
+ confirmation: { kind: "none" },
441
+ input: projectInputs.column_edit,
442
+ results: [jsonResult("ColumnChange")],
247
443
  run: (args) => {
248
444
  const { values, positionals, tokens } = parseArgs({
249
445
  args,
250
- options: { name: { type: "string" } },
446
+ options: projectInputs.column_edit.options,
251
447
  allowPositionals: true,
252
448
  strict: true,
253
449
  tokens: true,
254
450
  });
255
- validateUniqueOptions(tokens);
256
- validatePositionals(positionals, ["<project-key>", "<column-name>"]);
257
- if (values.name === undefined) {
258
- quit("Provide an edit flag: --name");
259
- }
451
+ validateUniqueOptions(tokens, projectInputs.column_edit.options);
452
+ validatePositionals(positionals, projectInputs.column_edit.forms[0]);
453
+ const name = requireStringOption(projectInputs.column_edit.options.name, values.name, "name", "Provide an edit flag: --name");
260
454
  const editedColumn = column.edit({
261
455
  projectKey: positionals[0],
262
456
  columnName: positionals[1],
263
- name: values.name,
457
+ name,
264
458
  }, currentActor());
265
- output(presentColumn(editedColumn), formatColumn);
459
+ outputChanges([editedColumn], (change) => presentColumn(change.column), (entries) => formatColumnList(entries, { showsProject: true }), (entry) => `Column "${entry.name}" was unchanged`);
266
460
  },
267
- help: `Usage: zinn project column edit <project-key> <column-name> --name <text>
461
+ help: `${generateCommandUsage("project column edit", projectInputs.column_edit)}
268
462
 
269
463
  Rename a column.
270
464
  The --name flag is required.
465
+ With --json, changed is false when the name already matches.
271
466
 
272
467
  Columns are matched by name, and matching is case-insensitive.
273
468
  Names are trimmed, and must remain unique within the same project.
274
469
  Changing only the casing of a column's own name is allowed.
275
470
 
276
- Example: zinn project column edit MDR "In Progress" --name "Refining"`,
471
+ ${dashValueHelp("--name")}
472
+
473
+ Example: zinn project column edit MDR 'In Progress' --name Refining`,
277
474
  },
278
475
  order: {
476
+ summary: "Change a column's position on the project's board.",
477
+ effects: { domain: "update", storage: "normal-open" },
478
+ confirmation: { kind: "none" },
479
+ input: projectInputs.column_order,
480
+ results: [jsonResult("ColumnChange")],
279
481
  run: (args) => {
280
- const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
281
- /**
282
- * The words every direction needs. Only whether they are there is checked here,
283
- * since the direction decides whether a target column follows.
284
- */
285
- const leadingWords = [
286
- "<project-key>",
287
- "<column-name>",
288
- "{first|previous|next|last|before|after}",
289
- ];
290
- validatePositionals(positionals.slice(0, leadingWords.length), leadingWords);
482
+ const { positionals } = parseArgs({
483
+ options: projectInputs.column_order.options,
484
+ args,
485
+ allowPositionals: true,
486
+ strict: true,
487
+ });
488
+ const form = validateOrderForms(positionals, projectInputs.column_order.forms);
291
489
  const projectKey = positionals[0];
292
490
  const columnName = positionals[1];
293
- const direction = positionals[2];
294
491
  let orderedColumn;
295
- switch (direction) {
296
- case "before":
297
- case "after": {
298
- validatePositionals(positionals, [...leadingWords, "<target-column-name>"]);
299
- orderedColumn = column.order({ projectKey, columnName, direction, targetColumnName: positionals[3] }, currentActor());
300
- break;
301
- }
302
- case "first":
303
- case "previous":
304
- case "next":
305
- case "last": {
306
- validatePositionals(positionals, leadingWords);
307
- orderedColumn = column.order({ projectKey, columnName, direction }, currentActor());
308
- break;
309
- }
310
- default:
311
- throw new UsageError(`Unknown order direction "${direction}"`);
492
+ if (form.id === "relative") {
493
+ orderedColumn = column.order({
494
+ projectKey,
495
+ columnName,
496
+ direction: form.direction,
497
+ targetColumnName: positionals[form.directionIndex + 1],
498
+ }, currentActor());
499
+ }
500
+ else {
501
+ orderedColumn = column.order({ projectKey, columnName, direction: form.direction }, currentActor());
312
502
  }
313
- // TODO: maybe also print the new full column state?
314
- output(presentColumn(orderedColumn), formatColumn);
503
+ outputChanges([orderedColumn], (change) => presentColumn(change.column), (entries) => formatColumnList(entries, { showsProject: true }), (entry) => `Column "${entry.name}" was already in that position`);
315
504
  },
316
- help: `Usage: zinn project column order <project-key> <column-name> {first|previous|next|last}
317
- zinn project column order <project-key> <column-name> {before|after} <target-column-name>
505
+ help: `${generateCommandUsage("project column order", projectInputs.column_order)}
318
506
 
319
507
  Change a column's position on the project's board.
320
508
  Use first or last for either end, previous or next for one position,
321
509
  or before or after to place it relative to another column.
322
510
 
323
511
  Columns are matched by name, and matching is case-insensitive.
512
+ Ordering to the current position, or before or after itself, leaves the column unchanged.
513
+ With --json, changed is false when the column was already in that position.
324
514
 
325
- Example: zinn project column order MDR Review before "In Progress"`,
515
+ Example: zinn project column order MDR Review before 'In Progress'`,
326
516
  },
327
517
  },
328
518
  };