@zinn-dev/cli 0.31.0 → 0.33.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 +11 -1
- package/package.json +2 -2
- package/src/presentation/color.ts +12 -2
- package/src/routes/backup-router.ts +23 -0
- package/src/routes/router.ts +5 -1
- package/src/routes/routes.ts +2 -0
package/README.md
CHANGED
|
@@ -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 mainly for _visual_ consumption. Colors appear only when the output goes to a terminal and [`NO_COLOR`](https://no-color.org/) 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 not set. In the case that [`FORCE_COLOR`](https://force-color.org/) is set, it overrides both. Note that `FORCE_COLOR=0` turns colors off, and any other value turns them on, even when piped. Piped text is plain otherwise, 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.33.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
|
}
|
|
@@ -2,9 +2,19 @@ import { styleText } from "node:util";
|
|
|
2
2
|
|
|
3
3
|
type StyleFormat = Parameters<typeof styleText>[0];
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Bun's styleText emits ANSI even when stdout is piped or NO_COLOR is set, so Zinn decides when to color.
|
|
7
|
+
* FORCE_COLOR (https://force-color.org/) wins over NO_COLOR and the TTY check.
|
|
8
|
+
* Following https://no-color.org/, any NO_COLOR value turns color off.
|
|
9
|
+
*/
|
|
7
10
|
export function isColorEnabled() {
|
|
11
|
+
const forceColor = process.env.FORCE_COLOR ?? "";
|
|
12
|
+
const isForceColorSet = forceColor.length > 0;
|
|
13
|
+
|
|
14
|
+
if (isForceColorSet) {
|
|
15
|
+
return forceColor !== "0";
|
|
16
|
+
}
|
|
17
|
+
|
|
8
18
|
const isNoColorSet = (process.env.NO_COLOR ?? "").length > 0;
|
|
9
19
|
|
|
10
20
|
return process.stdout.isTTY === true && !isNoColorSet;
|
|
@@ -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;
|
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
|
};
|