@duyquangnvx/agent-cli 0.0.0-stage → 0.1.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/CHANGELOG.md +22 -0
- package/dist/built-ins.d.ts +4 -0
- package/dist/built-ins.js +20 -0
- package/dist/built-ins.js.map +1 -0
- package/dist/confirm.d.ts +8 -0
- package/dist/confirm.js +22 -0
- package/dist/confirm.js.map +1 -0
- package/dist/define.d.ts +108 -0
- package/dist/define.js +8 -0
- package/dist/define.js.map +1 -0
- package/dist/doctor-rows.d.ts +3 -0
- package/dist/doctor-rows.js +115 -0
- package/dist/doctor-rows.js.map +1 -0
- package/dist/doctor.d.ts +3 -0
- package/dist/doctor.js +100 -0
- package/dist/doctor.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.js +72 -0
- package/dist/errors.js.map +1 -0
- package/dist/execute.d.ts +12 -0
- package/dist/execute.js +18 -0
- package/dist/execute.js.map +1 -0
- package/dist/fields.d.ts +14 -0
- package/dist/fields.js +71 -0
- package/dist/fields.js.map +1 -0
- package/dist/flags.d.ts +12 -0
- package/dist/flags.js +22 -0
- package/dist/flags.js.map +1 -0
- package/dist/global-install.d.ts +11 -0
- package/dist/global-install.js +50 -0
- package/dist/global-install.js.map +1 -0
- package/dist/help-json.d.ts +4 -0
- package/dist/help-json.js +60 -0
- package/dist/help-json.js.map +1 -0
- package/dist/help.d.ts +6 -0
- package/dist/help.js +61 -0
- package/dist/help.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +22 -0
- package/dist/input.js +70 -0
- package/dist/input.js.map +1 -0
- package/dist/interrupts.d.ts +18 -0
- package/dist/interrupts.js +118 -0
- package/dist/interrupts.js.map +1 -0
- package/dist/invocation.d.ts +9 -0
- package/dist/invocation.js +37 -0
- package/dist/invocation.js.map +1 -0
- package/dist/npm.d.ts +24 -0
- package/dist/npm.js +181 -0
- package/dist/npm.js.map +1 -0
- package/dist/page.d.ts +26 -0
- package/dist/page.js +49 -0
- package/dist/page.js.map +1 -0
- package/dist/parse-input.d.ts +5 -0
- package/dist/parse-input.js +114 -0
- package/dist/parse-input.js.map +1 -0
- package/dist/run-cli.d.ts +20 -0
- package/dist/run-cli.js +211 -0
- package/dist/run-cli.js.map +1 -0
- package/dist/run-process.d.ts +2 -0
- package/dist/run-process.js +37 -0
- package/dist/run-process.js.map +1 -0
- package/dist/semver.d.ts +9 -0
- package/dist/semver.js +70 -0
- package/dist/semver.js.map +1 -0
- package/dist/skills.d.ts +11 -0
- package/dist/skills.js +58 -0
- package/dist/skills.js.map +1 -0
- package/dist/style.d.ts +13 -0
- package/dist/style.js +38 -0
- package/dist/style.js.map +1 -0
- package/dist/suggest.d.ts +2 -0
- package/dist/suggest.js +41 -0
- package/dist/suggest.js.map +1 -0
- package/dist/update.d.ts +3 -0
- package/dist/update.js +91 -0
- package/dist/update.js.map +1 -0
- package/dist/upgrade-notes.d.ts +9 -0
- package/dist/upgrade-notes.js +41 -0
- package/dist/upgrade-notes.js.map +1 -0
- package/dist/usage.d.ts +13 -0
- package/dist/usage.js +72 -0
- package/dist/usage.js.map +1 -0
- package/package.json +32 -3
- package/README.md +0 -3
package/dist/fields.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { UsageError } from "./errors.js";
|
|
2
|
+
import { rowSchemaOf } from "./page.js";
|
|
3
|
+
const SEPARATOR = ",";
|
|
4
|
+
const COLUMN_SEPARATOR = "\t";
|
|
5
|
+
const UNSAFE_IN_COLUMN = /[\t\n\r]/;
|
|
6
|
+
export const FIELDS_OPTION = "--fields";
|
|
7
|
+
/** The fields a list Command's rows have, or undefined for a Command that is not a list. */
|
|
8
|
+
export function rowFieldsOf(command) {
|
|
9
|
+
const row = rowSchemaOf(command.output);
|
|
10
|
+
return row === undefined ? undefined : Object.keys(row.shape);
|
|
11
|
+
}
|
|
12
|
+
export function fieldsDescription(rowFields) {
|
|
13
|
+
return `print only these comma-separated fields of each row (any of: ${rowFields.join(", ")})`;
|
|
14
|
+
}
|
|
15
|
+
export function fieldsOption(rowFields) {
|
|
16
|
+
return {
|
|
17
|
+
key: "fields",
|
|
18
|
+
type: "string",
|
|
19
|
+
required: false,
|
|
20
|
+
defaultValue: undefined,
|
|
21
|
+
description: fieldsDescription(rowFields),
|
|
22
|
+
choices: undefined,
|
|
23
|
+
label: FIELDS_OPTION,
|
|
24
|
+
usage: `${FIELDS_OPTION} <a,b>`,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function quoted(names) {
|
|
28
|
+
return names.map((name) => `'${name}'`).join(", ");
|
|
29
|
+
}
|
|
30
|
+
/** The fields the caller asked for, in their order, or undefined when they gave no `--fields`. */
|
|
31
|
+
export function selectedFields(raw, rowFields, commandLine) {
|
|
32
|
+
if (raw === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const hint = `pass ${FIELDS_OPTION} with any of: ${rowFields.join(", ")}`;
|
|
36
|
+
const names = typeof raw === "string" ? raw.split(SEPARATOR).filter((name) => name !== "") : [];
|
|
37
|
+
if (names.length === 0) {
|
|
38
|
+
throw new UsageError({
|
|
39
|
+
code: "INVALID_INPUT",
|
|
40
|
+
message: `${FIELDS_OPTION}: missing value for \`${commandLine}\``,
|
|
41
|
+
hint,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const unknown = names.filter((name) => !rowFields.includes(name));
|
|
45
|
+
if (unknown.length > 0) {
|
|
46
|
+
throw new UsageError({
|
|
47
|
+
code: "UNKNOWN_FIELD",
|
|
48
|
+
message: `unknown field ${quoted(unknown)} for \`${commandLine}\``,
|
|
49
|
+
hint,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return names;
|
|
53
|
+
}
|
|
54
|
+
function fieldOf(row, field) {
|
|
55
|
+
return typeof row === "object" && row !== null ? row[field] : undefined;
|
|
56
|
+
}
|
|
57
|
+
export function projected(rows, fields) {
|
|
58
|
+
return rows.map((row) => Object.fromEntries(fields.map((field) => [field, fieldOf(row, field)])));
|
|
59
|
+
}
|
|
60
|
+
function cell(value) {
|
|
61
|
+
if (value === undefined || value === null) {
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
64
|
+
return typeof value === "string" && !UNSAFE_IN_COLUMN.test(value) ? value : JSON.stringify(value);
|
|
65
|
+
}
|
|
66
|
+
/** Selected rows as text: a header line of the field names, then one tab-separated line per row. */
|
|
67
|
+
export function renderRows(rows, fields) {
|
|
68
|
+
const lines = [fields, ...rows.map((row) => fields.map((field) => cell(row[field])))];
|
|
69
|
+
return `${lines.map((line) => line.join(COLUMN_SEPARATOR)).join("\n")}\n`;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAEpC,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AAIxC,4FAA4F;AAC5F,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,SAA4B;IAC5D,OAAO,gEAAgE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACjG,CAAC;A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,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtF,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5E,CAAC"}
|
package/dist/flags.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Command } from "./define.js";
|
|
2
|
+
type Effect = Command["effect"];
|
|
3
|
+
export interface RuntimeFlag {
|
|
4
|
+
readonly usage: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly effects: readonly Effect[];
|
|
7
|
+
}
|
|
8
|
+
export declare const JSON_FLAG: RuntimeFlag;
|
|
9
|
+
export declare const DRY_RUN_FLAG: RuntimeFlag;
|
|
10
|
+
export declare const CONFIRM_FLAG: RuntimeFlag;
|
|
11
|
+
export declare function runtimeFlagsFor(effect: Effect): readonly RuntimeFlag[];
|
|
12
|
+
export {};
|
package/dist/flags.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CONFIRM_OPTION } from "./confirm.js";
|
|
2
|
+
export const JSON_FLAG = {
|
|
3
|
+
usage: "--json",
|
|
4
|
+
description: "print the result as JSON",
|
|
5
|
+
effects: ["read", "write", "destructive"],
|
|
6
|
+
};
|
|
7
|
+
export const DRY_RUN_FLAG = {
|
|
8
|
+
usage: "--dry-run",
|
|
9
|
+
description: "print the Plan without changing anything",
|
|
10
|
+
effects: ["write", "destructive"],
|
|
11
|
+
};
|
|
12
|
+
export const CONFIRM_FLAG = {
|
|
13
|
+
usage: `${CONFIRM_OPTION} <target>`,
|
|
14
|
+
description: "name the target to confirm the change; an error hint gives the exact command",
|
|
15
|
+
effects: ["destructive"],
|
|
16
|
+
};
|
|
17
|
+
// A Command's help lists every flag here whose effects include the Command's Effect.
|
|
18
|
+
const RUNTIME_FLAGS = [JSON_FLAG, DRY_RUN_FLAG, CONFIRM_FLAG];
|
|
19
|
+
export function runtimeFlagsFor(effect) {
|
|
20
|
+
return RUNTIME_FLAGS.filter((flag) => flag.effects.includes(effect));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAW9C,MAAM,CAAC,MAAM,SAAS,GAAgB;IACpC,KAAK,EAAE,QAAQ;IACf,WAAW,EAAE,0BAA0B;IACvC,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAgB;IACvC,KAAK,EAAE,WAAW;IAClB,WAAW,EAAE,0CAA0C;IACvD,OAAO,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC;CAClC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAgB;IACvC,KAAK,EAAE,GAAG,cAAc,WAAW;IACnC,WAAW,EAAE,8EAA8E;IAC3F,OAAO,EAAE,CAAC,aAAa,CAAC;CACzB,CAAC;AAEF,qFAAqF;AACrF,MAAM,aAAa,GAA2B,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AAEtF,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type NpmContext } from "./npm.js";
|
|
2
|
+
/** Where npm installed this copy of the CLI globally. */
|
|
3
|
+
export interface InstalledCopy {
|
|
4
|
+
readonly prefix: string;
|
|
5
|
+
readonly packageDir: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The global npm install this copy runs from, found by asking npm for its global prefix.
|
|
9
|
+
* `bin` is the script that started the CLI; throws `NOT_GLOBAL_INSTALL` when it is not inside that install.
|
|
10
|
+
*/
|
|
11
|
+
export declare function globalInstallOf(bin: string | undefined, ctx: NpmContext): Promise<InstalledCopy>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
3
|
+
import { CliError, isMissingFile } from "./errors.js";
|
|
4
|
+
import { globalPrefix, installCommandLine } from "./npm.js";
|
|
5
|
+
function packageDirUnder(prefix, name) {
|
|
6
|
+
return process.platform === "win32"
|
|
7
|
+
? join(prefix, "node_modules", name)
|
|
8
|
+
: join(prefix, "lib", "node_modules", name);
|
|
9
|
+
}
|
|
10
|
+
function notGlobal(ctx, message) {
|
|
11
|
+
return new CliError({
|
|
12
|
+
code: "NOT_GLOBAL_INSTALL",
|
|
13
|
+
message,
|
|
14
|
+
hint: `install it with npm, so \`${ctx.cliName} update\` can replace it: ${installCommandLine(ctx.install)}`,
|
|
15
|
+
retryable: false,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async function realpathOrUndefined(path) {
|
|
19
|
+
return realpath(path).catch((error) => {
|
|
20
|
+
if (isMissingFile(error))
|
|
21
|
+
return undefined;
|
|
22
|
+
throw error;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function isInside(dir, path) {
|
|
26
|
+
const inner = relative(dir, path);
|
|
27
|
+
return inner !== "" && !inner.startsWith("..") && !isAbsolute(inner);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The global npm install this copy runs from, found by asking npm for its global prefix.
|
|
31
|
+
* `bin` is the script that started the CLI; throws `NOT_GLOBAL_INSTALL` when it is not inside that install.
|
|
32
|
+
*/
|
|
33
|
+
export async function globalInstallOf(bin, ctx) {
|
|
34
|
+
if (bin === undefined) {
|
|
35
|
+
throw notGlobal(ctx, `${ctx.cliName} runs from source, not from an npm install`);
|
|
36
|
+
}
|
|
37
|
+
const prefix = await globalPrefix(ctx);
|
|
38
|
+
const packageDir = packageDirUnder(prefix, ctx.install.package);
|
|
39
|
+
const installed = await realpathOrUndefined(packageDir);
|
|
40
|
+
const here = (await realpathOrUndefined(bin)) ?? bin;
|
|
41
|
+
if (installed === undefined || !isInside(installed, here)) {
|
|
42
|
+
throw notGlobal(ctx, `${ctx.cliName} runs from ${here}, not from npm's global install at ${packageDir}`);
|
|
43
|
+
}
|
|
44
|
+
// `npm link` puts a symlink to a source checkout where the install would be.
|
|
45
|
+
if ((await lstat(packageDir)).isSymbolicLink()) {
|
|
46
|
+
throw notGlobal(ctx, `${ctx.cliName} runs from a link to ${installed} (npm link), not from an npm install`);
|
|
47
|
+
}
|
|
48
|
+
return { prefix, packageDir };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=global-install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-install.js","sourceRoot":"","sources":["../src/global-install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAmB,MAAM,UAAU,CAAC;AAQ7E,SAAS,eAAe,CAAC,MAAc,EAAE,IAAY;IACnD,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO;QACjC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC;QACpC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI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CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;IACrD,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;QAC1D,MAAM,SAAS,CACb,GAAG,EACH,GAAG,GAAG,CAAC,OAAO,cAAc,IAAI,sCAAsC,UAAU,EAAE,CACnF,CAAC;IACJ,CAAC;IACD,6EAA6E;IAC7E,IAAI,CAAC,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC;QAC/C,MAAM,SAAS,CACb,GAAG,EACH,GAAG,GAAG,CAAC,OAAO,wBAAwB,SAAS,sCAAsC,CACtF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Command, type Commands } from "./define.js";
|
|
2
|
+
export declare function cliHelpJson(name: string, version: string, root: Command | Commands): string;
|
|
3
|
+
export declare function groupHelpJson(commandLine: string, commands: Commands): string;
|
|
4
|
+
export declare function commandHelpJson(commandLine: string, command: Command): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { isCommand } from "./define.js";
|
|
3
|
+
import { fieldsDescription, rowFieldsOf } from "./fields.js";
|
|
4
|
+
import { runtimeFlagsFor } from "./flags.js";
|
|
5
|
+
import { kebab } from "./input.js";
|
|
6
|
+
// Transforms and other unrepresentable parts become `{}` rather than failing the whole help.
|
|
7
|
+
function inputSchema(schema) {
|
|
8
|
+
return z.toJSONSchema(schema ?? z.object({}), { io: "input", unrepresentable: "any" });
|
|
9
|
+
}
|
|
10
|
+
// Options are keyed as the caller types them, so `greetingWord` reads `greeting-word`.
|
|
11
|
+
function optionsSchema(command) {
|
|
12
|
+
const shape = Object.entries(command.options?.shape ?? {}).map(([key, value]) => [
|
|
13
|
+
kebab(key),
|
|
14
|
+
value,
|
|
15
|
+
]);
|
|
16
|
+
const rowFields = rowFieldsOf(command);
|
|
17
|
+
const fields = rowFields === undefined
|
|
18
|
+
? []
|
|
19
|
+
: [["fields", z.string().optional().describe(fieldsDescription(rowFields))]];
|
|
20
|
+
return inputSchema(z.object(Object.fromEntries([...shape, ...fields])));
|
|
21
|
+
}
|
|
22
|
+
function commandData(commandLine, command) {
|
|
23
|
+
return {
|
|
24
|
+
name: commandLine,
|
|
25
|
+
description: command.description,
|
|
26
|
+
effect: command.effect,
|
|
27
|
+
examples: command.examples,
|
|
28
|
+
args: inputSchema(command.args),
|
|
29
|
+
options: optionsSchema(command),
|
|
30
|
+
standardFlags: runtimeFlagsFor(command.effect).map(({ usage, description }) => ({
|
|
31
|
+
usage,
|
|
32
|
+
description,
|
|
33
|
+
})),
|
|
34
|
+
output: command.output === undefined
|
|
35
|
+
? null
|
|
36
|
+
: z.toJSONSchema(command.output, { unrepresentable: "any" }),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function nodeData(commandLine, node) {
|
|
40
|
+
return isCommand(node) ? commandData(commandLine, node) : groupData(commandLine, node);
|
|
41
|
+
}
|
|
42
|
+
function groupData(commandLine, commands) {
|
|
43
|
+
return {
|
|
44
|
+
name: commandLine,
|
|
45
|
+
commands: Object.entries(commands).map(([key, node]) => nodeData(`${commandLine} ${key}`, node)),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function printed(data) {
|
|
49
|
+
return `${JSON.stringify(data)}\n`;
|
|
50
|
+
}
|
|
51
|
+
export function cliHelpJson(name, version, root) {
|
|
52
|
+
return printed({ name, version, ...nodeData(name, root) });
|
|
53
|
+
}
|
|
54
|
+
export function groupHelpJson(commandLine, commands) {
|
|
55
|
+
return printed(groupData(commandLine, commands));
|
|
56
|
+
}
|
|
57
|
+
export function commandHelpJson(commandLine, command) {
|
|
58
|
+
return printed(commandData(commandLine, command));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=help-json.js.map
|
|
@@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GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,OAAe,EAAE,IAAwB;IACjF,OAAO,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAAmB,EAAE,QAAkB;IACnE,OAAO,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,WAAmB,EAAE,OAAgB;IACnE,OAAO,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
package/dist/help.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Command, type Commands } from "./define.js";
|
|
2
|
+
import type { InputFields } from "./input.js";
|
|
3
|
+
import type { Style } from "./style.js";
|
|
4
|
+
export declare function cliHelp(name: string, version: string, commands: Commands, style: Style): string;
|
|
5
|
+
export declare function groupHelp(commandLine: string, commands: Commands, style: Style): string;
|
|
6
|
+
export declare function commandHelp(commandLine: string, command: Command, fields: InputFields, style: Style): string;
|
package/dist/help.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isCommand } from "./define.js";
|
|
2
|
+
import { runtimeFlagsFor } from "./flags.js";
|
|
3
|
+
function table(rows) {
|
|
4
|
+
const width = Math.max(...rows.map(([left]) => left.length));
|
|
5
|
+
return rows.map(([left, right]) => right === "" ? ` ${left}` : ` ${left.padEnd(width)} ${right}`);
|
|
6
|
+
}
|
|
7
|
+
function section(title, rows, style) {
|
|
8
|
+
return rows.length === 0 ? [] : ["", style.bold(`${title}:`), ...table(rows)];
|
|
9
|
+
}
|
|
10
|
+
function summaryOf(node) {
|
|
11
|
+
return isCommand(node) ? node.description : `group: ${Object.keys(node).join(", ")}`;
|
|
12
|
+
}
|
|
13
|
+
function commandRows(commands) {
|
|
14
|
+
return Object.entries(commands).map(([key, node]) => [key, summaryOf(node)]);
|
|
15
|
+
}
|
|
16
|
+
function lines(...parts) {
|
|
17
|
+
return `${parts.join("\n")}\n`;
|
|
18
|
+
}
|
|
19
|
+
function listing(heading, commandLine, commands, style) {
|
|
20
|
+
return lines(style.bold(heading), ...section("Commands", commandRows(commands), style), "", `Run \`${commandLine} <command> --help\` for its examples and input.`);
|
|
21
|
+
}
|
|
22
|
+
export function cliHelp(name, version, commands, style) {
|
|
23
|
+
return listing(`${name} ${version}`, name, commands, style);
|
|
24
|
+
}
|
|
25
|
+
export function groupHelp(commandLine, commands, style) {
|
|
26
|
+
return listing(commandLine, commandLine, commands, style);
|
|
27
|
+
}
|
|
28
|
+
const EFFECT_NOTES = {
|
|
29
|
+
read: "changes nothing",
|
|
30
|
+
write: "changes something; show the Plan with --dry-run",
|
|
31
|
+
destructive: "changes something hard to undo; show the Plan with --dry-run, run with --confirm",
|
|
32
|
+
};
|
|
33
|
+
function choicesOf(field) {
|
|
34
|
+
return field.choices === undefined ? [] : [`one of: ${field.choices.join(", ")}`];
|
|
35
|
+
}
|
|
36
|
+
function defaultsOf(field) {
|
|
37
|
+
if (field.defaultValue === undefined) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
if (field.type !== "boolean") {
|
|
41
|
+
return [`default: ${JSON.stringify(field.defaultValue)}`];
|
|
42
|
+
}
|
|
43
|
+
// A `--no-` flag sits next to the description of what it turns off, so the row must say so.
|
|
44
|
+
return field.defaultValue === true ? ["on by default; this flag turns it off"] : [];
|
|
45
|
+
}
|
|
46
|
+
function fieldRow(field, notes) {
|
|
47
|
+
const all = [...(field.required ? ["required"] : []), ...notes];
|
|
48
|
+
const suffix = all.length === 0 ? "" : `(${all.join("; ")})`;
|
|
49
|
+
return [field.usage, [field.description ?? "", suffix].filter((part) => part !== "").join(" ")];
|
|
50
|
+
}
|
|
51
|
+
function argRow(field) {
|
|
52
|
+
return fieldRow(field, [...choicesOf(field), ...defaultsOf(field)]);
|
|
53
|
+
}
|
|
54
|
+
// An option's usage already shows its choices, as in `--sort <name|date>`.
|
|
55
|
+
function optionRow(field) {
|
|
56
|
+
return fieldRow(field, defaultsOf(field));
|
|
57
|
+
}
|
|
58
|
+
export function commandHelp(commandLine, command, fields, style) {
|
|
59
|
+
return lines(style.bold(commandLine), command.description, ...section("Examples", command.examples.map(({ command, note }) => [command, note]), style), ...section("Arguments", fields.args.map(argRow), style), ...section("Options", fields.options.map(optionRow), style), "", `${style.bold("Effect:")} ${command.effect} (${EFFECT_NOTES[command.effect]})`, ...section("Standard flags", runtimeFlagsFor(command.effect).map(({ usage, description }) => [usage, description]), style));
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=help.js.map
|
package/dist/help.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAM7C,SAAS,KAAK,CAAC,IAAoB;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAChC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CACjE,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,KAAa,EAAE,IAAoB,EA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,CACR,gBAAgB,EAChB,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,EACrF,KAAK,CACN,CACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { defineCli } from "./built-ins.js";
|
|
2
|
+
export type { Cli, Command, Commands, Context, DestructiveCommand, DoctorCheck, DoctorFinding, Env, Example, GlobalInstall, ReadCommand, WriteCommand, } from "./define.js";
|
|
3
|
+
export { defineCommand } from "./define.js";
|
|
4
|
+
export type { CliErrorDetails, UsageErrorDetails } from "./errors.js";
|
|
5
|
+
export { CliError, debugVariable, UsageError } from "./errors.js";
|
|
6
|
+
export type { Page, PageInput } from "./page.js";
|
|
7
|
+
export { pageOf, pageOptions, paginate } from "./page.js";
|
|
8
|
+
export type { RunOptions, RunResult } from "./run-cli.js";
|
|
9
|
+
export { runCli } from "./run-cli.js";
|
|
10
|
+
export { runProcess } from "./run-process.js";
|
|
11
|
+
export type { Style } from "./style.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { defineCli } from "./built-ins.js";
|
|
2
|
+
export { defineCommand } from "./define.js";
|
|
3
|
+
export { CliError, debugVariable, UsageError } from "./errors.js";
|
|
4
|
+
export { pageOf, pageOptions, paginate } from "./page.js";
|
|
5
|
+
export { runCli } from "./run-cli.js";
|
|
6
|
+
export { runProcess } from "./run-process.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAe3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Command as Commander } from "commander";
|
|
2
|
+
import type { Command } from "./define.js";
|
|
3
|
+
export type ValueType = "string" | "number" | "boolean";
|
|
4
|
+
export interface InputField {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
readonly type: ValueType;
|
|
7
|
+
readonly required: boolean;
|
|
8
|
+
readonly defaultValue: unknown;
|
|
9
|
+
readonly description: string | undefined;
|
|
10
|
+
readonly choices: readonly string[] | undefined;
|
|
11
|
+
/** How the caller names it: `<name>` for an arg, `--name` or `--no-name` for an option. */
|
|
12
|
+
readonly label: string;
|
|
13
|
+
/** How the caller passes it: the label plus a value placeholder such as `<value>` or `<a|b>`. */
|
|
14
|
+
readonly usage: string;
|
|
15
|
+
}
|
|
16
|
+
export interface InputFields {
|
|
17
|
+
readonly args: readonly InputField[];
|
|
18
|
+
readonly options: readonly InputField[];
|
|
19
|
+
}
|
|
20
|
+
export declare function kebab(key: string): string;
|
|
21
|
+
export declare function inputFields(command: Command): InputFields;
|
|
22
|
+
export declare function registerInput(sub: Commander, options: readonly InputField[]): void;
|
package/dist/input.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
function isWrapper(schema) {
|
|
3
|
+
return (schema instanceof z.ZodOptional ||
|
|
4
|
+
schema instanceof z.ZodNullable ||
|
|
5
|
+
schema instanceof z.ZodDefault ||
|
|
6
|
+
schema instanceof z.ZodPrefault);
|
|
7
|
+
}
|
|
8
|
+
export function kebab(key) {
|
|
9
|
+
return key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
10
|
+
}
|
|
11
|
+
// Any other schema gets the caller's string, for Zod to accept or reject.
|
|
12
|
+
function typeOf(schema) {
|
|
13
|
+
if (schema instanceof z.ZodNumber) {
|
|
14
|
+
return "number";
|
|
15
|
+
}
|
|
16
|
+
return schema instanceof z.ZodBoolean ? "boolean" : "string";
|
|
17
|
+
}
|
|
18
|
+
function describe(schema) {
|
|
19
|
+
let current = schema;
|
|
20
|
+
let description = current.description;
|
|
21
|
+
let required = true;
|
|
22
|
+
let defaultValue;
|
|
23
|
+
while (isWrapper(current)) {
|
|
24
|
+
if (current instanceof z.ZodDefault || current instanceof z.ZodPrefault) {
|
|
25
|
+
defaultValue = current.def.defaultValue;
|
|
26
|
+
}
|
|
27
|
+
required = false;
|
|
28
|
+
current = current.unwrap();
|
|
29
|
+
description ??= current.description;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
type: typeOf(current),
|
|
33
|
+
required,
|
|
34
|
+
defaultValue,
|
|
35
|
+
description,
|
|
36
|
+
choices: current instanceof z.ZodEnum ? current.options.map(String) : undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function argField(key, schema) {
|
|
40
|
+
const label = `<${key}>`;
|
|
41
|
+
return { key, ...describe(schema), label, usage: label };
|
|
42
|
+
}
|
|
43
|
+
function optionField(key, schema) {
|
|
44
|
+
const described = describe(schema);
|
|
45
|
+
const isBoolean = described.type === "boolean";
|
|
46
|
+
// A boolean that defaults to true can only be changed by turning it off.
|
|
47
|
+
const label = isBoolean && described.defaultValue === true ? `--no-${kebab(key)}` : `--${kebab(key)}`;
|
|
48
|
+
const usage = isBoolean ? label : `${label} <${described.choices?.join("|") ?? "value"}>`;
|
|
49
|
+
return { key, ...described, label, usage };
|
|
50
|
+
}
|
|
51
|
+
function fieldsOf(schema, toField) {
|
|
52
|
+
return schema === undefined
|
|
53
|
+
? []
|
|
54
|
+
: Object.entries(schema.shape).map(([key, value]) => toField(key, value));
|
|
55
|
+
}
|
|
56
|
+
export function inputFields(command) {
|
|
57
|
+
return {
|
|
58
|
+
args: fieldsOf(command.args, argField),
|
|
59
|
+
options: fieldsOf(command.options, optionField),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Commander only collects what the caller typed, so that the Runtime can report every problem
|
|
63
|
+
// with it in one pass: unknown flags, extra args and missing values never stop commander.
|
|
64
|
+
export function registerInput(sub, options) {
|
|
65
|
+
sub.allowUnknownOption().allowExcessArguments();
|
|
66
|
+
for (const field of options) {
|
|
67
|
+
sub.option(field.type === "boolean" ? field.label : `${field.label} [value]`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AA2BzB,SAAS,SAAS,CAAC,MAAiB;IAClC,OAAO,CACL,MAAM,YAAY,CAAC,CAAC,WAAW;QAC/B,MAAM,YAAY,CAAC,CAAC,WAAW;QAC/B,MAAM,YAAY,CAAC,CAAC,UAAU;QAC9B,MAAM,YAAY,CAAC,CAAC,WAAW,CAChC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,0EAA0E;AAC1E,SAAS,MAAM,CAAC,MAAiB;IAC/B,IAAI,MAAM,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC;QAClC,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,MAAM,YAAY,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC/D,CAAC;AAED,SAAS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|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** How long an interrupted Command may take to settle before the run ends without it. */
|
|
2
|
+
export declare const GRACE_MS = 3000;
|
|
3
|
+
export declare const INTERRUPTED = "INTERRUPTED";
|
|
4
|
+
/** One Command run's cancellation: its signal, its deadlines and the steps it must finish. */
|
|
5
|
+
export declare class RunControl {
|
|
6
|
+
#private;
|
|
7
|
+
readonly signal: AbortSignal;
|
|
8
|
+
constructor(commandLine: string, outer: AbortSignal | undefined);
|
|
9
|
+
deadline(ms: number): AbortSignal;
|
|
10
|
+
runToEnd<T>(work: () => Promise<T>): Promise<T>;
|
|
11
|
+
/** Waits for the Command, its must-finish steps, and no longer than the grace once interrupted. */
|
|
12
|
+
settle<T>(work: Promise<T>): Promise<T>;
|
|
13
|
+
/**
|
|
14
|
+
* The error a run ends with: an interrupt or a missed deadline outranks what the Command threw,
|
|
15
|
+
* unless the Command threw its own `INTERRUPTED`, saying what it finished before it stopped.
|
|
16
|
+
*/
|
|
17
|
+
errorAfter(error: unknown): unknown;
|
|
18
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { CliError } from "./errors.js";
|
|
2
|
+
/** How long an interrupted Command may take to settle before the run ends without it. */
|
|
3
|
+
export const GRACE_MS = 3000;
|
|
4
|
+
const GRACE_OVER = Symbol("grace over");
|
|
5
|
+
export const INTERRUPTED = "INTERRUPTED";
|
|
6
|
+
function interruptedError() {
|
|
7
|
+
return new CliError({
|
|
8
|
+
code: INTERRUPTED,
|
|
9
|
+
message: "interrupted before it finished",
|
|
10
|
+
hint: "run the command again",
|
|
11
|
+
retryable: true,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function deadlineError(commandLine, ms) {
|
|
15
|
+
return new CliError({
|
|
16
|
+
code: "DEADLINE_EXCEEDED",
|
|
17
|
+
message: `${commandLine} ran past its ${ms} ms deadline`,
|
|
18
|
+
hint: "run it again later, when the service it waits on may answer faster",
|
|
19
|
+
retryable: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** One Command run's cancellation: its signal, its deadlines and the steps it must finish. */
|
|
23
|
+
export class RunControl {
|
|
24
|
+
signal;
|
|
25
|
+
#controller = new AbortController();
|
|
26
|
+
#commandLine;
|
|
27
|
+
#outer;
|
|
28
|
+
#onOuterAbort = () => this.#controller.abort(interruptedError());
|
|
29
|
+
#steps = new Set();
|
|
30
|
+
#deadlineTimers = new Set();
|
|
31
|
+
#deadlineHit;
|
|
32
|
+
#graceTimer;
|
|
33
|
+
#endGrace = () => { };
|
|
34
|
+
#graceOver = new Promise((resolve) => {
|
|
35
|
+
this.#endGrace = resolve;
|
|
36
|
+
});
|
|
37
|
+
constructor(commandLine, outer) {
|
|
38
|
+
this.#commandLine = commandLine;
|
|
39
|
+
this.#outer = outer;
|
|
40
|
+
this.signal = this.#controller.signal;
|
|
41
|
+
this.signal.addEventListener("abort", () => this.#startGrace(), { once: true });
|
|
42
|
+
if (outer?.aborted === true) {
|
|
43
|
+
this.#onOuterAbort();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
outer?.addEventListener("abort", this.#onOuterAbort, { once: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
deadline(ms) {
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
const timer = setTimeout(() => {
|
|
52
|
+
this.#deadlineHit ??= deadlineError(this.#commandLine, ms);
|
|
53
|
+
controller.abort(this.#deadlineHit);
|
|
54
|
+
}, ms);
|
|
55
|
+
this.#deadlineTimers.add(timer);
|
|
56
|
+
return AbortSignal.any([this.signal, controller.signal]);
|
|
57
|
+
}
|
|
58
|
+
async runToEnd(work) {
|
|
59
|
+
clearTimeout(this.#graceTimer);
|
|
60
|
+
const step = work();
|
|
61
|
+
// Only tracks when the step settles; the step's own error reaches the caller below.
|
|
62
|
+
const settled = step.then(() => { }, () => { });
|
|
63
|
+
this.#steps.add(settled);
|
|
64
|
+
try {
|
|
65
|
+
return await step;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
this.#steps.delete(settled);
|
|
69
|
+
this.#startGrace();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Waits for the Command, its must-finish steps, and no longer than the grace once interrupted. */
|
|
73
|
+
async settle(work) {
|
|
74
|
+
try {
|
|
75
|
+
const value = await Promise.race([work, this.#graceOver]);
|
|
76
|
+
if (this.signal.aborted || value === GRACE_OVER) {
|
|
77
|
+
throw this.signal.reason;
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
await this.#stepsDone();
|
|
83
|
+
this.#dispose();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The error a run ends with: an interrupt or a missed deadline outranks what the Command threw,
|
|
88
|
+
* unless the Command threw its own `INTERRUPTED`, saying what it finished before it stopped.
|
|
89
|
+
*/
|
|
90
|
+
errorAfter(error) {
|
|
91
|
+
if (this.signal.aborted) {
|
|
92
|
+
return error instanceof CliError && error.code === INTERRUPTED ? error : this.signal.reason;
|
|
93
|
+
}
|
|
94
|
+
if (this.#deadlineHit !== undefined && !(error instanceof CliError)) {
|
|
95
|
+
return this.#deadlineHit;
|
|
96
|
+
}
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
#startGrace() {
|
|
100
|
+
if (this.signal.aborted && this.#steps.size === 0) {
|
|
101
|
+
clearTimeout(this.#graceTimer);
|
|
102
|
+
this.#graceTimer = setTimeout(() => this.#endGrace(GRACE_OVER), GRACE_MS);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async #stepsDone() {
|
|
106
|
+
while (this.#steps.size > 0) {
|
|
107
|
+
await Promise.all(this.#steps);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
#dispose() {
|
|
111
|
+
clearTimeout(this.#graceTimer);
|
|
112
|
+
for (const timer of this.#deadlineTimers) {
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
}
|
|
115
|
+
this.#outer?.removeEventListener("abort", this.#onOuterAbort);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=interrupts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interrupts.js","sourceRoot":"","sources":["../src/interrupts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,yFAAyF;AACzF,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAE7B,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AAEzC,SAAS,gBAAgB;IACvB,OAAO,IAAI,QAAQ,CAAC;QAClB,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,gCAAgC;QACzC,IAAI,EAAE,uBAAuB;QAC7B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,WAAmB,EAAE,EAAU;IACpD,OAAO,IAAI,QAAQ,CAAC;QAClB,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,GAAG,WAAW,iBAAiB,EAAE,cAAc;QACxD,IAAI,EAAE,oEAAoE;QAC1E,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC;AAED,8FAA8F;AAC9F,MAAM,OAAO,UAAU;IACZ,MAAM,CAAc;IACpB,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,YAAY,CAAS;IACrB,MAAM,CAA0B;IAChC,aAAa,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACvE,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IAClC,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IACrD,YAAY,CAAuB;IACnC,WAAW,CAA6B;IACxC,SAAS,GAAsC,GAAG,EA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K,SAAS,IAAI,CAAC,CAAC,KAAK,YAAY,QAAQ,CAAC,EAAE,CAAC;YACpE,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW;QACT,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAClD,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,QAAQ;QACN,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC/B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzC,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const END_OF_OPTIONS = "--";
|
|
2
|
+
export interface Invocation {
|
|
3
|
+
readonly cliName: string;
|
|
4
|
+
readonly argv: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
/** The caller's command line, ready to paste, with `flag value` replacing any value they gave. */
|
|
7
|
+
export declare function commandLineWith({ cliName, argv }: Invocation, flag: string, value: string): string;
|
|
8
|
+
/** The caller's command line, ready to paste, with each flag in `renames` typed as its new name. */
|
|
9
|
+
export declare function commandLineRenaming({ cliName, argv }: Invocation, renames: ReadonlyMap<string, string>): string;
|