specli 0.0.11 → 0.0.13
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 +216 -325
- package/bin/cli.sh +27 -0
- package/dist/{src/ai → ai}/tools.d.ts +0 -1
- package/dist/ai/tools.js +161 -0
- package/dist/ai/tools.test.d.ts +1 -0
- package/dist/ai/tools.test.js +56 -0
- package/dist/{src/cli → cli}/auth-requirements.d.ts +0 -1
- package/dist/cli/auth-requirements.js +65 -0
- package/dist/cli/auth-requirements.test.d.ts +1 -0
- package/dist/cli/auth-requirements.test.js +16 -0
- package/dist/{src/cli → cli}/auth-schemes.d.ts +0 -1
- package/dist/cli/auth-schemes.js +112 -0
- package/dist/cli/auth-schemes.test.d.ts +1 -0
- package/dist/cli/auth-schemes.test.js +56 -0
- package/dist/{src/cli → cli}/capabilities.d.ts +0 -1
- package/dist/cli/capabilities.js +41 -0
- package/dist/cli/capabilities.test.d.ts +1 -0
- package/dist/cli/capabilities.test.js +84 -0
- package/dist/{src/cli → cli}/command-id.d.ts +0 -1
- package/dist/cli/command-id.js +8 -0
- package/dist/cli/command-id.test.d.ts +1 -0
- package/dist/cli/command-id.test.js +27 -0
- package/dist/{src/cli → cli}/command-index.d.ts +0 -1
- package/dist/cli/command-index.js +9 -0
- package/dist/{src/cli → cli}/command-model.d.ts +0 -1
- package/dist/cli/command-model.js +53 -0
- package/dist/cli/command-model.test.d.ts +1 -0
- package/dist/cli/command-model.test.js +40 -0
- package/dist/{src/cli → cli}/compile.d.ts +0 -1
- package/dist/cli/compile.js +79 -0
- package/dist/{src/cli → cli}/crypto.d.ts +0 -1
- package/dist/cli/crypto.js +9 -0
- package/dist/{src/cli → cli}/derive-name.d.ts +0 -1
- package/dist/cli/derive-name.js +96 -0
- package/dist/{src/cli → cli}/exec.d.ts +0 -1
- package/dist/cli/exec.js +50 -0
- package/dist/{src/cli → cli}/main.d.ts +0 -1
- package/dist/cli/main.js +177 -0
- package/dist/{src/cli → cli}/naming.d.ts +0 -1
- package/dist/cli/naming.js +191 -0
- package/dist/cli/naming.test.d.ts +1 -0
- package/dist/cli/naming.test.js +75 -0
- package/dist/{src/cli → cli}/operations.d.ts +0 -1
- package/dist/cli/operations.js +100 -0
- package/dist/cli/operations.test.d.ts +1 -0
- package/dist/cli/operations.test.js +51 -0
- package/dist/{src/cli → cli}/params.d.ts +0 -1
- package/dist/cli/params.js +36 -0
- package/dist/cli/params.test.d.ts +1 -0
- package/dist/cli/params.test.js +62 -0
- package/dist/{src/cli → cli}/pluralize.d.ts +0 -1
- package/dist/cli/pluralize.js +38 -0
- package/dist/{src/cli → cli}/positional.d.ts +0 -1
- package/dist/cli/positional.js +35 -0
- package/dist/cli/positional.test.d.ts +1 -0
- package/dist/cli/positional.test.js +60 -0
- package/dist/{src/cli → cli}/request-body.d.ts +0 -1
- package/dist/cli/request-body.js +44 -0
- package/dist/cli/request-body.test.d.ts +1 -0
- package/dist/cli/request-body.test.js +31 -0
- package/dist/{src/cli → cli}/runtime/argv.d.ts +0 -1
- package/dist/cli/runtime/argv.js +15 -0
- package/dist/{src/cli → cli}/runtime/auth/resolve.d.ts +0 -1
- package/dist/cli/runtime/auth/resolve.js +39 -0
- package/dist/{src/cli → cli}/runtime/body-flags.d.ts +0 -1
- package/dist/cli/runtime/body-flags.js +117 -0
- package/dist/cli/runtime/body-flags.test.d.ts +1 -0
- package/dist/cli/runtime/body-flags.test.js +192 -0
- package/dist/{src/cli → cli}/runtime/body.d.ts +0 -1
- package/dist/cli/runtime/body.js +16 -0
- package/dist/{src/cli → cli}/runtime/collect.d.ts +0 -1
- package/dist/cli/runtime/collect.js +3 -0
- package/dist/{src/cli → cli}/runtime/compat.d.ts +0 -1
- package/dist/cli/runtime/compat.js +78 -0
- package/dist/{src/cli → cli}/runtime/context.d.ts +0 -1
- package/dist/cli/runtime/context.js +44 -0
- package/dist/{src/cli → cli}/runtime/execute.d.ts +0 -1
- package/dist/cli/runtime/execute.js +106 -0
- package/dist/{src/cli → cli}/runtime/generated.d.ts +0 -1
- package/dist/cli/runtime/generated.js +168 -0
- package/dist/{src/cli → cli}/runtime/headers.d.ts +0 -1
- package/dist/cli/runtime/headers.js +30 -0
- package/dist/{src/cli → cli}/runtime/index.d.ts +0 -1
- package/dist/cli/runtime/index.js +3 -0
- package/dist/{src/cli → cli}/runtime/profile/secrets.d.ts +0 -1
- package/dist/cli/runtime/profile/secrets.js +53 -0
- package/dist/{src/cli → cli}/runtime/profile/store.d.ts +0 -1
- package/dist/cli/runtime/profile/store.js +63 -0
- package/dist/{src/cli → cli}/runtime/request.d.ts +0 -1
- package/dist/cli/runtime/request.js +283 -0
- package/dist/cli/runtime/request.test.d.ts +1 -0
- package/dist/cli/runtime/request.test.js +332 -0
- package/dist/{src/cli → cli}/runtime/server-url.d.ts +0 -1
- package/dist/cli/runtime/server-url.js +28 -0
- package/dist/{src/cli → cli}/runtime/template.d.ts +0 -1
- package/dist/cli/runtime/template.js +22 -0
- package/dist/cli/runtime/validate/ajv.d.ts +2 -0
- package/dist/cli/runtime/validate/ajv.js +11 -0
- package/dist/{src/cli → cli}/runtime/validate/coerce.d.ts +0 -1
- package/dist/cli/runtime/validate/coerce.js +63 -0
- package/dist/cli/runtime/validate/coerce.test.d.ts +1 -0
- package/dist/cli/runtime/validate/coerce.test.js +75 -0
- package/dist/{src/cli → cli}/runtime/validate/error.d.ts +0 -1
- package/dist/cli/runtime/validate/error.js +19 -0
- package/dist/{src/cli → cli}/runtime/validate/index.d.ts +0 -1
- package/dist/cli/runtime/validate/index.js +4 -0
- package/dist/{src/cli → cli}/runtime/validate/schema.d.ts +0 -1
- package/dist/cli/runtime/validate/schema.js +38 -0
- package/dist/{src/cli → cli}/schema-shape.d.ts +0 -1
- package/dist/cli/schema-shape.js +34 -0
- package/dist/{src/cli → cli}/schema.d.ts +0 -1
- package/dist/cli/schema.js +31 -0
- package/dist/{src/cli → cli}/server.d.ts +0 -1
- package/dist/cli/server.js +130 -0
- package/dist/cli/server.test.d.ts +1 -0
- package/dist/cli/server.test.js +49 -0
- package/dist/{src/cli → cli}/spec-id.d.ts +0 -1
- package/dist/cli/spec-id.js +8 -0
- package/dist/{src/cli → cli}/spec-loader.d.ts +0 -1
- package/dist/cli/spec-loader.js +40 -0
- package/dist/{src/cli → cli}/stable-json.d.ts +0 -1
- package/dist/cli/stable-json.js +29 -0
- package/dist/{src/cli → cli}/strings.d.ts +0 -1
- package/dist/cli/strings.js +20 -0
- package/dist/{src/cli → cli}/types.d.ts +0 -1
- package/dist/cli/types.js +3 -0
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +51 -2324
- package/dist/compiled.d.ts +2 -0
- package/{src/compiled.ts → dist/compiled.js} +8 -11
- package/dist/macros/env.d.ts +10 -0
- package/dist/macros/env.js +22 -0
- package/dist/macros/spec.d.ts +5 -0
- package/dist/macros/spec.js +16 -0
- package/package.json +17 -25
- package/bin/specli.js +0 -26
- package/cli.ts +0 -77
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -53
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2032
- package/dist/index.js.map +0 -48
- package/dist/src/ai/tools.d.ts.map +0 -1
- package/dist/src/ai/tools.js +0 -1656
- package/dist/src/ai/tools.js.map +0 -45
- package/dist/src/cli/auth-requirements.d.ts.map +0 -1
- package/dist/src/cli/auth-requirements.js +0 -66
- package/dist/src/cli/auth-requirements.js.map +0 -10
- package/dist/src/cli/auth-schemes.d.ts.map +0 -1
- package/dist/src/cli/auth-schemes.js +0 -116
- package/dist/src/cli/auth-schemes.js.map +0 -11
- package/dist/src/cli/capabilities.d.ts.map +0 -1
- package/dist/src/cli/capabilities.js +0 -45
- package/dist/src/cli/capabilities.js.map +0 -10
- package/dist/src/cli/command-id.d.ts.map +0 -1
- package/dist/src/cli/command-id.js +0 -18
- package/dist/src/cli/command-id.js.map +0 -11
- package/dist/src/cli/command-index.d.ts.map +0 -1
- package/dist/src/cli/command-index.js +0 -15
- package/dist/src/cli/command-index.js.map +0 -10
- package/dist/src/cli/command-model.d.ts.map +0 -1
- package/dist/src/cli/command-model.js +0 -274
- package/dist/src/cli/command-model.js.map +0 -18
- package/dist/src/cli/compile.d.ts.map +0 -1
- package/dist/src/cli/compile.js +0 -146
- package/dist/src/cli/compile.js.map +0 -11
- package/dist/src/cli/crypto.d.ts.map +0 -1
- package/dist/src/cli/crypto.js +0 -15
- package/dist/src/cli/crypto.js.map +0 -10
- package/dist/src/cli/derive-name.d.ts.map +0 -1
- package/dist/src/cli/derive-name.js +0 -70
- package/dist/src/cli/derive-name.js.map +0 -10
- package/dist/src/cli/exec.d.ts.map +0 -1
- package/dist/src/cli/exec.js +0 -2077
- package/dist/src/cli/exec.js.map +0 -49
- package/dist/src/cli/main.d.ts.map +0 -1
- package/dist/src/cli/main.js +0 -2032
- package/dist/src/cli/main.js.map +0 -48
- package/dist/src/cli/naming.d.ts.map +0 -1
- package/dist/src/cli/naming.js +0 -216
- package/dist/src/cli/naming.js.map +0 -12
- package/dist/src/cli/operations.d.ts.map +0 -1
- package/dist/src/cli/operations.js +0 -103
- package/dist/src/cli/operations.js.map +0 -10
- package/dist/src/cli/params.d.ts.map +0 -1
- package/dist/src/cli/params.js +0 -79
- package/dist/src/cli/params.js.map +0 -12
- package/dist/src/cli/pluralize.d.ts.map +0 -1
- package/dist/src/cli/pluralize.js +0 -43
- package/dist/src/cli/pluralize.js.map +0 -10
- package/dist/src/cli/positional.d.ts.map +0 -1
- package/dist/src/cli/positional.js +0 -39
- package/dist/src/cli/positional.js.map +0 -10
- package/dist/src/cli/request-body.d.ts.map +0 -1
- package/dist/src/cli/request-body.js +0 -82
- package/dist/src/cli/request-body.js.map +0 -12
- package/dist/src/cli/runtime/argv.d.ts.map +0 -1
- package/dist/src/cli/runtime/argv.js +0 -22
- package/dist/src/cli/runtime/argv.js.map +0 -10
- package/dist/src/cli/runtime/auth/resolve.d.ts.map +0 -1
- package/dist/src/cli/runtime/auth/resolve.js +0 -38
- package/dist/src/cli/runtime/auth/resolve.js.map +0 -10
- package/dist/src/cli/runtime/body-flags.d.ts.map +0 -1
- package/dist/src/cli/runtime/body-flags.js +0 -86
- package/dist/src/cli/runtime/body-flags.js.map +0 -10
- package/dist/src/cli/runtime/body.d.ts.map +0 -1
- package/dist/src/cli/runtime/body.js +0 -40
- package/dist/src/cli/runtime/body.js.map +0 -11
- package/dist/src/cli/runtime/collect.d.ts.map +0 -1
- package/dist/src/cli/runtime/collect.js +0 -9
- package/dist/src/cli/runtime/collect.js.map +0 -10
- package/dist/src/cli/runtime/compat.d.ts.map +0 -1
- package/dist/src/cli/runtime/compat.js +0 -62
- package/dist/src/cli/runtime/compat.js.map +0 -10
- package/dist/src/cli/runtime/context.d.ts.map +0 -1
- package/dist/src/cli/runtime/context.js +0 -936
- package/dist/src/cli/runtime/context.js.map +0 -32
- package/dist/src/cli/runtime/execute.d.ts.map +0 -1
- package/dist/src/cli/runtime/execute.js +0 -670
- package/dist/src/cli/runtime/execute.js.map +0 -22
- package/dist/src/cli/runtime/generated.d.ts.map +0 -1
- package/dist/src/cli/runtime/generated.js +0 -869
- package/dist/src/cli/runtime/generated.js.map +0 -23
- package/dist/src/cli/runtime/headers.d.ts.map +0 -1
- package/dist/src/cli/runtime/headers.js +0 -36
- package/dist/src/cli/runtime/headers.js.map +0 -10
- package/dist/src/cli/runtime/index.d.ts.map +0 -1
- package/dist/src/cli/runtime/index.js +0 -1808
- package/dist/src/cli/runtime/index.js.map +0 -46
- package/dist/src/cli/runtime/profile/secrets.d.ts.map +0 -1
- package/dist/src/cli/runtime/profile/secrets.js +0 -51
- package/dist/src/cli/runtime/profile/secrets.js.map +0 -11
- package/dist/src/cli/runtime/profile/store.d.ts.map +0 -1
- package/dist/src/cli/runtime/profile/store.js +0 -102
- package/dist/src/cli/runtime/profile/store.js.map +0 -11
- package/dist/src/cli/runtime/request.d.ts.map +0 -1
- package/dist/src/cli/runtime/request.js +0 -571
- package/dist/src/cli/runtime/request.js.map +0 -21
- package/dist/src/cli/runtime/server-url.d.ts.map +0 -1
- package/dist/src/cli/runtime/server-url.js +0 -55
- package/dist/src/cli/runtime/server-url.js.map +0 -11
- package/dist/src/cli/runtime/template.d.ts.map +0 -1
- package/dist/src/cli/runtime/template.js +0 -29
- package/dist/src/cli/runtime/template.js.map +0 -10
- package/dist/src/cli/runtime/validate/ajv.d.ts +0 -3
- package/dist/src/cli/runtime/validate/ajv.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/ajv.js +0 -17
- package/dist/src/cli/runtime/validate/ajv.js.map +0 -10
- package/dist/src/cli/runtime/validate/coerce.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/coerce.js +0 -60
- package/dist/src/cli/runtime/validate/coerce.js.map +0 -10
- package/dist/src/cli/runtime/validate/error.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/error.js +0 -21
- package/dist/src/cli/runtime/validate/error.js.map +0 -10
- package/dist/src/cli/runtime/validate/index.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/index.js +0 -122
- package/dist/src/cli/runtime/validate/index.js.map +0 -13
- package/dist/src/cli/runtime/validate/schema.d.ts.map +0 -1
- package/dist/src/cli/runtime/validate/schema.js +0 -36
- package/dist/src/cli/runtime/validate/schema.js.map +0 -10
- package/dist/src/cli/schema-shape.d.ts.map +0 -1
- package/dist/src/cli/schema-shape.js +0 -41
- package/dist/src/cli/schema-shape.js.map +0 -10
- package/dist/src/cli/schema.d.ts.map +0 -1
- package/dist/src/cli/schema.js +0 -38
- package/dist/src/cli/schema.js.map +0 -10
- package/dist/src/cli/server.d.ts.map +0 -1
- package/dist/src/cli/server.js +0 -64
- package/dist/src/cli/server.js.map +0 -11
- package/dist/src/cli/spec-id.d.ts.map +0 -1
- package/dist/src/cli/spec-id.js +0 -21
- package/dist/src/cli/spec-id.js.map +0 -11
- package/dist/src/cli/spec-loader.d.ts.map +0 -1
- package/dist/src/cli/spec-loader.js +0 -110
- package/dist/src/cli/spec-loader.js.map +0 -15
- package/dist/src/cli/stable-json.d.ts.map +0 -1
- package/dist/src/cli/stable-json.js +0 -35
- package/dist/src/cli/stable-json.js.map +0 -10
- package/dist/src/cli/strings.d.ts.map +0 -1
- package/dist/src/cli/strings.js +0 -16
- package/dist/src/cli/strings.js.map +0 -10
- package/dist/src/cli/types.d.ts.map +0 -1
- package/dist/src/cli/types.js +0 -9
- package/dist/src/cli/types.js.map +0 -10
- package/index.ts +0 -1
- package/src/ai/tools.ts +0 -211
- package/src/cli/auth-requirements.ts +0 -91
- package/src/cli/auth-schemes.ts +0 -187
- package/src/cli/capabilities.ts +0 -88
- package/src/cli/command-id.ts +0 -16
- package/src/cli/command-index.ts +0 -19
- package/src/cli/command-model.ts +0 -128
- package/src/cli/compile.ts +0 -101
- package/src/cli/crypto.ts +0 -9
- package/src/cli/derive-name.ts +0 -101
- package/src/cli/exec.ts +0 -72
- package/src/cli/main.ts +0 -231
- package/src/cli/naming.ts +0 -224
- package/src/cli/operations.ts +0 -152
- package/src/cli/params.ts +0 -71
- package/src/cli/pluralize.ts +0 -41
- package/src/cli/positional.ts +0 -75
- package/src/cli/request-body.ts +0 -94
- package/src/cli/runtime/argv.ts +0 -14
- package/src/cli/runtime/auth/resolve.ts +0 -59
- package/src/cli/runtime/body-flags.ts +0 -176
- package/src/cli/runtime/body.ts +0 -24
- package/src/cli/runtime/collect.ts +0 -6
- package/src/cli/runtime/compat.ts +0 -89
- package/src/cli/runtime/context.ts +0 -62
- package/src/cli/runtime/execute.ts +0 -147
- package/src/cli/runtime/generated.ts +0 -242
- package/src/cli/runtime/headers.ts +0 -37
- package/src/cli/runtime/index.ts +0 -3
- package/src/cli/runtime/profile/secrets.ts +0 -83
- package/src/cli/runtime/profile/store.ts +0 -100
- package/src/cli/runtime/request.ts +0 -390
- package/src/cli/runtime/server-url.ts +0 -45
- package/src/cli/runtime/template.ts +0 -26
- package/src/cli/runtime/validate/ajv.ts +0 -13
- package/src/cli/runtime/validate/coerce.ts +0 -71
- package/src/cli/runtime/validate/error.ts +0 -29
- package/src/cli/runtime/validate/index.ts +0 -4
- package/src/cli/runtime/validate/schema.ts +0 -54
- package/src/cli/schema-shape.ts +0 -36
- package/src/cli/schema.ts +0 -76
- package/src/cli/server.ts +0 -88
- package/src/cli/spec-id.ts +0 -12
- package/src/cli/spec-loader.ts +0 -58
- package/src/cli/stable-json.ts +0 -35
- package/src/cli/strings.ts +0 -21
- package/src/cli/types.ts +0 -59
- package/src/macros/env.ts +0 -21
- package/src/macros/spec.ts +0 -17
package/src/cli/command-model.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { AuthSummary } from "./auth-requirements.ts";
|
|
2
|
-
import { summarizeAuth } from "./auth-requirements.ts";
|
|
3
|
-
import type { AuthScheme } from "./auth-schemes.ts";
|
|
4
|
-
import { buildCommandId } from "./command-id.ts";
|
|
5
|
-
import type { PlannedOperation } from "./naming.ts";
|
|
6
|
-
import type { ParamSpec } from "./params.ts";
|
|
7
|
-
import { deriveParamSpecs } from "./params.ts";
|
|
8
|
-
import { deriveFlags, derivePositionals } from "./positional.ts";
|
|
9
|
-
import type { RequestBodyInfo } from "./request-body.ts";
|
|
10
|
-
import { deriveRequestBodyInfo } from "./request-body.ts";
|
|
11
|
-
import type { SecurityRequirement } from "./types.ts";
|
|
12
|
-
|
|
13
|
-
export type CommandAction = {
|
|
14
|
-
id: string;
|
|
15
|
-
key: string;
|
|
16
|
-
action: string;
|
|
17
|
-
// Derived path arguments. These become positionals later.
|
|
18
|
-
pathArgs: string[];
|
|
19
|
-
method: string;
|
|
20
|
-
path: string;
|
|
21
|
-
operationId?: string;
|
|
22
|
-
tags: string[];
|
|
23
|
-
summary?: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
deprecated?: boolean;
|
|
26
|
-
style: PlannedOperation["style"];
|
|
27
|
-
|
|
28
|
-
// Derived CLI shape (Phase 1 output; Phase 2 will wire these into commander)
|
|
29
|
-
positionals: Array<import("./positional.ts").PositionalArg>;
|
|
30
|
-
flags: Array<
|
|
31
|
-
Pick<
|
|
32
|
-
import("./params.ts").ParamSpec,
|
|
33
|
-
| "in"
|
|
34
|
-
| "name"
|
|
35
|
-
| "flag"
|
|
36
|
-
| "required"
|
|
37
|
-
| "description"
|
|
38
|
-
| "type"
|
|
39
|
-
| "format"
|
|
40
|
-
| "enum"
|
|
41
|
-
| "itemType"
|
|
42
|
-
| "itemFormat"
|
|
43
|
-
| "itemEnum"
|
|
44
|
-
>
|
|
45
|
-
>;
|
|
46
|
-
|
|
47
|
-
// Full raw params list (useful for debugging and future features)
|
|
48
|
-
params: ParamSpec[];
|
|
49
|
-
|
|
50
|
-
auth: AuthSummary;
|
|
51
|
-
requestBody?: RequestBodyInfo;
|
|
52
|
-
requestBodySchema?: import("./types.ts").JsonSchema;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type CommandResource = {
|
|
56
|
-
resource: string;
|
|
57
|
-
actions: CommandAction[];
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type CommandModel = {
|
|
61
|
-
resources: CommandResource[];
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type BuildCommandModelOptions = {
|
|
65
|
-
specId: string;
|
|
66
|
-
globalSecurity?: SecurityRequirement[];
|
|
67
|
-
authSchemes?: AuthScheme[];
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export function buildCommandModel(
|
|
71
|
-
planned: PlannedOperation[],
|
|
72
|
-
options: BuildCommandModelOptions,
|
|
73
|
-
): CommandModel {
|
|
74
|
-
const byResource = new Map<string, CommandAction[]>();
|
|
75
|
-
|
|
76
|
-
for (const op of planned) {
|
|
77
|
-
const list = byResource.get(op.resource) ?? [];
|
|
78
|
-
const params = deriveParamSpecs(op);
|
|
79
|
-
const positionals = derivePositionals({ pathArgs: op.pathArgs, params });
|
|
80
|
-
const flags = deriveFlags({ pathArgs: op.pathArgs, params });
|
|
81
|
-
|
|
82
|
-
list.push({
|
|
83
|
-
id: buildCommandId({
|
|
84
|
-
specId: options.specId,
|
|
85
|
-
resource: op.resource,
|
|
86
|
-
action: op.action,
|
|
87
|
-
operationKey: op.key,
|
|
88
|
-
}),
|
|
89
|
-
key: op.key,
|
|
90
|
-
action: op.action,
|
|
91
|
-
pathArgs: op.pathArgs,
|
|
92
|
-
method: op.method,
|
|
93
|
-
path: op.path,
|
|
94
|
-
operationId: op.operationId,
|
|
95
|
-
tags: op.tags,
|
|
96
|
-
summary: op.summary,
|
|
97
|
-
description: op.description,
|
|
98
|
-
deprecated: op.deprecated,
|
|
99
|
-
style: op.style,
|
|
100
|
-
params,
|
|
101
|
-
positionals,
|
|
102
|
-
flags: flags.flags,
|
|
103
|
-
auth: summarizeAuth(
|
|
104
|
-
op.security,
|
|
105
|
-
options.globalSecurity,
|
|
106
|
-
options.authSchemes ?? [],
|
|
107
|
-
),
|
|
108
|
-
requestBody: deriveRequestBodyInfo(op),
|
|
109
|
-
requestBodySchema: deriveRequestBodyInfo(op)?.preferredSchema,
|
|
110
|
-
});
|
|
111
|
-
byResource.set(op.resource, list);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const resources: CommandResource[] = [];
|
|
115
|
-
|
|
116
|
-
for (const [resource, actions] of byResource.entries()) {
|
|
117
|
-
actions.sort((a, b) => {
|
|
118
|
-
if (a.action !== b.action) return a.action.localeCompare(b.action);
|
|
119
|
-
if (a.path !== b.path) return a.path.localeCompare(b.path);
|
|
120
|
-
return a.method.localeCompare(b.method);
|
|
121
|
-
});
|
|
122
|
-
resources.push({ resource, actions });
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
resources.sort((a, b) => a.resource.localeCompare(b.resource));
|
|
126
|
-
|
|
127
|
-
return { resources };
|
|
128
|
-
}
|
package/src/cli/compile.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { deriveBinaryName } from "./derive-name.ts";
|
|
2
|
-
|
|
3
|
-
export type CompileOptions = {
|
|
4
|
-
name?: string;
|
|
5
|
-
outfile?: string;
|
|
6
|
-
target?: string;
|
|
7
|
-
minify?: boolean;
|
|
8
|
-
bytecode?: boolean;
|
|
9
|
-
dotenv?: boolean; // --no-dotenv sets this to false
|
|
10
|
-
bunfig?: boolean; // --no-bunfig sets this to false
|
|
11
|
-
define?: string[];
|
|
12
|
-
server?: string;
|
|
13
|
-
serverVar?: string[];
|
|
14
|
-
auth?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function parseKeyValue(input: string): { key: string; value: string } {
|
|
18
|
-
const idx = input.indexOf("=");
|
|
19
|
-
if (idx === -1)
|
|
20
|
-
throw new Error(`Invalid --define '${input}', expected key=value`);
|
|
21
|
-
const key = input.slice(0, idx).trim();
|
|
22
|
-
const value = input.slice(idx + 1).trim();
|
|
23
|
-
if (!key) throw new Error(`Invalid --define '${input}', missing key`);
|
|
24
|
-
return { key, value };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function compileCommand(
|
|
28
|
-
spec: string,
|
|
29
|
-
options: CompileOptions,
|
|
30
|
-
): Promise<void> {
|
|
31
|
-
// Derive name from spec if not provided
|
|
32
|
-
const name = options.name ?? (await deriveBinaryName(spec));
|
|
33
|
-
const outfile = options.outfile ?? `./dist/${name}`;
|
|
34
|
-
|
|
35
|
-
const target = options.target
|
|
36
|
-
? (options.target as Bun.Build.Target)
|
|
37
|
-
: (`bun-${process.platform}-${process.arch}` as Bun.Build.Target);
|
|
38
|
-
|
|
39
|
-
// Parse --define pairs
|
|
40
|
-
const define: Record<string, string> = {};
|
|
41
|
-
if (options.define) {
|
|
42
|
-
for (const pair of options.define) {
|
|
43
|
-
const { key, value } = parseKeyValue(pair);
|
|
44
|
-
define[key] = JSON.stringify(value);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Build command args
|
|
49
|
-
const buildArgs = [
|
|
50
|
-
"build",
|
|
51
|
-
"--compile",
|
|
52
|
-
`--outfile=${outfile}`,
|
|
53
|
-
`--target=${target}`,
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
if (options.minify) buildArgs.push("--minify");
|
|
57
|
-
if (options.bytecode) buildArgs.push("--bytecode");
|
|
58
|
-
|
|
59
|
-
for (const [k, v] of Object.entries(define)) {
|
|
60
|
-
buildArgs.push("--define", `${k}=${v}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (options.dotenv === false) buildArgs.push("--no-compile-autoload-dotenv");
|
|
64
|
-
if (options.bunfig === false) buildArgs.push("--no-compile-autoload-bunfig");
|
|
65
|
-
|
|
66
|
-
buildArgs.push("./src/compiled.ts");
|
|
67
|
-
|
|
68
|
-
// Only set env vars that have actual values - avoid empty strings
|
|
69
|
-
// because the macros will embed them and they will override defaults.
|
|
70
|
-
const buildEnv: Record<string, string> = {
|
|
71
|
-
...process.env,
|
|
72
|
-
SPECLI_SPEC: spec,
|
|
73
|
-
SPECLI_NAME: name,
|
|
74
|
-
};
|
|
75
|
-
if (options.server) buildEnv.SPECLI_SERVER = options.server;
|
|
76
|
-
if (options.serverVar?.length)
|
|
77
|
-
buildEnv.SPECLI_SERVER_VARS = options.serverVar.join(",");
|
|
78
|
-
if (options.auth) buildEnv.SPECLI_AUTH = options.auth;
|
|
79
|
-
|
|
80
|
-
const proc = Bun.spawn({
|
|
81
|
-
cmd: ["bun", ...buildArgs],
|
|
82
|
-
stdout: "pipe",
|
|
83
|
-
stderr: "pipe",
|
|
84
|
-
env: buildEnv,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const output = await new Response(proc.stdout).text();
|
|
88
|
-
const error = await new Response(proc.stderr).text();
|
|
89
|
-
const code = await proc.exited;
|
|
90
|
-
|
|
91
|
-
if (output) process.stdout.write(output);
|
|
92
|
-
if (error) process.stderr.write(error);
|
|
93
|
-
if (code !== 0) {
|
|
94
|
-
process.exitCode = code;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
process.stdout.write(`ok: built ${outfile}\n`);
|
|
99
|
-
process.stdout.write(`target: ${target}\n`);
|
|
100
|
-
process.stdout.write(`name: ${name}\n`);
|
|
101
|
-
}
|
package/src/cli/crypto.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export async function sha256Hex(text: string): Promise<string> {
|
|
2
|
-
const data = new TextEncoder().encode(text);
|
|
3
|
-
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
4
|
-
const bytes = new Uint8Array(hash);
|
|
5
|
-
|
|
6
|
-
let out = "";
|
|
7
|
-
for (const b of bytes) out += b.toString(16).padStart(2, "0");
|
|
8
|
-
return out;
|
|
9
|
-
}
|
package/src/cli/derive-name.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const RESERVED_NAMES = [
|
|
2
|
-
"exec",
|
|
3
|
-
"compile",
|
|
4
|
-
"profile",
|
|
5
|
-
"auth",
|
|
6
|
-
"help",
|
|
7
|
-
"version",
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Derives a clean binary name from an OpenAPI spec.
|
|
12
|
-
* Priority:
|
|
13
|
-
* 1. info.title (kebab-cased, sanitized)
|
|
14
|
-
* 2. Host from spec URL (if URL provided)
|
|
15
|
-
* 3. Fallback to "specli"
|
|
16
|
-
*/
|
|
17
|
-
export async function deriveBinaryName(spec: string): Promise<string> {
|
|
18
|
-
try {
|
|
19
|
-
// Load spec to extract title
|
|
20
|
-
const text = await loadSpecText(spec);
|
|
21
|
-
const doc = parseSpec(text);
|
|
22
|
-
|
|
23
|
-
const title = doc?.info?.title;
|
|
24
|
-
if (title && typeof title === "string") {
|
|
25
|
-
const name = sanitizeName(title);
|
|
26
|
-
if (name) return name;
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
// Fall through to URL-based derivation
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Try to derive from URL host
|
|
33
|
-
if (/^https?:\/\//i.test(spec)) {
|
|
34
|
-
try {
|
|
35
|
-
const url = new URL(spec);
|
|
36
|
-
const hostParts = url.hostname.split(".");
|
|
37
|
-
// Use first meaningful segment (skip www, api prefixes)
|
|
38
|
-
const meaningful = hostParts.find(
|
|
39
|
-
(p) => p !== "www" && p !== "api" && p.length > 2,
|
|
40
|
-
);
|
|
41
|
-
if (meaningful) {
|
|
42
|
-
const name = sanitizeName(meaningful);
|
|
43
|
-
if (name) return name;
|
|
44
|
-
}
|
|
45
|
-
} catch {
|
|
46
|
-
// Invalid URL, fall through
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Fallback
|
|
51
|
-
return "specli";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function loadSpecText(spec: string): Promise<string> {
|
|
55
|
-
if (/^https?:\/\//i.test(spec)) {
|
|
56
|
-
const res = await fetch(spec);
|
|
57
|
-
if (!res.ok) throw new Error(`Failed to fetch: ${res.status}`);
|
|
58
|
-
return res.text();
|
|
59
|
-
}
|
|
60
|
-
return Bun.file(spec).text();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function parseSpec(text: string): { info?: { title?: string } } | null {
|
|
64
|
-
try {
|
|
65
|
-
const trimmed = text.trimStart();
|
|
66
|
-
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
67
|
-
return JSON.parse(text);
|
|
68
|
-
}
|
|
69
|
-
// Use Bun's YAML parser
|
|
70
|
-
const { YAML } = globalThis.Bun ?? {};
|
|
71
|
-
if (YAML?.parse) {
|
|
72
|
-
return YAML.parse(text) as { info?: { title?: string } };
|
|
73
|
-
}
|
|
74
|
-
// Fallback: only JSON supported
|
|
75
|
-
return null;
|
|
76
|
-
} catch {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Convert title to valid binary name:
|
|
83
|
-
* - kebab-case
|
|
84
|
-
* - lowercase
|
|
85
|
-
* - remove invalid chars
|
|
86
|
-
* - max 32 chars
|
|
87
|
-
* - avoid reserved names
|
|
88
|
-
*/
|
|
89
|
-
function sanitizeName(input: string): string {
|
|
90
|
-
let name = input
|
|
91
|
-
.toLowerCase()
|
|
92
|
-
.replace(/[^a-z0-9]+/g, "-") // Replace non-alphanumeric with dash
|
|
93
|
-
.replace(/^-+|-+$/g, "") // Trim leading/trailing dashes
|
|
94
|
-
.slice(0, 32); // Limit length
|
|
95
|
-
|
|
96
|
-
if (RESERVED_NAMES.includes(name)) {
|
|
97
|
-
name = `${name}-cli`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return name;
|
|
101
|
-
}
|
package/src/cli/exec.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { main } from "./main.ts";
|
|
2
|
-
|
|
3
|
-
export type ExecOptions = {
|
|
4
|
-
server?: string;
|
|
5
|
-
serverVar?: string[];
|
|
6
|
-
auth?: string;
|
|
7
|
-
bearerToken?: string;
|
|
8
|
-
oauthToken?: string;
|
|
9
|
-
username?: string;
|
|
10
|
-
password?: string;
|
|
11
|
-
apiKey?: string;
|
|
12
|
-
profile?: string;
|
|
13
|
-
json?: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export async function execCommand(
|
|
17
|
-
spec: string,
|
|
18
|
-
options: ExecOptions,
|
|
19
|
-
commandArgs: string[],
|
|
20
|
-
): Promise<void> {
|
|
21
|
-
// commandArgs includes the spec as first element, filter it out
|
|
22
|
-
// to get the remaining args (resource, action, etc.)
|
|
23
|
-
const remainingArgs = commandArgs.slice(1);
|
|
24
|
-
|
|
25
|
-
// Reconstruct argv for main():
|
|
26
|
-
// [node, script, --spec, <spec>, ...options, ...remainingArgs]
|
|
27
|
-
const argv = [
|
|
28
|
-
process.argv[0] ?? "bun",
|
|
29
|
-
process.argv[1] ?? "specli",
|
|
30
|
-
"--spec",
|
|
31
|
-
spec,
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
// Add common options back as flags
|
|
35
|
-
if (options.server) {
|
|
36
|
-
argv.push("--server", options.server);
|
|
37
|
-
}
|
|
38
|
-
if (options.serverVar) {
|
|
39
|
-
for (const v of options.serverVar) {
|
|
40
|
-
argv.push("--server-var", v);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (options.auth) {
|
|
44
|
-
argv.push("--auth", options.auth);
|
|
45
|
-
}
|
|
46
|
-
if (options.bearerToken) {
|
|
47
|
-
argv.push("--bearer-token", options.bearerToken);
|
|
48
|
-
}
|
|
49
|
-
if (options.oauthToken) {
|
|
50
|
-
argv.push("--oauth-token", options.oauthToken);
|
|
51
|
-
}
|
|
52
|
-
if (options.username) {
|
|
53
|
-
argv.push("--username", options.username);
|
|
54
|
-
}
|
|
55
|
-
if (options.password) {
|
|
56
|
-
argv.push("--password", options.password);
|
|
57
|
-
}
|
|
58
|
-
if (options.apiKey) {
|
|
59
|
-
argv.push("--api-key", options.apiKey);
|
|
60
|
-
}
|
|
61
|
-
if (options.profile) {
|
|
62
|
-
argv.push("--profile", options.profile);
|
|
63
|
-
}
|
|
64
|
-
if (options.json) {
|
|
65
|
-
argv.push("--json");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Append remaining args (subcommand + its args)
|
|
69
|
-
argv.push(...remainingArgs);
|
|
70
|
-
|
|
71
|
-
await main(argv);
|
|
72
|
-
}
|
package/src/cli/main.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
|
|
3
|
-
import { getArgValue, hasAnyArg } from "./runtime/argv.ts";
|
|
4
|
-
import { collectRepeatable } from "./runtime/collect.ts";
|
|
5
|
-
import { readStdinText } from "./runtime/compat.ts";
|
|
6
|
-
import { buildRuntimeContext } from "./runtime/context.ts";
|
|
7
|
-
import { addGeneratedCommands } from "./runtime/generated.ts";
|
|
8
|
-
import { deleteToken, getToken, setToken } from "./runtime/profile/secrets.ts";
|
|
9
|
-
import {
|
|
10
|
-
readProfiles,
|
|
11
|
-
upsertProfile,
|
|
12
|
-
writeProfiles,
|
|
13
|
-
} from "./runtime/profile/store.ts";
|
|
14
|
-
import { toMinimalSchemaOutput } from "./schema.ts";
|
|
15
|
-
import { stableStringify } from "./stable-json.ts";
|
|
16
|
-
|
|
17
|
-
type MainOptions = {
|
|
18
|
-
embeddedSpecText?: string;
|
|
19
|
-
cliName?: string;
|
|
20
|
-
server?: string;
|
|
21
|
-
serverVars?: string[];
|
|
22
|
-
auth?: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export async function main(argv: string[], options: MainOptions = {}) {
|
|
26
|
-
const program = new Command();
|
|
27
|
-
|
|
28
|
-
program
|
|
29
|
-
.name(options.cliName ?? "specli")
|
|
30
|
-
.description("Generate a CLI from an OpenAPI spec")
|
|
31
|
-
.option("--spec <urlOrPath>", "OpenAPI URL or file path")
|
|
32
|
-
.option("--server <url>", "Override server/base URL")
|
|
33
|
-
.option(
|
|
34
|
-
"--server-var <name=value>",
|
|
35
|
-
"Server URL template variable (repeatable)",
|
|
36
|
-
collectRepeatable,
|
|
37
|
-
)
|
|
38
|
-
.option("--auth <scheme>", "Select auth scheme by key")
|
|
39
|
-
.option("--bearer-token <token>", "Bearer token (Authorization: Bearer)")
|
|
40
|
-
.option("--oauth-token <token>", "OAuth token (alias of bearer)")
|
|
41
|
-
.option("--username <username>", "Basic auth username")
|
|
42
|
-
.option("--password <password>", "Basic auth password")
|
|
43
|
-
.option("--api-key <key>", "API key value")
|
|
44
|
-
.option("--json", "Machine-readable output")
|
|
45
|
-
.showHelpAfterError();
|
|
46
|
-
|
|
47
|
-
// If user asks for help and we have no embedded spec and no --spec, show minimal help.
|
|
48
|
-
const spec = getArgValue(argv, "--spec");
|
|
49
|
-
const wantsHelp = hasAnyArg(argv, ["-h", "--help"]);
|
|
50
|
-
if (!spec && !options.embeddedSpecText && wantsHelp) {
|
|
51
|
-
program.addHelpText(
|
|
52
|
-
"after",
|
|
53
|
-
"\nTo see generated commands, run with --spec <url|path>.\n",
|
|
54
|
-
);
|
|
55
|
-
program.parse(argv);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const ctx = await buildRuntimeContext({
|
|
60
|
-
spec,
|
|
61
|
-
embeddedSpecText: options.embeddedSpecText,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Simple auth commands
|
|
65
|
-
const defaultProfileName = "default";
|
|
66
|
-
|
|
67
|
-
program
|
|
68
|
-
.command("login [token]")
|
|
69
|
-
.description("Store a bearer token for authentication")
|
|
70
|
-
.action(async (tokenArg: string | undefined, _opts, command) => {
|
|
71
|
-
const globals = command.optsWithGlobals() as { json?: boolean };
|
|
72
|
-
|
|
73
|
-
let token = tokenArg;
|
|
74
|
-
|
|
75
|
-
// If no token argument, try to read from stdin (for piping)
|
|
76
|
-
if (!token) {
|
|
77
|
-
const isTTY = process.stdin.isTTY;
|
|
78
|
-
if (isTTY) {
|
|
79
|
-
// Interactive mode - prompt user
|
|
80
|
-
process.stdout.write("Enter token: ");
|
|
81
|
-
const reader = process.stdin;
|
|
82
|
-
const chunks: Buffer[] = [];
|
|
83
|
-
for await (const chunk of reader) {
|
|
84
|
-
chunks.push(chunk);
|
|
85
|
-
// Read one line only
|
|
86
|
-
if (chunk.includes(10)) break; // newline
|
|
87
|
-
}
|
|
88
|
-
token = Buffer.concat(chunks).toString().trim();
|
|
89
|
-
} else {
|
|
90
|
-
// Piped input - use cross-runtime stdin reading
|
|
91
|
-
const text = await readStdinText();
|
|
92
|
-
token = text.trim();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!token) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
"No token provided. Usage: login <token> or echo $TOKEN | login",
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Ensure default profile exists
|
|
103
|
-
const file = await readProfiles();
|
|
104
|
-
if (!file.profiles.find((p) => p.name === defaultProfileName)) {
|
|
105
|
-
const updated = upsertProfile(file, { name: defaultProfileName });
|
|
106
|
-
await writeProfiles({ ...updated, defaultProfile: defaultProfileName });
|
|
107
|
-
} else if (!file.defaultProfile) {
|
|
108
|
-
await writeProfiles({ ...file, defaultProfile: defaultProfileName });
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
await setToken(ctx.loaded.id, defaultProfileName, token);
|
|
112
|
-
|
|
113
|
-
if (globals.json) {
|
|
114
|
-
process.stdout.write(`${JSON.stringify({ ok: true })}\n`);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
process.stdout.write("ok: logged in\n");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
program
|
|
121
|
-
.command("logout")
|
|
122
|
-
.description("Clear stored authentication token")
|
|
123
|
-
.action(async (_opts, command) => {
|
|
124
|
-
const globals = command.optsWithGlobals() as { json?: boolean };
|
|
125
|
-
|
|
126
|
-
const deleted = await deleteToken(ctx.loaded.id, defaultProfileName);
|
|
127
|
-
|
|
128
|
-
if (globals.json) {
|
|
129
|
-
process.stdout.write(`${JSON.stringify({ ok: deleted })}\n`);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
process.stdout.write(
|
|
133
|
-
deleted ? "ok: logged out\n" : "ok: not logged in\n",
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
program
|
|
138
|
-
.command("whoami")
|
|
139
|
-
.description("Show current authentication status")
|
|
140
|
-
.action(async (_opts, command) => {
|
|
141
|
-
const globals = command.optsWithGlobals() as { json?: boolean };
|
|
142
|
-
|
|
143
|
-
const token = await getToken(ctx.loaded.id, defaultProfileName);
|
|
144
|
-
const hasToken = Boolean(token);
|
|
145
|
-
|
|
146
|
-
// Mask the token for display (show first 8 and last 4 chars)
|
|
147
|
-
let maskedToken: string | null = null;
|
|
148
|
-
if (token && token.length > 16) {
|
|
149
|
-
maskedToken = `${token.slice(0, 8)}...${token.slice(-4)}`;
|
|
150
|
-
} else if (token) {
|
|
151
|
-
maskedToken = `${token.slice(0, 4)}...`;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (globals.json) {
|
|
155
|
-
process.stdout.write(
|
|
156
|
-
`${JSON.stringify({ authenticated: hasToken, token: maskedToken })}\n`,
|
|
157
|
-
);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (hasToken) {
|
|
162
|
-
process.stdout.write(`authenticated: yes\n`);
|
|
163
|
-
process.stdout.write(`token: ${maskedToken}\n`);
|
|
164
|
-
} else {
|
|
165
|
-
process.stdout.write(`authenticated: no\n`);
|
|
166
|
-
process.stdout.write(`Run 'login <token>' to authenticate.\n`);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
program
|
|
171
|
-
.command("__schema")
|
|
172
|
-
.description("Print indexed operations (machine-readable when --json)")
|
|
173
|
-
.option("--pretty", "Pretty-print JSON when used with --json")
|
|
174
|
-
.option("--min", "Minimal JSON output (commands + metadata only)")
|
|
175
|
-
.action(async (_opts, command) => {
|
|
176
|
-
const flags = command.optsWithGlobals() as {
|
|
177
|
-
json?: boolean;
|
|
178
|
-
pretty?: boolean;
|
|
179
|
-
min?: boolean;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
if (flags.json) {
|
|
183
|
-
const pretty = Boolean(flags.pretty);
|
|
184
|
-
const payload = flags.min
|
|
185
|
-
? toMinimalSchemaOutput(ctx.schema)
|
|
186
|
-
: ctx.schema;
|
|
187
|
-
const text = stableStringify(payload, { space: pretty ? 2 : 0 });
|
|
188
|
-
process.stdout.write(`${text}\n`);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
process.stdout.write(`${ctx.schema.openapi.title ?? "(untitled)"}\n`);
|
|
193
|
-
process.stdout.write(`OpenAPI: ${ctx.schema.openapi.version}\n`);
|
|
194
|
-
process.stdout.write(
|
|
195
|
-
`Spec: ${ctx.schema.spec.id} (${ctx.schema.spec.source})\n`,
|
|
196
|
-
);
|
|
197
|
-
process.stdout.write(`Fingerprint: ${ctx.schema.spec.fingerprint}\n`);
|
|
198
|
-
process.stdout.write(`Servers: ${ctx.schema.servers.length}\n`);
|
|
199
|
-
process.stdout.write(`Auth Schemes: ${ctx.schema.authSchemes.length}\n`);
|
|
200
|
-
process.stdout.write(`Operations: ${ctx.schema.operations.length}\n`);
|
|
201
|
-
|
|
202
|
-
for (const op of ctx.schema.operations) {
|
|
203
|
-
const id = op.operationId ? ` (${op.operationId})` : "";
|
|
204
|
-
process.stdout.write(`- ${op.method} ${op.path}${id}\n`);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (ctx.schema.planned?.length) {
|
|
208
|
-
process.stdout.write("\nPlanned commands:\n");
|
|
209
|
-
for (const op of ctx.schema.planned) {
|
|
210
|
-
const args = op.pathArgs.length
|
|
211
|
-
? ` ${op.pathArgs.map((a) => `<${a}>`).join(" ")}`
|
|
212
|
-
: "";
|
|
213
|
-
process.stdout.write(`- specli ${op.resource} ${op.action}${args}\n`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
addGeneratedCommands(program, {
|
|
219
|
-
servers: ctx.servers,
|
|
220
|
-
authSchemes: ctx.authSchemes,
|
|
221
|
-
commands: ctx.commands,
|
|
222
|
-
specId: ctx.loaded.id,
|
|
223
|
-
embeddedDefaults: {
|
|
224
|
-
server: options.server,
|
|
225
|
-
serverVars: options.serverVars,
|
|
226
|
-
auth: options.auth,
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
await program.parseAsync(argv);
|
|
231
|
-
}
|