@zinn-dev/cli 0.21.0 → 0.23.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
@@ -50,6 +50,16 @@ Add another column at the end of the board:
50
50
  zinn project column create MDR "Boardlog"
51
51
  ```
52
52
 
53
+ Rename a column:
54
+
55
+ ```sh
56
+ zinn project column edit MDR "In Progress" --name "Refining"
57
+ ```
58
+
59
+ Columns are matched by name, and matching is case-insenstivie. Names are trimmed and they cannot be blank.
60
+ Since columns are case-insensitive, you cannot have two columns with only different casing such as `todo` and `Todo`. However, you are free to change the casing of an existing column.
61
+ Tasks stay in the renamed column.
62
+
53
63
  `zinn project delete MDR` asks for confirmation, then permanently deletes the project and all of its columns and tasks.
54
64
 
55
65
  ## Create and read tasks
@@ -71,6 +81,28 @@ zinn task view MDR-1
71
81
 
72
82
  When a project key is supplied, the list follows the project's column order and the task order within each column.
73
83
 
84
+ ## Search tasks
85
+
86
+ Search task titles, descriptions, and comments, optionally in one project:
87
+
88
+ ```sh
89
+ zinn task search refine
90
+ zinn task search "quarterly quota" MDR
91
+ zinn task search MDR-1
92
+ zinn task search auth --all --limit 5
93
+ ```
94
+
95
+ Each query matches the start of a word, ignoring case and accents, so `cafe` finds "Café" and `auth` finds "Authentication". Every word must match somewhere in the task: its title, its description, or any of its comments. A comment match lists the task the comment belongs to.
96
+
97
+ If the whole query is an existing task key, such as `mdr-1`, that task comes first. Other results follow by relevance, with title matches weighted highest. Equally relevant tasks are ordered by project key, then task number.
98
+
99
+ Note that by default only the active tasks are searched.
100
+ `--archived` searches only archived tasks and `--all` searches both, just like how it is with `task list`. When archived matches are left out, Zinn prints a note such as `2 archived matches hidden, use --all to include them`. This extra info is not a part of the `--json` output. `--limit <n>` shows at most `n` results.
101
+
102
+ Results use the same rows and `--json` shape as `task list`. A search with no results prints nothing and exits successfully. Put `--` before a query that begins with a dash: `zinn task search -- -flag`.
103
+
104
+ Search uses an index that Zinn keeps up to date as tasks and comments change.
105
+
74
106
  ## Labels
75
107
 
76
108
  Labels are global and reusable in all the available projects.
package/index.ts CHANGED
@@ -24,9 +24,11 @@ Commands:
24
24
  project view
25
25
  project delete
26
26
  project column create
27
+ project column edit
27
28
  project column list
28
29
  task create
29
30
  task list
31
+ task search
30
32
  task view
31
33
  task edit
32
34
  task move
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.21.0",
3
+ "version": "0.23.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.14.0"
45
+ "@zinn-dev/core": "0.16.0"
46
46
  }
47
47
  }
@@ -212,8 +212,51 @@ Example: zinn project delete MDR`,
212
212
  help: `Usage: zinn project column create <project-key> <column-name>
213
213
 
214
214
  Add a column at the end of a project's board.
215
+ Names are trimmed, must contain printable text on a single line, and must be unique within the project regardless of casing.
215
216
 
216
217
  Example: zinn project column create MDR "Boardlog"`,
218
+ },
219
+ edit: {
220
+ run: (args: Array<string>) => {
221
+ const { values, positionals, tokens } = parseArgs({
222
+ args,
223
+ options: { name: { type: "string" } },
224
+ allowPositionals: true,
225
+ strict: true,
226
+ tokens: true,
227
+ });
228
+
229
+ validatePositionalCount(
230
+ positionals,
231
+ 2,
232
+ "Both the project key and the column name must be specified",
233
+ );
234
+ validateUniqueOptions(tokens);
235
+
236
+ if (values.name === undefined) {
237
+ quit("Provide an edit flag: --name");
238
+ }
239
+
240
+ const editedColumn = column.edit({
241
+ projectKey: positionals[0]!,
242
+ columnName: positionals[1]!,
243
+ name: values.name,
244
+ });
245
+ const columnProject = project.getById(editedColumn.project_id)!;
246
+ const presentedColumn = { project: columnProject.key, name: editedColumn.name };
247
+
248
+ output(presentedColumn, (c) => `${c.project} | ${c.name}`);
249
+ },
250
+ help: `Usage: zinn project column edit <project-key> <column-name> --name <text>
251
+
252
+ Rename a column.
253
+ The --name flag is required.
254
+
255
+ Columns are matched by name, and matching is case-insensitive.
256
+ Names are trimmed, and must remain unique within the same project.
257
+ Changing only the casing of a column's own name is allowed.
258
+
259
+ Example: zinn project column edit MDR "In Progress" --name "Refining"`,
217
260
  },
