@zinn-dev/cli 0.39.0 → 0.41.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 +171 -40
- package/index.d.ts +2 -0
- package/index.js +34 -0
- package/package.json +27 -18
- package/skills/zinn/SKILL.md +63 -0
- package/src/actor.d.ts +7 -0
- package/src/actor.js +129 -0
- package/src/capabilities-schema.d.ts +163 -0
- package/src/capabilities-schema.js +124 -0
- package/src/capabilities.d.ts +21 -0
- package/src/capabilities.js +22 -0
- package/src/database.d.ts +6 -0
- package/src/database.js +27 -0
- package/src/errors.d.ts +158 -0
- package/src/errors.js +224 -0
- package/src/input.d.ts +116 -0
- package/src/input.js +119 -0
- package/src/lib.d.ts +66 -0
- package/src/lib.js +333 -0
- package/src/presentation/activity-presentation.d.ts +23 -0
- package/src/presentation/activity-presentation.js +403 -0
- package/src/presentation/color.d.ts +9 -0
- package/src/presentation/color.js +21 -0
- package/src/presentation/column-presentation.d.ts +14 -0
- package/src/presentation/column-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +3 -0
- package/src/presentation/description-presentation.js +11 -0
- package/src/presentation/info-presentation.d.ts +4 -0
- package/src/presentation/info-presentation.js +96 -0
- package/src/presentation/row-layout.d.ts +22 -0
- package/src/presentation/row-layout.js +58 -0
- package/src/presentation/section.d.ts +4 -0
- package/src/presentation/section.js +9 -0
- package/src/presentation/task-presentation.d.ts +9 -0
- package/src/presentation/task-presentation.js +62 -0
- package/src/presentation/time.d.ts +1 -0
- package/src/presentation/time.js +13 -0
- package/src/project.d.ts +12 -0
- package/src/project.js +44 -0
- package/src/release-identity.d.ts +2 -0
- package/src/release-identity.js +1 -0
- package/src/result-schemas.d.ts +987 -0
- package/src/result-schemas.js +220 -0
- package/src/results.d.ts +23 -0
- package/src/results.js +17 -0
- package/src/routes/activity-router.d.ts +81 -0
- package/src/routes/activity-router.js +119 -0
- package/src/routes/backup-router.d.ts +21 -0
- package/src/routes/backup-router.js +30 -0
- package/src/routes/capabilities-router.d.ts +21 -0
- package/src/routes/capabilities-router.js +28 -0
- package/src/routes/comment-router.d.ts +203 -0
- package/src/routes/comment-router.js +241 -0
- package/src/routes/info-router.d.ts +21 -0
- package/src/routes/info-router.js +29 -0
- package/src/routes/label-router.d.ts +183 -0
- package/src/routes/label-router.js +218 -0
- package/src/routes/migrate-router.d.ts +21 -0
- package/src/routes/migrate-router.js +49 -0
- package/src/routes/project-router.d.ts +389 -0
- package/src/routes/project-router.js +514 -0
- package/src/routes/reindex-router.d.ts +21 -0
- package/src/routes/reindex-router.js +33 -0
- package/src/routes/relation-router.d.ts +124 -0
- package/src/routes/relation-router.js +223 -0
- package/src/routes/restore-router.d.ts +33 -0
- package/src/routes/restore-router.js +88 -0
- package/src/routes/router.d.ts +6 -0
- package/src/routes/router.js +204 -0
- package/src/routes/routes.d.ts +1735 -0
- package/src/routes/routes.js +23 -0
- package/src/routes/task-router.d.ts +945 -0
- package/src/routes/task-router.js +789 -0
- package/src/text-edit.d.ts +43 -0
- package/src/text-edit.js +57 -0
- package/src/types.d.ts +24 -0
- package/src/types.js +1 -0
- package/index.ts +0 -26
- package/release-stamp.json +0 -1
- package/src/actor.test.ts +0 -41
- package/src/actor.ts +0 -78
- package/src/database.test.ts +0 -70
- package/src/database.ts +0 -41
- package/src/lib.test.ts +0 -86
- package/src/lib.ts +0 -159
- package/src/presentation/activity-presentation.test.ts +0 -112
- package/src/presentation/activity-presentation.ts +0 -490
- package/src/presentation/color.ts +0 -29
- package/src/presentation/column-presentation.ts +0 -48
- package/src/presentation/description-presentation.ts +0 -18
- package/src/presentation/row-layout.ts +0 -77
- package/src/presentation/section.ts +0 -16
- package/src/presentation/task-presentation.ts +0 -92
- package/src/presentation/time.ts +0 -17
- package/src/project.test.ts +0 -479
- package/src/project.ts +0 -53
- package/src/routes/activity-router.ts +0 -81
- package/src/routes/backup-router.ts +0 -24
- package/src/routes/comment-router.ts +0 -171
- package/src/routes/label-router.ts +0 -168
- package/src/routes/migrate-router.test.ts +0 -31
- package/src/routes/migrate-router.ts +0 -48
- package/src/routes/project-router.ts +0 -415
- package/src/routes/reindex-router.ts +0 -27
- package/src/routes/relation-router.ts +0 -194
- package/src/routes/restore-router.test.ts +0 -44
- package/src/routes/restore-router.ts +0 -90
- package/src/routes/router.test.ts +0 -136
- package/src/routes/router.ts +0 -248
- package/src/routes/routes.ts +0 -20
- package/src/routes/task-router.ts +0 -649
- package/src/text-edit.ts +0 -68
- package/src/types.ts +0 -6
package/src/lib.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { assertWritable, ReadOnlyDatabaseError, TextEditMatchError, UnmarkedDatabaseError, } from "@zinn-dev/core";
|
|
3
|
+
import { CliError, classifyFailure } from "./errors.js";
|
|
4
|
+
import { helpSpellings, routerOptionNames, positionalWords } from "./input.js";
|
|
5
|
+
let outputMode = "text";
|
|
6
|
+
let legacyReadAllowed = false;
|
|
7
|
+
const diagnostics = [];
|
|
8
|
+
const DOUBLE_DASH = "--";
|
|
9
|
+
export function setOutputMode(mode) {
|
|
10
|
+
outputMode = mode;
|
|
11
|
+
}
|
|
12
|
+
/** Selects output before routing, without treating words after `--` as flags. */
|
|
13
|
+
export function prepareOutput(args) {
|
|
14
|
+
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
15
|
+
const options = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
|
|
16
|
+
setOutputMode(options.some(isJsonFlag) ? "json" : "text");
|
|
17
|
+
}
|
|
18
|
+
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
19
|
+
export function diagnostic(message) {
|
|
20
|
+
if (outputMode === "json") {
|
|
21
|
+
diagnostics.push(message);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
console.error(message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function flushDiagnostics() {
|
|
28
|
+
for (const message of diagnostics.splice(0)) {
|
|
29
|
+
console.error(message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function isJsonFlag(flag) {
|
|
33
|
+
return flag === `--${routerOptionNames.json}`;
|
|
34
|
+
}
|
|
35
|
+
export function isAllowLegacyReadFlag(flag) {
|
|
36
|
+
return flag === `--${routerOptionNames.legacyRead}`;
|
|
37
|
+
}
|
|
38
|
+
/** A flag the router reads wherever it appears before --, for every command. */
|
|
39
|
+
export function isRouterFlag(flag) {
|
|
40
|
+
return isJsonFlag(flag) || isAllowLegacyReadFlag(flag);
|
|
41
|
+
}
|
|
42
|
+
export function setLegacyReadAllowed(allowed) {
|
|
43
|
+
legacyReadAllowed = allowed;
|
|
44
|
+
}
|
|
45
|
+
export function isLegacyReadAllowed() {
|
|
46
|
+
return legacyReadAllowed;
|
|
47
|
+
}
|
|
48
|
+
export function output(data, transformToString) {
|
|
49
|
+
if (outputMode === "json") {
|
|
50
|
+
console.info(JSON.stringify(data, null, 2));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const dataText = transformToString(data);
|
|
54
|
+
if (dataText.length > 0) {
|
|
55
|
+
console.info(dataText);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Asks before a change that cannot be undone, unless --yes already confirmed it. */
|
|
59
|
+
export async function confirmAction(message, isPreconfirmed, jsonRefusal) {
|
|
60
|
+
// Throws on a read-only database, to avoid asking for confirmation to an already refused action
|
|
61
|
+
assertWritable();
|
|
62
|
+
return askConfirmation(message, isPreconfirmed, jsonRefusal);
|
|
63
|
+
}
|
|
64
|
+
export const confirmationDescription = "Requires --yes with --json or without a terminal. Otherwise prompts on stderr and only y or Y confirms. Declining exits successfully without the requested mutation; interruption exits 130.";
|
|
65
|
+
/** Like confirmAction, without opening the database, for commands that bypass the open policy. */
|
|
66
|
+
export async function askConfirmation(message, isPreconfirmed, jsonRefusal = "Commands that ask for confirmation need --yes when used with --json") {
|
|
67
|
+
if (isPreconfirmed) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (outputMode === "json") {
|
|
71
|
+
quit(jsonRefusal, undefined, { argument: "--yes", reason: "confirmation_required" });
|
|
72
|
+
}
|
|
73
|
+
// Refuses rather than treating an unanswered prompt as declined, so scripts do not see a false success
|
|
74
|
+
if (!canPrompt()) {
|
|
75
|
+
quit("Commands that ask for confirmation need --yes when not running in a terminal", undefined, { argument: "--yes", reason: "confirmation_required" });
|
|
76
|
+
}
|
|
77
|
+
const prompt = createInterface({ input: process.stdin, output: process.stderr });
|
|
78
|
+
const closed = new AbortController();
|
|
79
|
+
prompt.once("close", () => closed.abort());
|
|
80
|
+
prompt.once("SIGINT", () => process.kill(process.pid, "SIGINT"));
|
|
81
|
+
try {
|
|
82
|
+
const answer = await prompt.question(`${message} [y/N] `, { signal: closed.signal });
|
|
83
|
+
return answer === "y" || answer === "Y";
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (closed.signal.aborted) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
// Readline echoes a newline in a terminal; redirected stderr and EOF need one explicitly.
|
|
93
|
+
if (!process.stderr.isTTY || closed.signal.aborted) {
|
|
94
|
+
process.stderr.write("\n");
|
|
95
|
+
}
|
|
96
|
+
prompt.close();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Whether someone can answer a prompt: stdin and stdout are both terminals, like how gh decides it. */
|
|
100
|
+
export function canPrompt() {
|
|
101
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
102
|
+
}
|
|
103
|
+
/** The message to report for a failed command, or fallback when the error has none. */
|
|
104
|
+
export function failureMessage(error, fallback) {
|
|
105
|
+
const isOlderReadOnly = error instanceof ReadOnlyDatabaseError && error.reason === "older";
|
|
106
|
+
if (isOlderReadOnly) {
|
|
107
|
+
return `${error.message}. Run \`zinn migrate\` to upgrade it.`;
|
|
108
|
+
}
|
|
109
|
+
if (error instanceof UnmarkedDatabaseError) {
|
|
110
|
+
return `${error.message}. Add --allow-legacy-read to read it anyway.`;
|
|
111
|
+
}
|
|
112
|
+
if (error instanceof TextEditMatchError && error.matchCount > 1) {
|
|
113
|
+
return `${error.message} Use --all to replace every match.`;
|
|
114
|
+
}
|
|
115
|
+
if (error?.message === "no such table: task_search") {
|
|
116
|
+
return `${error.message}. Run \`zinn reindex\` to rebuild the search index.`;
|
|
117
|
+
}
|
|
118
|
+
return typeof error?.message === "string" ? error.message : fallback;
|
|
119
|
+
}
|
|
120
|
+
/** Stops a command while retaining its classified error for the outer renderer. */
|
|
121
|
+
export function quit(reason, help, details) {
|
|
122
|
+
if (reason instanceof Error) {
|
|
123
|
+
throw reason;
|
|
124
|
+
}
|
|
125
|
+
throw new CliError(reason, "invalid_input", details, help);
|
|
126
|
+
}
|
|
127
|
+
/** Emits one handled failure, including any notices collected before it. */
|
|
128
|
+
export function renderFailure(reason) {
|
|
129
|
+
const failure = {
|
|
130
|
+
...classifyFailure(reason),
|
|
131
|
+
message: failureMessage(reason, "Something went wrong"),
|
|
132
|
+
};
|
|
133
|
+
const pendingDiagnostics = diagnostics.splice(0);
|
|
134
|
+
if (outputMode === "json") {
|
|
135
|
+
const details = failure.details === undefined
|
|
136
|
+
? undefined
|
|
137
|
+
: Object.fromEntries(Object.entries(failure.details).filter(([, value]) => value !== undefined));
|
|
138
|
+
const error = {
|
|
139
|
+
...failure,
|
|
140
|
+
details: details !== undefined && Object.keys(details).length > 0 ? details : undefined,
|
|
141
|
+
diagnostics: pendingDiagnostics.length > 0 ? pendingDiagnostics : undefined,
|
|
142
|
+
};
|
|
143
|
+
console.error(JSON.stringify({ error }, null, 2));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
for (const message of pendingDiagnostics) {
|
|
147
|
+
console.error(message);
|
|
148
|
+
}
|
|
149
|
+
console.error(failure.help == null ? failure.message : `${failure.message}\n\n${failure.help}`);
|
|
150
|
+
}
|
|
151
|
+
// Let piped stderr finish writing before Node exits
|
|
152
|
+
process.stderr.write("", () => process.exit(1));
|
|
153
|
+
}
|
|
154
|
+
/** A command was given the wrong words. The router prints the message with the command's usage lines. */
|
|
155
|
+
export class UsageError extends CliError {
|
|
156
|
+
constructor(message, details) {
|
|
157
|
+
super(message, "invalid_input", details);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Checks a command's words against its usage line, with the words written the same way:
|
|
162
|
+
* `<task-key>` is required, `[<project-key>]` is optional and `<task-key>...` repeats.
|
|
163
|
+
* Optional words go last.
|
|
164
|
+
*/
|
|
165
|
+
export function validatePositionals(positionals, form) {
|
|
166
|
+
const words = positionalWords(form);
|
|
167
|
+
const requiredWords = words.filter((word) => !word.startsWith("["));
|
|
168
|
+
const missingWord = requiredWords[positionals.length];
|
|
169
|
+
if (missingWord !== undefined) {
|
|
170
|
+
throw new UsageError(`Missing argument ${missingWord}`, {
|
|
171
|
+
argument: missingWord.replaceAll(/[\[\]<>]/g, "").replace(/\.\.\.$/, ""),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const hasRepeatingWord = words.some((word) => word.endsWith("..."));
|
|
175
|
+
const extraWord = positionals[words.length];
|
|
176
|
+
if (!hasRepeatingWord && extraWord !== undefined) {
|
|
177
|
+
throw new UsageError(`Unexpected argument "${extraWord}"`, { field: [] });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export function validateUniqueOptions(tokens, options) {
|
|
181
|
+
const repeatableOptions = Object.keys(options).filter((name) => options[name].multiple);
|
|
182
|
+
const parsedArgs = new Set();
|
|
183
|
+
for (const token of tokens) {
|
|
184
|
+
if (token.kind !== "option") {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const isRepeatable = repeatableOptions.includes(token.name);
|
|
188
|
+
if (parsedArgs.has(token.name) && !isRepeatable) {
|
|
189
|
+
quit(`Option "--${token.name}" can only be specified once`, undefined, {
|
|
190
|
+
argument: `--${token.name}`,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
parsedArgs.add(token.name);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** Selects an order form after checking its required leading words. */
|
|
197
|
+
export function validateOrderForms(positionals, forms) {
|
|
198
|
+
const firstForm = forms[0];
|
|
199
|
+
const directionIndex = firstForm.positionals.findIndex(({ name }) => name === "direction");
|
|
200
|
+
const leadingPositionals = firstForm.positionals.slice(0, directionIndex + 1);
|
|
201
|
+
const directions = forms.flatMap((form) => form.positionals[directionIndex].value.choices);
|
|
202
|
+
leadingPositionals[directionIndex] = {
|
|
203
|
+
...leadingPositionals[directionIndex],
|
|
204
|
+
value: { kind: "enum", choices: directions },
|
|
205
|
+
};
|
|
206
|
+
validatePositionals(positionals.slice(0, leadingPositionals.length), {
|
|
207
|
+
id: "leading",
|
|
208
|
+
positionals: leadingPositionals,
|
|
209
|
+
});
|
|
210
|
+
const direction = positionals[directionIndex];
|
|
211
|
+
const form = forms.find((candidate) => candidate.positionals[directionIndex].value.choices.includes(direction));
|
|
212
|
+
if (form === undefined) {
|
|
213
|
+
throw new UsageError(`Unknown order direction "${direction}"`, { argument: "direction" });
|
|
214
|
+
}
|
|
215
|
+
validatePositionals(positionals, form);
|
|
216
|
+
return form;
|
|
217
|
+
}
|
|
218
|
+
export function requireStringOption(option, value, name, message) {
|
|
219
|
+
if (value === undefined) {
|
|
220
|
+
quit(message, undefined, { argument: `--${name}` });
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
224
|
+
export function isHelpFlag(flag) {
|
|
225
|
+
return helpSpellings.includes(flag);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Help sentence for a flag whose value may begin with a dash, such as a Markdown bullet.
|
|
229
|
+
* `parseArgs` refuses `--flag -value`, since a value that looks like an option may mean the value
|
|
230
|
+
* was forgotten, so we respect that refusal and not take the next word as the value
|
|
231
|
+
* @see {@link https://github.com/pkgjs/parseargs/issues/77}
|
|
232
|
+
*/
|
|
233
|
+
export function dashValueHelp(flag) {
|
|
234
|
+
return `A value that begins with a dash must be joined to its flag with =, as in ${flag}='- item'.`;
|
|
235
|
+
}
|
|
236
|
+
// "Option '--title' argument is ambiguous."
|
|
237
|
+
const DASH_VALUE_ERROR_PATTERN = /^Option '(--[^']+)' argument is ambiguous\./;
|
|
238
|
+
// The characters Python's `shlex.quote` leaves unquoted.
|
|
239
|
+
const SHELL_SAFE_WORD_PATTERN = /^[\w@%+=:,./-]+$/;
|
|
240
|
+
/** Quotes a word for a POSIX shell when it needs it, like Python's `shlex.quote` */
|
|
241
|
+
export function shellQuote(word) {
|
|
242
|
+
if (SHELL_SAFE_WORD_PATTERN.test(word)) {
|
|
243
|
+
return word;
|
|
244
|
+
}
|
|
245
|
+
return `'${word.replaceAll("'", `'\\''`)}'`;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The message for `parseArgs` refusal of a value that begins with a dash, showing the user's
|
|
249
|
+
* command with that value joined to its flag.
|
|
250
|
+
* `null` for any other error
|
|
251
|
+
*/
|
|
252
|
+
function dashValueMessage(error, args) {
|
|
253
|
+
const isInvalidOptionValue = error?.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE";
|
|
254
|
+
const flag = isInvalidOptionValue ? DASH_VALUE_ERROR_PATTERN.exec(error.message)?.[1] : undefined;
|
|
255
|
+
const flagIndex = args.findIndex((arg, index) => arg === flag && args[index + 1]?.startsWith("-"));
|
|
256
|
+
if (flagIndex === -1) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const value = args[flagIndex + 1];
|
|
260
|
+
const fixedCommand = [
|
|
261
|
+
"zinn",
|
|
262
|
+
...args.slice(0, flagIndex).map(shellQuote),
|
|
263
|
+
`${flag}=${shellQuote(value)}`,
|
|
264
|
+
...args.slice(flagIndex + 2).map(shellQuote),
|
|
265
|
+
].join(" ");
|
|
266
|
+
return `Option "${flag}" is followed by "${value}", which begins with a dash. If it is the value, join it to the flag with =: ${fixedCommand}`;
|
|
267
|
+
}
|
|
268
|
+
// "Unknown option '--project'."
|
|
269
|
+
const UNKNOWN_LONG_OPTION_PATTERN = /^Unknown option '(--[^']+)'/;
|
|
270
|
+
// A word that begins with a single dash, such as -later.
|
|
271
|
+
const SHORT_OPTION_WORD_PATTERN = /^-[^-]/;
|
|
272
|
+
/** A command line to show, with each word quoted for the shell as needed. */
|
|
273
|
+
function formatCommand(args) {
|
|
274
|
+
return ["zinn", ...args].map(shellQuote).join(" ");
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The message for `parseArgs` refusal of an unknown option.
|
|
278
|
+
* A long flag is named, with the command the user likely meant when one is known,
|
|
279
|
+
* and otherwise the usage line shown with it is the fix.
|
|
280
|
+
* A word with a single dash shows the user's command with it after `--`.
|
|
281
|
+
*/
|
|
282
|
+
function unknownOptionMessage(message, args, suggestFor) {
|
|
283
|
+
const flag = UNKNOWN_LONG_OPTION_PATTERN.exec(message)?.[1];
|
|
284
|
+
if (flag !== undefined) {
|
|
285
|
+
const suggestion = suggestFor(flag);
|
|
286
|
+
const reason = `Unknown option "${flag}"`;
|
|
287
|
+
return suggestion === undefined
|
|
288
|
+
? reason
|
|
289
|
+
: `${reason}. Did you mean: ${formatCommand([...suggestion, ...args.filter(isRouterFlag)])}`;
|
|
290
|
+
}
|
|
291
|
+
// Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
|
|
292
|
+
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
293
|
+
const optionArgs = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
|
|
294
|
+
const wordIndex = optionArgs.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
|
|
295
|
+
if (wordIndex === -1) {
|
|
296
|
+
return message;
|
|
297
|
+
}
|
|
298
|
+
const word = args[wordIndex];
|
|
299
|
+
const readOptions = [...word.slice(1)].map((letter) => `-${letter}`);
|
|
300
|
+
const readAs = readOptions.length > 1 ? ` (Zinn read ${word} as ${readOptions.join(" ")})` : "";
|
|
301
|
+
const reason = `Unknown option "${readOptions[0]}"${readAs}. If it is a value, put it after --`;
|
|
302
|
+
// Flags after the word must stay before --, and only the router's own flags are known to be flags.
|
|
303
|
+
const wordsAfter = args.slice(wordIndex + 1);
|
|
304
|
+
const routerFlagsAfter = wordsAfter.filter(isRouterFlag);
|
|
305
|
+
const plainWordsAfter = wordsAfter.filter((arg) => !isRouterFlag(arg));
|
|
306
|
+
if (plainWordsAfter.some((arg) => arg.startsWith("-"))) {
|
|
307
|
+
return `${reason}.`;
|
|
308
|
+
}
|
|
309
|
+
const fixedCommand = formatCommand([
|
|
310
|
+
...args.slice(0, wordIndex),
|
|
311
|
+
...routerFlagsAfter,
|
|
312
|
+
DOUBLE_DASH,
|
|
313
|
+
word,
|
|
314
|
+
...plainWordsAfter,
|
|
315
|
+
]);
|
|
316
|
+
return `${reason}: ${fixedCommand}`;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* The message for an argument error from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
320
|
+
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
321
|
+
* `null` for any other error.
|
|
322
|
+
*/
|
|
323
|
+
export function parseArgsMessage(error, args, suggestFor) {
|
|
324
|
+
const code = error?.code;
|
|
325
|
+
const isParseArgsError = typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
326
|
+
if (!isParseArgsError) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
330
|
+
return unknownOptionMessage(error.message, args, suggestFor);
|
|
331
|
+
}
|
|
332
|
+
return dashValueMessage(error, args) ?? error.message;
|
|
333
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Activity, ActivityTaskIdentity } from "@zinn-dev/core";
|
|
2
|
+
type NavigationIdentity = {
|
|
3
|
+
/** Undefined when the entity no longer exists and this event recorded no name for it. */
|
|
4
|
+
name?: string;
|
|
5
|
+
status: "current" | "archived" | "deleted";
|
|
6
|
+
distinguishesTaskId?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type PresentedActivity = {
|
|
9
|
+
event: Activity;
|
|
10
|
+
displayId: string;
|
|
11
|
+
navigation: NavigationIdentity;
|
|
12
|
+
removedTasks: Array<ActivityTaskIdentity>;
|
|
13
|
+
};
|
|
14
|
+
/** Neighbors in sorted UUID order determine the shortest globally unique left prefix. */
|
|
15
|
+
export declare function abbreviateActivityIds(ids: Array<string>): Map<string, string>;
|
|
16
|
+
export declare function presentActivities(events: Array<Activity>, options?: {
|
|
17
|
+
taskKey?: string;
|
|
18
|
+
showsFullIds?: boolean;
|
|
19
|
+
}): Array<PresentedActivity>;
|
|
20
|
+
export declare function formatActivityList(entries: Array<PresentedActivity>, options?: {
|
|
21
|
+
showsDetails?: boolean;
|
|
22
|
+
}): string;
|
|
23
|
+
export {};
|