@zinn-dev/cli 0.30.0 → 0.32.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
|
@@ -144,7 +144,7 @@ Label names preserve their stored casing, but matching and uniqueness are case-i
|
|
|
144
144
|
|
|
145
145
|
Descriptions default to an empty string and the label colors default to white. Available colors are _red_, _green_, _yellow_, _blue_, _magenta_, _cyan_, _white_, and _gray_.
|
|
146
146
|
|
|
147
|
-
`label create` and `label list` print each label name in its color. `--json` output shows the color as a value
|
|
147
|
+
`label create`, `label edit` and `label list` print each label name in its color. When color is off (see [Scripting and JSON output](#scripting-and-json-output)), they name the color instead, such as `bug | red | Broken`. `--json` output always shows the color as a value.
|
|
148
148
|
|
|
149
149
|
`label edit` changes only the supplied name, color, or description. Renaming preserves every task attachment because attachments refer to the label's internal ID. Also, updating a label does not affect any tasks' timestamps that it is attached to.
|
|
150
150
|
|
|
@@ -263,6 +263,16 @@ zinn task unarchive MDR-1
|
|
|
263
263
|
|
|
264
264
|
Delete a task permanently with `zinn task delete MDR-1`. It asks for confirmation before performing the action, unless `--yes` is used (see [Confirmations](#confirmations)).
|
|
265
265
|
|
|
266
|
+
## Back up the database
|
|
267
|
+
|
|
268
|
+
It is recommended to save a copy of the database before installing a new version:
|
|
269
|
+
|
|
270
|
+
```sh
|
|
271
|
+
zinn backup
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The copy goes to `~/.zinn/backups/` (or `backups/` in `ZINN_DIR`), in a file named after the UTC time and the CLI version that made it, like `2026-09-29T12-30-05Z-cli-0.32.0.sqlite`. It is a single file with every change made so far, and it is safe to take while Zinn is in use. Existing backups are never overwritten. With `--json`, the command prints `{ "path": "..." }`. It fails when there is no database yet.
|
|
275
|
+
|
|
266
276
|
## Scripting and JSON output
|
|
267
277
|
|
|
268
278
|
Add `--json` to any command to get JSON instead of text. The flag can go anywhere in the command, except after `--`, where it is treated as a regular argument such as searching literally for `--json` in text.
|
|
@@ -276,7 +286,7 @@ zinn task create MDR --title "Refine the numbers" --json
|
|
|
276
286
|
- Output is a single JSON document on stdout. Empty lists print `[]`.
|
|
277
287
|
- Errors go to stderr as `{ "error": { "message": "..." } }`, stdout stays empty, and the command exits with code 1.
|
|
278
288
|
|
|
279
|
-
Text output is
|
|
289
|
+
Text output is mainly for _visual_ consumption. Colors appear only when the output goes to a terminal and [`NO_COLOR`](https://no-color.org/) is unset or empty. Piped text is plain, but its layout may change between versions. Scripts should use `--json` to get reliable output.
|
|
280
290
|
|
|
281
291
|
### Confirmations
|
|
282
292
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zinn-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.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.22.0"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
|
|
3
|
+
type StyleFormat = Parameters<typeof styleText>[0];
|
|
4
|
+
|
|
5
|
+
// Bun's styleText emits ANSI even when stdout is piped or NO_COLOR is set, so Zinn decides when to color.
|
|
6
|
+
// Following https://no-color.org/, any non-empty NO_COLOR value turns color off.
|
|
7
|
+
export function isColorEnabled() {
|
|
8
|
+
const isNoColorSet = (process.env.NO_COLOR ?? "").length > 0;
|
|
9
|
+
|
|
10
|
+
return process.stdout.isTTY === true && !isNoColorSet;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function styleOutputText(format: StyleFormat, text: string) {
|
|
14
|
+
if (!isColorEnabled()) {
|
|
15
|
+
return text;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return styleText(format, text);
|
|
19
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TaskPriority, TaskWithKey } from "@zinn-dev/core";
|
|
2
2
|
|
|
3
|
-
import { styleText } from "node:util";
|
|
4
3
|
import { column, task } from "@zinn-dev/core";
|
|
5
4
|
|
|
6
5
|
import { TASK_DESCRIPTION_PREVIEW_LENGTH } from "../constant";
|
|
6
|
+
import { styleOutputText } from "./color";
|
|
7
7
|
|
|
8
8
|
function formatTaskDescriptionPreview(description: string | null) {
|
|
9
9
|
if (description == null) {
|
|
@@ -42,11 +42,11 @@ export function formatTaskColumn(columnName: string, width = columnName.length)
|
|
|
42
42
|
|
|
43
43
|
// TODO: Derive column colors from column roles once roles exist instead of relying on names.
|
|
44
44
|
if (columnName === "Backlog") {
|
|
45
|
-
return
|
|
45
|
+
return styleOutputText("gray", paddedColumnName);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (columnName === "Done") {
|
|
49
|
-
return
|
|
49
|
+
return styleOutputText("green", paddedColumnName);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
return paddedColumnName;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Command } from "../types";
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { backup } from "@zinn-dev/core";
|
|
5
|
+
|
|
6
|
+
import { output } from "../lib";
|
|
7
|
+
import packageJson from "../../package.json";
|
|
8
|
+
|
|
9
|
+
export const backupCommand = {
|
|
10
|
+
run: (args) => {
|
|
11
|
+
parseArgs({ args, strict: true, allowPositionals: false });
|
|
12
|
+
|
|
13
|
+
const created = backup.create({ client: "cli", version: packageJson.version });
|
|
14
|
+
|
|
15
|
+
output(created, (b) => `Saved a backup to ${b.path}`);
|
|
16
|
+
},
|
|
17
|
+
help: `Usage: zinn backup
|
|
18
|
+
|
|
19
|
+
Save a copy of the database to ~/.zinn/backups/, or to backups/ in ZINN_DIR when it is set.
|
|
20
|
+
|
|
21
|
+
The copy includes recent writes and is safe to take while Zinn is in use.
|
|
22
|
+
Fails when there is no database yet. Existing backups are never overwritten.`,
|
|
23
|
+
} satisfies Command;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Label } from "@zinn-dev/core";
|
|
2
2
|
import type { RouteDef } from "../types";
|
|
3
3
|
|
|
4
|
-
import { parseArgs
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
5
|
import { label, labelCreateSchema, labelDeleteSchema, labelEditSchema } from "@zinn-dev/core";
|
|
6
6
|
|
|
7
7
|
import {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
validateUniqueOptions,
|
|
13
13
|
} from "../lib";
|
|
14
14
|
import { currentActor } from "../actor";
|
|
15
|
+
import { isColorEnabled, styleOutputText } from "../presentation/color";
|
|
15
16
|
|
|
16
17
|
type PresentedLabel = Omit<Label, "id">;
|
|
17
18
|
|
|
@@ -20,13 +21,16 @@ function presentLabel(labelMatch: Label): PresentedLabel {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function formatLabel(presented: PresentedLabel) {
|
|
23
|
-
|
|
24
|
+
// The colored name shows the color; without color, the color is named instead.
|
|
25
|
+
const name = isColorEnabled()
|
|
26
|
+
? styleOutputText(presented.color, presented.name)
|
|
27
|
+
: `${presented.name} | ${presented.color}`;
|
|
24
28
|
|
|
25
29
|
if (presented.description.length === 0) {
|
|
26
|
-
return
|
|
30
|
+
return name;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
return `${
|
|
33
|
+
return `${name} | ${presented.description}`;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
export const labelRouter = {
|
package/src/routes/router.ts
CHANGED
|
@@ -11,6 +11,7 @@ function toCommand(args: Array<string>) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// Groups sibling commands into one line, e.g. " comment {create|list|edit|delete}".
|
|
14
|
+
// A command without siblings is not a choice, so it gets no braces, e.g. " backup".
|
|
14
15
|
function formatCommands(parsedRoutes: Array<ParsedRoute>, prefix: string) {
|
|
15
16
|
const siblingsByParent = new Map<string, Array<string>>();
|
|
16
17
|
for (const { command } of parsedRoutes) {
|
|
@@ -24,7 +25,10 @@ function formatCommands(parsedRoutes: Array<ParsedRoute>, prefix: string) {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
return [...siblingsByParent]
|
|
27
|
-
.map(([parent, siblings]) =>
|
|
28
|
+
.map(([parent, siblings]) => {
|
|
29
|
+
const commands = siblings.length === 1 ? siblings[0] : `{${siblings.join("|")}}`;
|
|
30
|
+
return ` ${parent === "" ? "" : `${parent} `}${commands}`;
|
|
31
|
+
})
|
|
28
32
|
.join("\n");
|
|
29
33
|
}
|
|
30
34
|
|
package/src/routes/routes.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { projectRouter } from "./project-router";
|
|
2
2
|
import { taskRouter } from "./task-router";
|
|
3
3
|
import { labelRouter } from "./label-router";
|
|
4
|
+
import { backupCommand } from "./backup-router";
|
|
4
5
|
|
|
5
6
|
// TODO: lazy load?
|
|
6
7
|
export const routes = {
|
|
7
8
|
project: projectRouter,
|
|
8
9
|
task: taskRouter,
|
|
9
10
|
label: labelRouter,
|
|
11
|
+
backup: backupCommand,
|
|
10
12
|
};
|