218
261
  list: {
219
262
  run: (args: Array<string>) => {
@@ -64,6 +64,22 @@ test("router calls the deepest nesting command", () => {
64
64
  expect(routes.foo.create.run).not.toHaveBeenCalled();
65
65
  });
66
66
 
67
+ test("only arguments before the first -- are treated as router flags", () => {
68
+ const run = mock(() => {});
69
+ const router = createRouter({ foo: { run, help: "" } });
70
+
71
+ router.route(["foo", "--", "--json", "--help"]);
72
+ expect(run).toHaveBeenCalledWith(["--", "--json", "--help"]);
73
+ });
74
+
75
+ test("router flags before a -- still apply", () => {
76
+ const run = mock(() => {});
77
+ const router = createRouter({ foo: { run, help: "" } });
78
+
79
+ router.route(["foo", "--json", "--", "literal"]);
80
+ expect(run).toHaveBeenCalledWith(["--", "literal"]);
81
+ });
82
+
67
83
  test("a help request never runs a command even when its help is empty", () => {
68
84
  const run = mock(() => {});
69
85
  const info = spyOn(console, "info").mockImplementation(() => {});
@@ -47,17 +47,21 @@ export function parseRoutes(routesDef: RouteDef, prefix?: string) {
47
47
  }
48
48
 
49
49
  function route(parsedRoutes: Array<ParsedRoute>, rawArgs: Array<string>) {
50
- // Stripped here so commands with strict `parseArgs` never see an unknown "--json" option
51
- const args = rawArgs.filter((arg) => !isJsonFlag(arg));
50
+ // Anything after "--" belongs to the command, so "--json" there is search text, not a flag.
51
+ const separatorIndex = rawArgs.indexOf("--");
52
+ const routableArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
53
+ const passthroughArgs = separatorIndex === -1 ? [] : rawArgs.slice(separatorIndex);
54
+ const filteredRoutableArgs = routableArgs.filter((arg) => !isJsonFlag(arg));
52
55
 
53
- if (args.length !== rawArgs.length) {
56
+ if (filteredRoutableArgs.length !== routableArgs.length) {
54
57
  setOutputMode("json");
55
58
  }
56
59
 
57
- const isHelpRequest = isHelpFlag(args.at(-1) ?? "");
60
+ const args = [...filteredRoutableArgs, ...passthroughArgs];
61
+ const isHelpRequest = isHelpFlag(filteredRoutableArgs.at(-1) ?? "");
58
62
 
59
63
  if (isHelpRequest && args.length > 1) {
60
- const namespace = toCommand(args.slice(0, -1));
64
+ const namespace = toCommand(filteredRoutableArgs.slice(0, -1));
61
65
  const namespaceHelp = getNamespaceHelp(parsedRoutes, namespace);
62
66
  if (namespaceHelp != null) {
63
67
  console.info(namespaceHelp);
@@ -1,7 +1,7 @@
1
1
  import type { RouteDef } from "../types";
2
2
 
3
3
  import { parseArgs } from "node:util";
4
- import { task, project } from "@zinn-dev/core";
4
+ import { task, project, positiveIntegerPattern, searchLimitMessage } from "@zinn-dev/core";
5
5
 
6
6
  import {
7
7
  confirmAction,
@@ -21,6 +21,8 @@ import {
21
21
  presentTask,
22
22
  } from "../presentation/task-presentation";
23
23
 
24
+ const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
25
+
24
26
  export const taskRouter = {
25
27
  edit: {
26
28
  run: (args) => {
@@ -175,6 +177,74 @@ Use --archived to list archived tasks or --all to list both.
175
177
  Priority markers: - unassigned, L low, M medium, H high, U urgent.
176
178
 
177
179
  Example: zinn task list MDR --all`,
180
+ },
181
+ search: {
182
+ run: (args) => {
183
+ const { values, positionals, tokens } = parseArgs({
184
+ args,
185
+ options: {
186
+ archived: { type: "boolean" },
187
+ all: { type: "boolean" },
188
+ limit: { type: "string" },
189
+ },
190
+ allowPositionals: true,
191
+ strict: true,
192
+ tokens: true,
193
+ });
194
+
195
+ const [query, projectKey] = positionals;
196
+
197
+ if (query == null) {
198
+ quit("A search query must be specified");
199
+ }
200
+
201
+ if (positionals.length > 2) {
202
+ quit("Only one query and one project key can be specified; quote multi-word queries");
203
+ }
204
+
205
+ validateUniqueOptions(tokens);
206
+
207
+ if (values.archived && values.all) {
208
+ quit('Use either "--archived" or "--all", not both');
209
+ }
210
+
211
+ const archive = values.all ? "all" : values.archived ? "archived" : "active";
212
+
213
+ if (values.limit !== undefined && !limitPattern.test(values.limit)) {
214
+ quit(searchLimitMessage);
215
+ }
216
+
217
+ const limit = values.limit === undefined ? undefined : Number(values.limit);
218
+ const result = task.search({ query, projectKey, archive, limit });
219
+
220
+ output(result.tasks.map(presentTask), (presentedTasks) =>
221
+ formatTaskList(presentedTasks, { showsStatus: values.all }),
222
+ );
223
+
224
+ if (result.hiddenArchivedCount > 0) {
225
+ const count = result.hiddenArchivedCount;
226
+ const noun = count === 1 ? "match" : "matches";
227
+ console.error(`${count} archived ${noun} hidden, use --all to include them`);
228
+ }
229
+ },
230
+ help: `Usage: zinn task search <query> [project-key] [--archived | --all] [--limit <n>]
231
+
232
+ Search task titles, descriptions, and comments. A comment match lists the task it belongs to.
233
+ Each word matches the start of a word, ignoring case and accents: e.g. "auth" finds "Authentication".
234
+ Every word must match. Quote a query with several words.
235
+
236
+ A query that is exactly a task key, such as MDR-1, lists that task first.
237
+ Other results are ordered by relevance, with title matches weighted highest.
238
+ Equally relevant tasks are ordered by project key, then task number.
239
+
240
+ By default, only active tasks are searched. Use --archived to search archived tasks or --all to search both.
241
+ When archived matches are hidden, a note is printed to say how many.
242
+ Use --limit to show at most <n> results.
243
+ A search result's output matches that of 'task list'.
244
+
245
+ Use -- before a query that begins with a dash.
246
+
247
+ Example: zinn task search "refinement quota" MDR --limit 5`,
178
248
  },
179
249
  view: {
180
250
  run: (args) => {