@duyquangnvx/agent-cli 0.17.0 → 0.19.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 +77 -0
- package/README.md +2 -2
- package/agents-section.md +5 -0
- package/dist/agent-cli.d.ts +69 -11
- package/dist/agent-cli.js +71 -10
- package/dist/agent-cli.js.map +1 -1
- package/dist/built-ins/agents-md.d.ts +9 -9
- package/dist/built-ins/agents-md.js +8 -8
- package/dist/built-ins/agents-md.js.map +1 -1
- package/dist/built-ins/doctor-rows.js +5 -3
- package/dist/built-ins/doctor-rows.js.map +1 -1
- package/dist/built-ins/doctor.d.ts +1 -1
- package/dist/built-ins/doctor.js +16 -15
- package/dist/built-ins/doctor.js.map +1 -1
- package/dist/built-ins/install/dependency.js +1 -1
- package/dist/built-ins/install/dependency.js.map +1 -1
- package/dist/built-ins/install/global-npm.js +6 -4
- package/dist/built-ins/install/global-npm.js.map +1 -1
- package/dist/built-ins/npm.d.ts +3 -2
- package/dist/built-ins/npm.js +16 -9
- package/dist/built-ins/npm.js.map +1 -1
- package/dist/{project-root.js → built-ins/project-root.js} +1 -1
- package/dist/built-ins/project-root.js.map +1 -0
- package/dist/built-ins/skill/hub.d.ts +3 -2
- package/dist/built-ins/skill/hub.js +28 -16
- package/dist/built-ins/skill/hub.js.map +1 -1
- package/dist/built-ins/skill/install-command.d.ts +3 -4
- package/dist/built-ins/skill/install-command.js +20 -21
- package/dist/built-ins/skill/install-command.js.map +1 -1
- package/dist/built-ins/skill/packaged.js +5 -2
- package/dist/built-ins/skill/packaged.js.map +1 -1
- package/dist/built-ins/skill/skill.d.ts +5 -2
- package/dist/built-ins/skill/skill.js +1 -1
- package/dist/built-ins/skill/skill.js.map +1 -1
- package/dist/built-ins/update.d.ts +1 -1
- package/dist/built-ins/update.js +4 -9
- package/dist/built-ins/update.js.map +1 -1
- package/dist/check-examples.d.ts +6 -0
- package/dist/check-examples.js +53 -0
- package/dist/check-examples.js.map +1 -0
- package/dist/check-next-steps.d.ts +10 -0
- package/dist/check-next-steps.js +47 -0
- package/dist/check-next-steps.js.map +1 -0
- package/dist/command-errors.d.ts +8 -0
- package/dist/command-errors.js +25 -0
- package/dist/command-errors.js.map +1 -0
- package/dist/{flags.d.ts → command-line/flags.d.ts} +4 -4
- package/dist/{flags.js → command-line/flags.js} +7 -10
- package/dist/command-line/flags.js.map +1 -0
- package/dist/{input.d.ts → command-line/input.d.ts} +1 -1
- package/dist/{input.js → command-line/input.js} +1 -1
- package/dist/command-line/input.js.map +1 -0
- package/dist/{invocation.d.ts → command-line/invocation.d.ts} +6 -3
- package/dist/{invocation.js → command-line/invocation.js} +9 -5
- package/dist/command-line/invocation.js.map +1 -0
- package/dist/{parse-input.d.ts → command-line/parse-input.d.ts} +2 -2
- package/dist/{parse-input.js → command-line/parse-input.js} +3 -3
- package/dist/command-line/parse-input.js.map +1 -0
- package/dist/command-line/route-line.d.ts +15 -0
- package/dist/command-line/route-line.js +18 -0
- package/dist/command-line/route-line.js.map +1 -0
- package/dist/{route.d.ts → command-line/route.d.ts} +2 -2
- package/dist/{route.js → command-line/route.js} +1 -1
- package/dist/command-line/route.js.map +1 -0
- package/dist/command-line/shell-words.d.ts +12 -0
- package/dist/command-line/shell-words.js +83 -0
- package/dist/command-line/shell-words.js.map +1 -0
- package/dist/command-line/suggest.js.map +1 -0
- package/dist/command-line/tokenize.js.map +1 -0
- package/dist/{usage.d.ts → command-line/usage.d.ts} +1 -1
- package/dist/{usage.js → command-line/usage.js} +2 -2
- package/dist/command-line/usage.js.map +1 -0
- package/dist/command-spec.d.ts +13 -4
- package/dist/command-spec.js +22 -11
- package/dist/command-spec.js.map +1 -1
- package/dist/{agent.d.ts → context/agent.d.ts} +1 -1
- package/dist/context/agent.js.map +1 -0
- package/dist/{confirm.d.ts → context/confirm.d.ts} +3 -3
- package/dist/{confirm.js → context/confirm.js} +9 -11
- package/dist/context/confirm.js.map +1 -0
- package/dist/{cost.d.ts → context/cost.d.ts} +3 -3
- package/dist/context/cost.js +16 -0
- package/dist/context/cost.js.map +1 -0
- package/dist/context/declared.d.ts +8 -0
- package/dist/context/declared.js +10 -0
- package/dist/context/declared.js.map +1 -0
- package/dist/{errno.d.ts → context/errno.d.ts} +4 -3
- package/dist/{errno.js → context/errno.js} +14 -7
- package/dist/context/errno.js.map +1 -0
- package/dist/{files.js → context/files.js} +1 -1
- package/dist/context/files.js.map +1 -0
- package/dist/{interrupts.d.ts → context/interrupts.d.ts} +14 -10
- package/dist/{interrupts.js → context/interrupts.js} +30 -27
- package/dist/context/interrupts.js.map +1 -0
- package/dist/{operator.d.ts → context/operator.d.ts} +4 -3
- package/dist/{operator.js → context/operator.js} +4 -3
- package/dist/context/operator.js.map +1 -0
- package/dist/{outputs.d.ts → context/outputs.d.ts} +6 -5
- package/dist/{outputs.js → context/outputs.js} +10 -9
- package/dist/context/outputs.js.map +1 -0
- package/dist/{project.d.ts → context/project.d.ts} +4 -3
- package/dist/{project.js → context/project.js} +8 -7
- package/dist/context/project.js.map +1 -0
- package/dist/{secrets.d.ts → context/secrets.d.ts} +8 -1
- package/dist/context/secrets.js +85 -0
- package/dist/context/secrets.js.map +1 -0
- package/dist/{side-task.d.ts → context/side-task.d.ts} +2 -2
- package/dist/{side-task.js → context/side-task.js} +1 -1
- package/dist/context/side-task.js.map +1 -0
- package/dist/{spawn.d.ts → context/spawn.d.ts} +4 -3
- package/dist/{spawn.js → context/spawn.js} +7 -6
- package/dist/context/spawn.js.map +1 -0
- package/dist/{spill.d.ts → context/spill.d.ts} +4 -3
- package/dist/{spill.js → context/spill.js} +4 -4
- package/dist/context/spill.js.map +1 -0
- package/dist/{stdin.d.ts → context/stdin.d.ts} +2 -2
- package/dist/{stdin.js → context/stdin.js} +2 -2
- package/dist/context/stdin.js.map +1 -0
- package/dist/{tools.d.ts → context/tools.d.ts} +4 -3
- package/dist/{tools.js → context/tools.js} +8 -10
- package/dist/context/tools.js.map +1 -0
- package/dist/context.d.ts +51 -27
- package/dist/define-command.d.ts +47 -0
- package/dist/define-command.js +25 -0
- package/dist/define-command.js.map +1 -0
- package/dist/define.d.ts +71 -63
- package/dist/define.js +0 -14
- package/dist/define.js.map +1 -1
- package/dist/error-table.d.ts +9 -6
- package/dist/error-table.js +6 -6
- package/dist/error-table.js.map +1 -1
- package/dist/errors.d.ts +15 -1
- package/dist/errors.js +24 -6
- package/dist/errors.js.map +1 -1
- package/dist/execute.d.ts +8 -7
- package/dist/execute.js +51 -22
- package/dist/execute.js.map +1 -1
- package/dist/exit-classes.d.ts +1 -2
- package/dist/exit-classes.js +41 -48
- package/dist/exit-classes.js.map +1 -1
- package/dist/help-json.d.ts +4 -3
- package/dist/help-json.js +33 -11
- package/dist/help-json.js.map +1 -1
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts +19 -26
- package/dist/index.js +6 -18
- package/dist/index.js.map +1 -1
- package/dist/list.d.ts +6 -5
- package/dist/list.js +17 -11
- package/dist/list.js.map +1 -1
- package/dist/next-step.d.ts +23 -0
- package/dist/next-step.js +20 -0
- package/dist/next-step.js.map +1 -0
- package/dist/output.d.ts +11 -5
- package/dist/output.js +25 -11
- package/dist/output.js.map +1 -1
- package/dist/root-spec.d.ts +5 -0
- package/dist/root-spec.js +15 -0
- package/dist/root-spec.js.map +1 -0
- package/dist/run-cli.d.ts +2 -2
- package/dist/run-cli.js +12 -11
- package/dist/run-cli.js.map +1 -1
- package/dist/run-command.d.ts +4 -4
- package/dist/run-command.js +66 -37
- package/dist/run-command.js.map +1 -1
- package/dist/run-options.d.ts +11 -4
- package/dist/run-process.js +22 -7
- package/dist/run-process.js.map +1 -1
- package/dist/runtime-codes.d.ts +33 -0
- package/dist/runtime-codes.js +50 -0
- package/dist/runtime-codes.js.map +1 -0
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/testing.d.ts +27 -0
- package/dist/testing.js +66 -0
- package/dist/testing.js.map +1 -0
- package/dist/version.d.ts +4 -1
- package/dist/version.js +6 -1
- package/dist/version.js.map +1 -1
- package/docs/README.md +51 -0
- package/docs/example/archive.test.ts +280 -0
- package/docs/example/archive.ts +160 -0
- package/docs/example/bin.test.ts +118 -0
- package/docs/example/bin.ts +5 -0
- package/docs/example/bundle.test.ts +57 -0
- package/docs/example/bundle.ts +57 -0
- package/docs/example/cli.test.ts +428 -0
- package/docs/example/cli.ts +191 -0
- package/docs/example/commit.test.ts +78 -0
- package/docs/example/commit.ts +26 -0
- package/docs/example/define.ts +16 -0
- package/docs/example/errors.ts +17 -0
- package/docs/example/export.test.ts +64 -0
- package/docs/example/export.ts +32 -0
- package/docs/example/fake-ports.ts +14 -0
- package/docs/example/folder.ts +48 -0
- package/docs/example/import.test.ts +53 -0
- package/docs/example/import.ts +50 -0
- package/docs/example/package.json +21 -0
- package/docs/example/ports.ts +105 -0
- package/docs/example/serve.test.ts +49 -0
- package/docs/example/serve.ts +40 -0
- package/docs/example/store.ts +62 -0
- package/docs/example/tsdown.config.ts +33 -0
- package/docs/getting-started.md +19 -0
- package/docs/guides/commands.md +35 -0
- package/docs/guides/doctor.md +52 -0
- package/docs/guides/effects-and-plans.md +44 -0
- package/docs/guides/errors.md +57 -0
- package/docs/guides/lists.md +18 -0
- package/docs/guides/local-state.md +28 -0
- package/docs/guides/long-runs.md +109 -0
- package/docs/guides/remote-services.md +124 -0
- package/docs/guides/shipping.md +61 -0
- package/docs/guides/testing.md +69 -0
- package/docs/principles.md +39 -0
- package/docs/reference.md +25 -0
- package/package.json +12 -1
- package/dist/agent.js.map +0 -1
- package/dist/confirm.js.map +0 -1
- package/dist/cost.js +0 -16
- package/dist/cost.js.map +0 -1
- package/dist/errno.js.map +0 -1
- package/dist/files.js.map +0 -1
- package/dist/flags.js.map +0 -1
- package/dist/input.js.map +0 -1
- package/dist/interrupts.js.map +0 -1
- package/dist/invocation.js.map +0 -1
- package/dist/operator.js.map +0 -1
- package/dist/outputs.js.map +0 -1
- package/dist/parse-input.js.map +0 -1
- package/dist/project-root.js.map +0 -1
- package/dist/project.js.map +0 -1
- package/dist/route.js.map +0 -1
- package/dist/secrets.js +0 -31
- package/dist/secrets.js.map +0 -1
- package/dist/side-task.js.map +0 -1
- package/dist/spawn.js.map +0 -1
- package/dist/spill.js.map +0 -1
- package/dist/stdin.js.map +0 -1
- package/dist/suggest.js.map +0 -1
- package/dist/tokenize.js.map +0 -1
- package/dist/tools.js.map +0 -1
- package/dist/usage.js.map +0 -1
- /package/dist/{project-root.d.ts → built-ins/project-root.d.ts} +0 -0
- /package/dist/{suggest.d.ts → command-line/suggest.d.ts} +0 -0
- /package/dist/{suggest.js → command-line/suggest.js} +0 -0
- /package/dist/{tokenize.d.ts → command-line/tokenize.d.ts} +0 -0
- /package/dist/{tokenize.js → command-line/tokenize.js} +0 -0
- /package/dist/{agent.js → context/agent.js} +0 -0
- /package/dist/{files.d.ts → context/files.d.ts} +0 -0
package/dist/error-table.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as z from "zod";
|
|
2
2
|
import { CliError } from "./errors.js";
|
|
3
3
|
import type { ExitClass } from "./exit-classes.js";
|
|
4
|
+
import type { NextStep } from "./next-step.js";
|
|
4
5
|
/** The Exit classes a CLI's own code can have; a bug or an interrupt is the Runtime's to tell. */
|
|
5
6
|
export type DeclaredExitClass = Exclude<ExitClass, "bug" | "interrupted">;
|
|
6
7
|
export interface ErrorDeclaration {
|
|
@@ -15,6 +16,11 @@ export interface ErrorDeclaration {
|
|
|
15
16
|
}
|
|
16
17
|
/** A CLI's error codes, each with the class that must act on it and the facts it carries. */
|
|
17
18
|
export type ErrorTable = Readonly<Record<string, ErrorDeclaration>>;
|
|
19
|
+
export type NoErrors = Record<never, never>;
|
|
20
|
+
/** The Error table a CLI declares, empty when it declares none. */
|
|
21
|
+
export declare function errorTableOf({ errors }: {
|
|
22
|
+
readonly errors?: ErrorTable;
|
|
23
|
+
}): ErrorTable;
|
|
18
24
|
type StringKeys<Details> = {
|
|
19
25
|
[Key in keyof Details]-?: Exclude<Details[Key], undefined> extends string ? Key : never;
|
|
20
26
|
}[keyof Details] & string;
|
|
@@ -52,11 +58,8 @@ type RetryInit<Declaration> = Declaration extends {
|
|
|
52
58
|
export type CliErrorInit<Declaration extends ErrorDeclaration> = {
|
|
53
59
|
readonly message: string;
|
|
54
60
|
readonly hint: string;
|
|
61
|
+
readonly next?: readonly NextStep[];
|
|
55
62
|
} & DetailsInit<Declaration> & RetryInit<Declaration>;
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
* names the next command to run and says whether running it again can help; `retryAt` (ISO 8601)
|
|
59
|
-
* is allowed only on a wait-class code.
|
|
60
|
-
*/
|
|
61
|
-
export declare function cliError<Table extends ErrorTable, Code extends keyof Table & string>(_table: Table, code: Code, init: CliErrorInit<Table[Code]>, options?: ErrorOptions): CliError;
|
|
63
|
+
/** The `CliError` for a code of `Table`, as `cliError` and `ctx.fail` build it. */
|
|
64
|
+
export declare function cliErrorOf<Table extends ErrorTable, Code extends keyof Table & string>(code: Code, init: CliErrorInit<Table[Code]>, options?: ErrorOptions): CliError;
|
|
62
65
|
export {};
|
package/dist/error-table.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { CliError } from "./errors.js";
|
|
2
|
+
/** The Error table a CLI declares, empty when it declares none. */
|
|
3
|
+
export function errorTableOf({ errors }) {
|
|
4
|
+
return errors ?? {};
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
7
|
* Keeps each code's literal class and `details` schema, so `cliError` can type its throw sites;
|
|
4
8
|
* `print` must name a string key of the code's `details`.
|
|
@@ -6,12 +10,8 @@ import { CliError } from "./errors.js";
|
|
|
6
10
|
export function defineErrors(table) {
|
|
7
11
|
return table;
|
|
8
12
|
}
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
* names the next command to run and says whether running it again can help; `retryAt` (ISO 8601)
|
|
12
|
-
* is allowed only on a wait-class code.
|
|
13
|
-
*/
|
|
14
|
-
export function cliError(_table, code, init, options) {
|
|
13
|
+
/** The `CliError` for a code of `Table`, as `cliError` and `ctx.fail` build it. */
|
|
14
|
+
export function cliErrorOf(code, init, options) {
|
|
15
15
|
return new CliError({ ...init, code }, options);
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=error-table.js.map
|
package/dist/error-table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-table.js","sourceRoot":"","sources":["../src/error-table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"error-table.js","sourceRoot":"","sources":["../src/error-table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAuBvC,mEAAmE;AACnE,MAAM,UAAU,YAAY,CAAC,EAAE,MAAM,EAAoC;IACvE,OAAO,MAAM,IAAI,EAAE,CAAC;AACtB,CAAC;AAwBD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,KAA0E;IAE1E,OAAO,KAAK,CAAC;AACf,CAAC;AAoBD,mFAAmF;AACnF,MAAM,UAAU,UAAU,CACxB,IAAU,EACV,IAA+B,EAC/B,OAAsB;IAEtB,OAAO,IAAI,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Env } from "./context.js";
|
|
2
2
|
import type { ErrorTable } from "./error-table.js";
|
|
3
|
+
import { type NextStep, type Step } from "./next-step.js";
|
|
3
4
|
import type { Style } from "./style.js";
|
|
4
5
|
export interface CliErrorFields {
|
|
5
6
|
readonly code: string;
|
|
@@ -9,14 +10,24 @@ export interface CliErrorFields {
|
|
|
9
10
|
readonly details?: unknown;
|
|
10
11
|
/** ISO 8601: when a wait-class failure may pass, set only when the source said so. */
|
|
11
12
|
readonly retryAt?: string;
|
|
13
|
+
/** The lines to run next, in order; the hint says whether and when to run them. */
|
|
14
|
+
readonly next?: readonly NextStep[];
|
|
12
15
|
}
|
|
16
|
+
/** What a failure tells its caller to do. */
|
|
17
|
+
export type Advice = Pick<CliErrorFields, "hint" | "next">;
|
|
13
18
|
export declare class CliError extends Error {
|
|
14
19
|
readonly code: string;
|
|
15
20
|
readonly hint: string;
|
|
16
21
|
readonly details: unknown;
|
|
17
22
|
readonly retryAt: string | undefined;
|
|
18
|
-
|
|
23
|
+
readonly next: readonly Step[];
|
|
24
|
+
constructor({ code, message, hint, details, retryAt, next }: CliErrorFields, options?: ErrorOptions);
|
|
19
25
|
}
|
|
26
|
+
interface RuntimeErrorFields extends Omit<CliErrorFields, "next"> {
|
|
27
|
+
readonly next: readonly Step[];
|
|
28
|
+
}
|
|
29
|
+
/** A `CliError` whose Next steps may hold a line given whole, which only the Runtime builds. */
|
|
30
|
+
export declare function runtimeError(fields: RuntimeErrorFields, options?: ErrorOptions): CliError;
|
|
20
31
|
export type UsageErrorFields = Pick<CliErrorFields, "code" | "message" | "hint">;
|
|
21
32
|
/** The caller called the Agent CLI wrong; the same call can't succeed. */
|
|
22
33
|
export declare class UsageError extends CliError {
|
|
@@ -25,6 +36,8 @@ export declare class UsageError extends CliError {
|
|
|
25
36
|
export declare const INTERNAL = "INTERNAL";
|
|
26
37
|
export interface ErrorFormat {
|
|
27
38
|
readonly cliName: string;
|
|
39
|
+
/** What each Next step's line starts with. */
|
|
40
|
+
readonly runAs: string;
|
|
28
41
|
readonly json: boolean;
|
|
29
42
|
readonly env: Env;
|
|
30
43
|
readonly style: Style;
|
|
@@ -50,3 +63,4 @@ export declare function traceOf(error: unknown): string;
|
|
|
50
63
|
*/
|
|
51
64
|
export declare function errorsOf(error: unknown): readonly unknown[];
|
|
52
65
|
export declare function formatRuntimeError(error: unknown, format: ErrorFormat): string;
|
|
66
|
+
export {};
|
package/dist/errors.js
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
+
import { lineOf } from "./next-step.js";
|
|
1
2
|
export class CliError extends Error {
|
|
2
3
|
code;
|
|
3
4
|
hint;
|
|
4
5
|
details;
|
|
5
6
|
retryAt;
|
|
6
|
-
|
|
7
|
+
next;
|
|
8
|
+
constructor({ code, message, hint, details, retryAt, next = [] }, options) {
|
|
7
9
|
super(message, options);
|
|
8
10
|
this.name = "CliError";
|
|
9
11
|
this.code = code;
|
|
10
12
|
this.hint = hint;
|
|
11
13
|
this.details = details;
|
|
12
14
|
this.retryAt = retryAt;
|
|
15
|
+
this.next = next;
|
|
13
16
|
}
|
|
14
17
|
}
|
|
18
|
+
class RuntimeError extends CliError {
|
|
19
|
+
constructor({ next, ...fields }, options) {
|
|
20
|
+
super(fields, options);
|
|
21
|
+
this.next = next;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** A `CliError` whose Next steps may hold a line given whole, which only the Runtime builds. */
|
|
25
|
+
export function runtimeError(fields, options) {
|
|
26
|
+
return new RuntimeError(fields, options);
|
|
27
|
+
}
|
|
15
28
|
/** The caller called the Agent CLI wrong; the same call can't succeed. */
|
|
16
29
|
export class UsageError extends CliError {
|
|
17
30
|
constructor(fields) {
|
|
@@ -61,12 +74,16 @@ function bugHint(format) {
|
|
|
61
74
|
const rerun = `rerun with ${debugVariable(format.cliName)}=1 to see the stack trace`;
|
|
62
75
|
return bugs === undefined ? rerun : `${rerun}, then report it at ${bugs}`;
|
|
63
76
|
}
|
|
77
|
+
// A bug's own Next steps are the author's guess at a failure that was not meant to happen.
|
|
64
78
|
function fieldsOf(error, format) {
|
|
65
|
-
if (error instanceof CliError) {
|
|
66
|
-
|
|
67
|
-
return { code, message, hint: format.isBug(error) ? bugHint(format) : hint, details, retryAt };
|
|
79
|
+
if (!(error instanceof CliError)) {
|
|
80
|
+
return { code: INTERNAL, message: messageOf(error), hint: bugHint(format) };
|
|
68
81
|
}
|
|
69
|
-
|
|
82
|
+
const { code, message, hint, details, retryAt, next } = error;
|
|
83
|
+
if (format.isBug(error))
|
|
84
|
+
return { code, message, hint: bugHint(format), details, retryAt };
|
|
85
|
+
const lines = next.map((step) => lineOf(step, format.runAs));
|
|
86
|
+
return { code, message, hint, details, retryAt, ...(lines.length === 0 ? {} : { next: lines }) };
|
|
70
87
|
}
|
|
71
88
|
export function causesOf(error) {
|
|
72
89
|
return error instanceof Error && error.cause !== undefined
|
|
@@ -112,7 +129,8 @@ function errorLines(error, format) {
|
|
|
112
129
|
const { style } = format;
|
|
113
130
|
const label = style.red(format.isBug(error) ? "internal error:" : "error:");
|
|
114
131
|
const between = blocks.map((block) => `${block}\n`).join("");
|
|
115
|
-
|
|
132
|
+
const runs = (fields.next ?? []).map((line) => `${style.cyan("run:")} ${line}\n`).join("");
|
|
133
|
+
return `${label} ${fields.message}\n${between}${style.cyan("hint:")} ${fields.hint}\n${runs}`;
|
|
116
134
|
}
|
|
117
135
|
export function formatRuntimeError(error, format) {
|
|
118
136
|
const errors = errorsOf(error);
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAA4B,MAAM,gBAAgB,CAAC;AAkBlE,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,IAAI,CAAS;IACb,OAAO,CAAU;IACjB,OAAO,CAAqB;IAC5B,IAAI,CAAkB;IAE/B,YACE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAkB,EACpE,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI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kBAAkB,CAAC,KAAc,EAAE,MAAmB;IACpE,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACpC,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YACzB,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;SAChC,CAAC,CAAC,CAAC;QACJ,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;IACpD,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/execute.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import type { Files } from "./context/files.js";
|
|
2
|
+
import { type OutputsGuard } from "./context/outputs.js";
|
|
1
3
|
import type { Context } from "./context.js";
|
|
2
4
|
import type { Command } from "./define.js";
|
|
3
|
-
import type { Files } from "./files.js";
|
|
4
|
-
import type { Invocation } from "./invocation.js";
|
|
5
5
|
import type { PageInput } from "./list.js";
|
|
6
|
-
import { type OutputsGuard } from "./outputs.js";
|
|
7
6
|
import type { Style } from "./style.js";
|
|
8
7
|
export interface Outcome {
|
|
9
8
|
readonly value: unknown;
|
|
@@ -18,7 +17,6 @@ export interface ExecuteFlags {
|
|
|
18
17
|
/** The page a List Command's `run` receives with its input. */
|
|
19
18
|
readonly page: PageInput;
|
|
20
19
|
/** The caller's command line and the Command's, for the hint of a confirmation error. */
|
|
21
|
-
readonly invocation: Invocation;
|
|
22
20
|
readonly commandLine: string;
|
|
23
21
|
/** Prints a serve Command's data the moment `start` returns it. */
|
|
24
22
|
readonly started: (outcome: Outcome) => Promise<void>;
|
|
@@ -27,6 +25,9 @@ export interface ExecuteFlags {
|
|
|
27
25
|
/** Guards the declared outputs of `ctx.files` and the ports' files once every check passes. */
|
|
28
26
|
readonly guardOutputs: OutputsGuard["guard"];
|
|
29
27
|
}
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The data a Command returned or delivered as it prints it: parsed by its `output` schema when it
|
|
30
|
+
* declares one, so data the schema rejects fails the run as a bug.
|
|
31
|
+
*/
|
|
32
|
+
export declare function dataOutcome(command: Command, data: unknown, commandLine: string): Outcome;
|
|
33
|
+
export declare function execute(command: Command, input: Record<string, unknown>, ctx: Context, { dryRun, confirm, yes, page, commandLine, started, files, guardOutputs }: ExecuteFlags): Promise<Outcome>;
|
package/dist/execute.js
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
|
+
import { encode } from "@toon-format/toon";
|
|
2
|
+
import * as z from "zod";
|
|
1
3
|
import { untilAborted } from "./abort.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { checkOutputs, probeOutputs } from "./outputs.js";
|
|
6
|
-
import {
|
|
4
|
+
import { FORCE_FLAG } from "./command-line/flags.js";
|
|
5
|
+
import { checkConfirmation } from "./context/confirm.js";
|
|
6
|
+
import { checkCost } from "./context/cost.js";
|
|
7
|
+
import { checkOutputs, probeOutputs } from "./context/outputs.js";
|
|
8
|
+
import { checkSecrets } from "./context/secrets.js";
|
|
9
|
+
import { checkTools } from "./context/tools.js";
|
|
10
|
+
const PLAN_INDENT = " ";
|
|
7
11
|
function outcomeOf(value, render) {
|
|
8
12
|
return { value, render: (style) => render(value, style) };
|
|
9
13
|
}
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The data a Command returned or delivered as it prints it: parsed by its `output` schema when it
|
|
16
|
+
* declares one, so data the schema rejects fails the run as a bug.
|
|
17
|
+
*/
|
|
18
|
+
export function dataOutcome(command, data, commandLine) {
|
|
19
|
+
// Without its own render, a Command's text is its data as TOON (ADR 0012), and no data prints
|
|
20
|
+
// nothing. The union of render signatures only accepts the intersection of their data types.
|
|
21
|
+
const render = (command.render ??
|
|
22
|
+
((value) => (value === undefined ? "" : encode(value))));
|
|
23
|
+
if (command.rows !== undefined || command.output === undefined) {
|
|
24
|
+
return outcomeOf(data, render);
|
|
25
|
+
}
|
|
26
|
+
const parsed = command.output.safeParse(data);
|
|
27
|
+
if (!parsed.success) {
|
|
28
|
+
throw new Error(`\`${commandLine}\` produced data its output schema rejects:\n${z.prettifyError(parsed.error)}`);
|
|
29
|
+
}
|
|
30
|
+
return outcomeOf(parsed.data, render);
|
|
31
|
+
}
|
|
32
|
+
function indented(text) {
|
|
33
|
+
return text
|
|
34
|
+
.split("\n")
|
|
35
|
+
.map((line) => `${PLAN_INDENT}${line}`)
|
|
36
|
+
.join("\n");
|
|
14
37
|
}
|
|
15
|
-
function dryRunOutcome(command, plan) {
|
|
16
|
-
|
|
38
|
+
function dryRunOutcome(command, plan, commandLine) {
|
|
39
|
+
// The Plan is indented under its header, so its keys never read as the `outputs:` or `cost:` after it.
|
|
40
|
+
const renderPlan = (style) => command.renderPlan === undefined
|
|
41
|
+
? `Would run ${commandLine}:\n${indented(encode(plan))}`
|
|
42
|
+
: command.renderPlan(plan, style);
|
|
17
43
|
if (command.outputs === undefined && command.cost === undefined) {
|
|
18
44
|
return { value: plan, render: renderPlan };
|
|
19
45
|
}
|
|
@@ -40,39 +66,42 @@ function serveContextOf(ctx, end) {
|
|
|
40
66
|
const serveCtx = Object.create(ctx);
|
|
41
67
|
return Object.assign(serveCtx, { end });
|
|
42
68
|
}
|
|
43
|
-
export async function execute(command, input, ctx, { dryRun, confirm, yes, page,
|
|
44
|
-
await checkTools(command.tools ?? [], ctx.env, ctx.
|
|
69
|
+
export async function execute(command, input, ctx, { dryRun, confirm, yes, page, commandLine, started, files, guardOutputs }) {
|
|
70
|
+
await checkTools(command.tools ?? [], ctx.env, ctx.rerun());
|
|
71
|
+
const { env, envFile, fileError } = ctx;
|
|
72
|
+
checkSecrets(command.secrets ?? [], { env, envFile, fileError }, ctx.rerun());
|
|
45
73
|
if (command.rows !== undefined) {
|
|
46
|
-
|
|
74
|
+
const { render } = command;
|
|
75
|
+
return outcomeOf(await command.run({ ...input, ...page }, ctx), (data, style) => render === undefined ? encode(data.items) : render(data, style));
|
|
47
76
|
}
|
|
48
77
|
if (command.effect === "read" || command.effect === "act") {
|
|
49
|
-
return
|
|
78
|
+
return dataOutcome(command, await command.run(input, ctx), commandLine);
|
|
50
79
|
}
|
|
51
80
|
if (command.effect === "serve") {
|
|
52
81
|
let end = () => { };
|
|
53
82
|
const ended = new Promise((resolve) => {
|
|
54
83
|
end = resolve;
|
|
55
84
|
});
|
|
56
|
-
const outcome =
|
|
85
|
+
const outcome = dataOutcome(command, await command.start(input, serveContextOf(ctx, end)), commandLine);
|
|
57
86
|
await started(outcome);
|
|
58
87
|
await Promise.race([ended, untilAborted(ctx.signal)]);
|
|
59
88
|
return outcome;
|
|
60
89
|
}
|
|
61
90
|
const plan = await command.plan(input, ctx);
|
|
62
91
|
if (dryRun) {
|
|
63
|
-
return dryRunOutcome(command, plan);
|
|
92
|
+
return dryRunOutcome(command, plan, commandLine);
|
|
64
93
|
}
|
|
65
94
|
const outputs = command.outputs?.(plan);
|
|
66
|
-
await checkOutputs({
|
|
67
|
-
checkCost({
|
|
95
|
+
await checkOutputs({ rerun: ctx.rerun, commandLine, force: ctx.force, files: ctx.files }, outputs);
|
|
96
|
+
checkCost({ rerun: ctx.rerun, commandLine, yes }, command.cost?.(plan));
|
|
68
97
|
if (command.effect === "destructive") {
|
|
69
|
-
checkConfirmation({
|
|
98
|
+
checkConfirmation({ rerun: ctx.rerun, commandLine, given: confirm }, command.confirm(plan));
|
|
70
99
|
}
|
|
71
100
|
if (outputs !== undefined) {
|
|
72
101
|
await probeOutputs({ files, cwd: ctx.cwd, fileError: ctx.fileError }, outputs);
|
|
73
102
|
if (!ctx.force)
|
|
74
|
-
guardOutputs(outputs, ctx.
|
|
103
|
+
guardOutputs(outputs, ctx.rerun({ add: [FORCE_FLAG.flag] }));
|
|
75
104
|
}
|
|
76
|
-
return
|
|
105
|
+
return dataOutcome(command, await command.apply(plan, ctx), commandLine);
|
|
77
106
|
}
|
|
78
107
|
//# sourceMappingURL=execute.js.map
|
package/dist/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAqB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AA8BhD,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,SAAS,SAAS,CAAQ,KAAY,EAAE,MAA8C;IACpF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED;;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AAC,CAAC,CAAC;IACxE,IAAI,OAAO,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;QACrC,iBAAiB,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,YAAY,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;QAC/E,IAAI,CAAC,GAAG,CAAC,KAAK;YAAE,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,WAAW,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC;AAC3E,CAAC"}
|
package/dist/exit-classes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Cli } from "./define.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type DeclaredExitClass, type ErrorTable } from "./error-table.js";
|
|
3
3
|
/** Who must act on a failure (ADR 0005), which sets the exit code. */
|
|
4
4
|
export type ExitClass = "caller" | "operator" | "source" | "wait" | "bug" | "interrupted";
|
|
5
5
|
export declare const SIGNAL_EXIT_CODES: {
|
|
@@ -14,7 +14,6 @@ export declare const EXIT_CODES: {
|
|
|
14
14
|
readonly wait: 75;
|
|
15
15
|
readonly bug: 70;
|
|
16
16
|
};
|
|
17
|
-
export declare const RUNTIME_EXIT_CLASSES: Readonly<Record<string, ExitClass>>;
|
|
18
17
|
/** The codes of `errors` that the Runtime already declares, which a CLI cannot redeclare. */
|
|
19
18
|
export declare function runtimeCodesIn(errors: ErrorTable): string[];
|
|
20
19
|
export declare function isBug(error: unknown, errors: ErrorTable): boolean;
|
package/dist/exit-classes.js
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import { DOCTOR_PROBLEMS } from "./built-ins/doctor.js";
|
|
2
|
-
import { NOT_GLOBAL_INSTALL } from "./built-ins/install/global-npm.js";
|
|
3
1
|
import { installOf } from "./built-ins/install/install.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { NOT_CONFIRMED } from "./cost.js";
|
|
7
|
-
import { ALREADY_EXISTS, DISK_FULL, NOT_A_FILE, NOT_FOUND, PERMISSION_DENIED } from "./errno.js";
|
|
8
|
-
import { CliError, errorsOf, INTERNAL, UsageError } from "./errors.js";
|
|
9
|
-
import { DEADLINE_EXCEEDED, INTERRUPTED } from "./interrupts.js";
|
|
10
|
-
import { UNKNOWN_FIELD } from "./list.js";
|
|
11
|
-
import { NEEDS_OPERATOR } from "./operator.js";
|
|
12
|
-
import { OUTPUT_EXISTS } from "./outputs.js";
|
|
13
|
-
import { PROJECT_INVALID } from "./project.js";
|
|
14
|
-
import { TOOL_FAILED } from "./spawn.js";
|
|
15
|
-
import { STDIN_STALLED } from "./stdin.js";
|
|
16
|
-
import { TOOL_MISSING } from "./tools.js";
|
|
17
|
-
import { INVALID_INPUT, UNKNOWN_COMMAND, UNKNOWN_OPTION } from "./usage.js";
|
|
2
|
+
import { errorTableOf } from "./error-table.js";
|
|
3
|
+
import { CliError, errorsOf, UsageError } from "./errors.js";
|
|
18
4
|
export const SIGNAL_EXIT_CODES = { SIGINT: 130, SIGTERM: 143 };
|
|
19
5
|
export const EXIT_CODES = {
|
|
20
6
|
caller: 1,
|
|
@@ -23,39 +9,44 @@ export const EXIT_CODES = {
|
|
|
23
9
|
wait: 75,
|
|
24
10
|
bug: 70,
|
|
25
11
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
12
|
+
// Typed by every Runtime code, so a code missing here or not on `runtimeCodes` fails to compile.
|
|
13
|
+
const RUNTIME_EXIT_CLASSES = {
|
|
14
|
+
INVALID_INPUT: "caller",
|
|
15
|
+
UNKNOWN_OPTION: "caller",
|
|
16
|
+
UNKNOWN_COMMAND: "caller",
|
|
17
|
+
UNKNOWN_FIELD: "caller",
|
|
18
|
+
CONFIRMATION_REQUIRED: "caller",
|
|
19
|
+
CONFIRMATION_MISMATCH: "caller",
|
|
20
|
+
NOT_CONFIRMED: "operator",
|
|
21
|
+
NEEDS_OPERATOR: "operator",
|
|
22
|
+
OUTPUT_EXISTS: "caller",
|
|
23
|
+
STDIN_STALLED: "caller",
|
|
24
|
+
INTERRUPTED: "interrupted",
|
|
25
|
+
DEADLINE_EXCEEDED: "wait",
|
|
26
|
+
INTERNAL: "bug",
|
|
27
|
+
PERMISSION_DENIED: "operator",
|
|
28
|
+
DISK_FULL: "operator",
|
|
29
|
+
NOT_FOUND: "caller",
|
|
30
|
+
ALREADY_EXISTS: "caller",
|
|
31
|
+
NOT_A_FILE: "caller",
|
|
32
|
+
TOOL_FAILED: "operator",
|
|
33
|
+
TOOL_MISSING: "operator",
|
|
34
|
+
SECRET_MISSING: "operator",
|
|
35
|
+
PROJECT_INVALID: "operator",
|
|
36
|
+
DOCTOR_PROBLEMS: "operator",
|
|
37
|
+
NOT_GLOBAL_INSTALL: "operator",
|
|
38
|
+
REGISTRY_UNREACHABLE: "operator",
|
|
39
|
+
REGISTRY_AUTH: "operator",
|
|
40
|
+
INSTALL_FAILED: "operator",
|
|
41
|
+
NPM_FAILED: "operator",
|
|
42
|
+
NO_LATEST: "source",
|
|
55
43
|
};
|
|
44
|
+
function isRuntimeCode(code) {
|
|
45
|
+
return Object.hasOwn(RUNTIME_EXIT_CLASSES, code);
|
|
46
|
+
}
|
|
56
47
|
/** The codes of `errors` that the Runtime already declares, which a CLI cannot redeclare. */
|
|
57
48
|
export function runtimeCodesIn(errors) {
|
|
58
|
-
return Object.keys(errors).filter(
|
|
49
|
+
return Object.keys(errors).filter(isRuntimeCode);
|
|
59
50
|
}
|
|
60
51
|
// A code that neither the Runtime nor the CLI declares was thrown by mistake: a bug.
|
|
61
52
|
function exitClassOfOne(error, errors) {
|
|
@@ -63,7 +54,9 @@ function exitClassOfOne(error, errors) {
|
|
|
63
54
|
return "bug";
|
|
64
55
|
if (error instanceof UsageError)
|
|
65
56
|
return "caller";
|
|
66
|
-
|
|
57
|
+
if (isRuntimeCode(error.code))
|
|
58
|
+
return RUNTIME_EXIT_CLASSES[error.code];
|
|
59
|
+
return errors[error.code]?.class ?? "bug";
|
|
67
60
|
}
|
|
68
61
|
export function isBug(error, errors) {
|
|
69
62
|
return exitClassOfOne(error, errors) === "bug";
|
|
@@ -89,7 +82,7 @@ export function reachableExitClasses(cli) {
|
|
|
89
82
|
"wait",
|
|
90
83
|
...(cli.commands === undefined ? [] : installOf(cli).exitClasses),
|
|
91
84
|
];
|
|
92
|
-
const own = Object.values(cli
|
|
85
|
+
const own = Object.values(errorTableOf(cli)).map((declaration) => declaration.class);
|
|
93
86
|
return new Set([...runtime, ...own]);
|
|
94
87
|
}
|
|
95
88
|
/** The signal named by an interrupt's abort reason; any other reason counts as Ctrl-C. */
|
package/dist/exit-classes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exit-classes.js","sourceRoot":"","sources":["../src/exit-classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{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js";
|
|
2
2
|
import type { Cli } from "./define.js";
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
3
|
+
import { type ErrorTable } from "./error-table.js";
|
|
4
|
+
export declare function cliHelpJson(cli: Cli, root: SpecNode): string;
|
|
5
|
+
export declare function groupHelpJson(group: GroupSpec, table: ErrorTable): string;
|
|
6
|
+
export declare function commandHelpJson(spec: CommandSpec, table: ErrorTable): string;
|
package/dist/help-json.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
import { visibleCommands, } from "./command-spec.js";
|
|
3
|
+
import { errorTableOf } from "./error-table.js";
|
|
3
4
|
// Transforms and other unrepresentable parts become `{}` rather than failing the whole help.
|
|
4
5
|
function inputSchema(schema) {
|
|
5
6
|
return z.toJSONSchema(schema, { io: "input", unrepresentable: "any" });
|
|
@@ -8,7 +9,7 @@ function inputSchema(schema) {
|
|
|
8
9
|
function optionsSchema(options) {
|
|
9
10
|
return inputSchema(z.object(Object.fromEntries(options.map(({ name, schema }) => [name, schema]))));
|
|
10
11
|
}
|
|
11
|
-
function commandData(spec) {
|
|
12
|
+
function commandData(spec, table) {
|
|
12
13
|
return {
|
|
13
14
|
name: spec.commandLine,
|
|
14
15
|
description: spec.description,
|
|
@@ -16,6 +17,9 @@ function commandData(spec) {
|
|
|
16
17
|
effect: spec.effect,
|
|
17
18
|
operator: spec.operator,
|
|
18
19
|
examples: spec.examples,
|
|
20
|
+
secrets: spec.command.secrets ?? [],
|
|
21
|
+
// `defineCli` checked that each declared code is in the table.
|
|
22
|
+
errors: (spec.command.errors ?? []).map((code) => ({ code, class: table[code]?.class })),
|
|
19
23
|
args: inputSchema(spec.command.args ?? z.object({})),
|
|
20
24
|
options: optionsSchema(spec.options),
|
|
21
25
|
standardFlags: spec.standardFlags.map(({ usage, description, schema }) => ({
|
|
@@ -26,11 +30,14 @@ function commandData(spec) {
|
|
|
26
30
|
output: spec.output === undefined ? null : z.toJSONSchema(spec.output, { unrepresentable: "any" }),
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
|
-
function nodeData(node) {
|
|
30
|
-
return node.kind === "command" ? commandData(node) : groupData(node);
|
|
33
|
+
function nodeData(node, table) {
|
|
34
|
+
return node.kind === "command" ? commandData(node, table) : groupData(node, table);
|
|
31
35
|
}
|
|
32
|
-
function groupData(group) {
|
|
33
|
-
return {
|
|
36
|
+
function groupData(group, table) {
|
|
37
|
+
return {
|
|
38
|
+
name: group.commandLine,
|
|
39
|
+
commands: Object.values(visibleCommands(group)).map((node) => nodeData(node, table)),
|
|
40
|
+
};
|
|
34
41
|
}
|
|
35
42
|
function printed(data) {
|
|
36
43
|
return `${JSON.stringify(data)}\n`;
|
|
@@ -46,15 +53,30 @@ function errorsData(errors) {
|
|
|
46
53
|
},
|
|
47
54
|
]));
|
|
48
55
|
}
|
|
56
|
+
// A single-Command CLI publishes only the codes its Command throws, in the table's own shape.
|
|
57
|
+
function publishedTable(table, root) {
|
|
58
|
+
if (root.kind !== "command")
|
|
59
|
+
return table;
|
|
60
|
+
const declared = new Set(root.command.errors ?? []);
|
|
61
|
+
return Object.fromEntries(Object.entries(table).filter(([code]) => declared.has(code)));
|
|
62
|
+
}
|
|
49
63
|
// The root names the CLI beside its version, as the text header does; its Commands keep the run-as.
|
|
50
|
-
|
|
64
|
+
// A single-Command CLI's root is its Command, whose `errors` list gives way to the table.
|
|
65
|
+
export function cliHelpJson(cli, root) {
|
|
66
|
+
const { name, version, description } = cli;
|
|
51
67
|
const header = { name, version, description };
|
|
52
|
-
|
|
68
|
+
const table = errorTableOf(cli);
|
|
69
|
+
return printed({
|
|
70
|
+
...header,
|
|
71
|
+
...nodeData(root, table),
|
|
72
|
+
name,
|
|
73
|
+
errors: errorsData(publishedTable(table, root)),
|
|
74
|
+
});
|
|
53
75
|
}
|
|
54
|
-
export function groupHelpJson(group) {
|
|
55
|
-
return printed(groupData(group));
|
|
76
|
+
export function groupHelpJson(group, table) {
|
|
77
|
+
return printed(groupData(group, table));
|
|
56
78
|
}
|
|
57
|
-
export function commandHelpJson(spec) {
|
|
58
|
-
return printed(commandData(spec));
|
|
79
|
+
export function commandHelpJson(spec, table) {
|
|
80
|
+
return printed(commandData(spec, table));
|
|
59
81
|
}
|
|
60
82
|
//# sourceMappingURL=help-json.js.map
|