@kjanat/dreamcli 0.0.0 → 2.0.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 +706 -0
- package/LICENSE +22 -0
- package/README.md +502 -0
- package/dist/core/cli/dispatch.d.mts +85 -0
- package/dist/core/cli/dispatch.mjs +1 -0
- package/dist/core/cli/index.d.mts +418 -0
- package/dist/core/cli/index.mjs +1 -0
- package/dist/core/cli/planner.d.mts +143 -0
- package/dist/core/cli/planner.mjs +1 -0
- package/dist/core/cli/plugin.d.mts +94 -0
- package/dist/core/cli/plugin.mjs +1 -0
- package/dist/core/cli/propagate.d.mts +39 -0
- package/dist/core/cli/propagate.mjs +1 -0
- package/dist/core/cli/root-help.d.mts +28 -0
- package/dist/core/cli/root-help.mjs +7 -0
- package/dist/core/cli/root-surface.d.mts +42 -0
- package/dist/core/cli/root-surface.mjs +1 -0
- package/dist/core/cli/runtime-preflight.d.mts +149 -0
- package/dist/core/cli/runtime-preflight.mjs +1 -0
- package/dist/core/completion/index.d.mts +46 -0
- package/dist/core/completion/index.mjs +1 -0
- package/dist/core/completion/shells/bash.d.mts +24 -0
- package/dist/core/completion/shells/bash.mjs +3 -0
- package/dist/core/completion/shells/fish.d.mts +20 -0
- package/dist/core/completion/shells/fish.mjs +2 -0
- package/dist/core/completion/shells/powershell.d.mts +14 -0
- package/dist/core/completion/shells/powershell.mjs +2 -0
- package/dist/core/completion/shells/shared.d.mts +139 -0
- package/dist/core/completion/shells/shared.mjs +1 -0
- package/dist/core/completion/shells/zsh.d.mts +24 -0
- package/dist/core/completion/shells/zsh.mjs +2 -0
- package/dist/core/config/index.d.mts +161 -0
- package/dist/core/config/index.mjs +1 -0
- package/dist/core/config/package-json.d.mts +68 -0
- package/dist/core/config/package-json.mjs +1 -0
- package/dist/core/errors/index.d.mts +126 -0
- package/dist/core/errors/index.mjs +1 -0
- package/dist/core/execution/index.d.mts +49 -0
- package/dist/core/execution/index.mjs +1 -0
- package/dist/core/help/index.d.mts +49 -0
- package/dist/core/help/index.mjs +8 -0
- package/dist/core/json-schema/index.d.mts +109 -0
- package/dist/core/json-schema/index.mjs +55 -0
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +185 -0
- package/dist/core/json-schema/meta-descriptions.generated.mjs +28 -0
- package/dist/core/output/activity.d.mts +194 -0
- package/dist/core/output/activity.mjs +1 -0
- package/dist/core/output/contracts.d.mts +88 -0
- package/dist/core/output/contracts.mjs +1 -0
- package/dist/core/output/display-value.d.mts +19 -0
- package/dist/core/output/display-value.mjs +1 -0
- package/dist/core/output/index.d.mts +280 -0
- package/dist/core/output/index.mjs +2 -0
- package/dist/core/output/renderers.d.mts +46 -0
- package/dist/core/output/renderers.mjs +1 -0
- package/dist/core/output/writer.d.mts +40 -0
- package/dist/core/output/writer.mjs +1 -0
- package/dist/core/parse/index.d.mts +79 -0
- package/dist/core/parse/index.mjs +1 -0
- package/dist/core/prompt/index.d.mts +205 -0
- package/dist/core/prompt/index.mjs +6 -0
- package/dist/core/resolve/args.d.mts +8 -0
- package/dist/core/resolve/args.mjs +1 -0
- package/dist/core/resolve/coerce.d.mts +22 -0
- package/dist/core/resolve/coerce.mjs +1 -0
- package/dist/core/resolve/config.d.mts +10 -0
- package/dist/core/resolve/config.mjs +1 -0
- package/dist/core/resolve/contracts.d.mts +112 -0
- package/dist/core/resolve/errors.d.mts +11 -0
- package/dist/core/resolve/errors.mjs +2 -0
- package/dist/core/resolve/flags.d.mts +10 -0
- package/dist/core/resolve/flags.mjs +1 -0
- package/dist/core/resolve/index.d.mts +42 -0
- package/dist/core/resolve/index.mjs +1 -0
- package/dist/core/resolve/property.d.mts +47 -0
- package/dist/core/resolve/property.mjs +1 -0
- package/dist/core/schema/activity.d.mts +169 -0
- package/dist/core/schema/arg.d.mts +559 -0
- package/dist/core/schema/arg.mjs +1 -0
- package/dist/core/schema/command.d.mts +960 -0
- package/dist/core/schema/command.mjs +1 -0
- package/dist/core/schema/flag.d.mts +491 -0
- package/dist/core/schema/flag.mjs +1 -0
- package/dist/core/schema/index.d.mts +8 -0
- package/dist/core/schema/middleware.d.mts +122 -0
- package/dist/core/schema/middleware.mjs +1 -0
- package/dist/core/schema/prompt.d.mts +117 -0
- package/dist/core/schema/run.d.mts +171 -0
- package/dist/core/schema-dsl/runtime.d.mts +144 -0
- package/dist/core/schema-dsl/runtime.mjs +2 -0
- package/dist/core/schema-dsl/to-json-schema.d.mts +30 -0
- package/dist/core/schema-dsl/to-json-schema.mjs +1 -0
- package/dist/core/testkit/index.d.mts +54 -0
- package/dist/core/testkit/index.mjs +1 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.mjs +1 -0
- package/dist/runtime/adapter.d.mts +212 -0
- package/dist/runtime/adapter.mjs +1 -0
- package/dist/runtime/auto.d.mts +26 -0
- package/dist/runtime/auto.mjs +1 -0
- package/dist/runtime/bun.d.mts +28 -0
- package/dist/runtime/bun.mjs +1 -0
- package/dist/runtime/deno.d.mts +76 -0
- package/dist/runtime/deno.mjs +2 -0
- package/dist/runtime/detect.d.mts +86 -0
- package/dist/runtime/detect.mjs +1 -0
- package/dist/runtime/index.d.mts +7 -0
- package/dist/runtime/node.d.mts +65 -0
- package/dist/runtime/node.mjs +2 -0
- package/dist/runtime/paths.d.mts +31 -0
- package/dist/runtime/paths.mjs +1 -0
- package/dist/runtime/support.d.mts +42 -0
- package/dist/runtime/support.mjs +1 -0
- package/dist/runtime.d.mts +7 -0
- package/dist/runtime.mjs +1 -0
- package/dist/testkit.d.mts +6 -0
- package/dist/testkit.mjs +1 -0
- package/dist/version.d.mts +16 -0
- package/dist/version.mjs +1 -0
- package/dreamcli.schema.json +338 -0
- package/examples/basic.ts +33 -0
- package/examples/gh/package.json +44 -0
- package/examples/gh/src/commands/auth.ts +66 -0
- package/examples/gh/src/commands/issue.ts +120 -0
- package/examples/gh/src/commands/pr.ts +125 -0
- package/examples/gh/src/data/issues.yaml +5 -0
- package/examples/gh/src/data/issues.yaml.d.ts +17 -0
- package/examples/gh/src/data/pull-requests.yaml +7 -0
- package/examples/gh/src/data/pull-requests.yaml.d.ts +18 -0
- package/examples/gh/src/docs.ts +11 -0
- package/examples/gh/src/lib/auth.ts +37 -0
- package/examples/gh/src/lib/utils.ts +17 -0
- package/examples/gh/src/main.test.ts +307 -0
- package/examples/gh/src/main.ts +40 -0
- package/examples/interactive.ts +66 -0
- package/examples/json-mode.ts +91 -0
- package/examples/middleware.ts +71 -0
- package/examples/multi-command.ts +66 -0
- package/examples/spinner-progress.ts +49 -0
- package/examples/testing.ts +147 -0
- package/package.json +149 -2
- package/src/core/cli/dispatch.ts +286 -0
- package/src/core/cli/index.ts +978 -0
- package/src/core/cli/planner.ts +413 -0
- package/src/core/cli/plugin.ts +117 -0
- package/src/core/cli/propagate.ts +97 -0
- package/src/core/cli/root-help.ts +269 -0
- package/src/core/cli/root-surface.ts +74 -0
- package/src/core/cli/runtime-preflight.ts +409 -0
- package/src/core/completion/index.ts +88 -0
- package/src/core/completion/shells/bash.ts +459 -0
- package/src/core/completion/shells/fish.ts +259 -0
- package/src/core/completion/shells/powershell.ts +405 -0
- package/src/core/completion/shells/shared.ts +283 -0
- package/src/core/completion/shells/zsh.ts +381 -0
- package/src/core/config/index.ts +407 -0
- package/src/core/config/package-json.ts +220 -0
- package/src/core/errors/index.ts +193 -0
- package/src/core/execution/index.ts +270 -0
- package/src/core/help/index.ts +557 -0
- package/src/core/json-schema/index.ts +891 -0
- package/src/core/json-schema/meta-descriptions.generated.ts +202 -0
- package/src/core/output/activity.ts +568 -0
- package/src/core/output/contracts.ts +194 -0
- package/src/core/output/display-value.ts +48 -0
- package/src/core/output/index.ts +669 -0
- package/src/core/output/renderers.ts +125 -0
- package/src/core/output/writer.ts +46 -0
- package/src/core/parse/index.ts +661 -0
- package/src/core/prompt/index.ts +583 -0
- package/src/core/resolve/args.ts +144 -0
- package/src/core/resolve/coerce.ts +432 -0
- package/src/core/resolve/config.ts +26 -0
- package/src/core/resolve/contracts.ts +135 -0
- package/src/core/resolve/errors.ts +227 -0
- package/src/core/resolve/flags.ts +205 -0
- package/src/core/resolve/index.ts +108 -0
- package/src/core/resolve/property.ts +99 -0
- package/src/core/schema/activity.ts +240 -0
- package/src/core/schema/arg.ts +719 -0
- package/src/core/schema/command.ts +1490 -0
- package/src/core/schema/flag.ts +756 -0
- package/src/core/schema/index.ts +91 -0
- package/src/core/schema/middleware.ts +171 -0
- package/src/core/schema/prompt.ts +156 -0
- package/src/core/schema/run.ts +195 -0
- package/src/core/schema-dsl/index.ts +109 -0
- package/src/core/schema-dsl/parse.ts +262 -0
- package/src/core/schema-dsl/runtime.ts +609 -0
- package/src/core/schema-dsl/to-json-schema.ts +102 -0
- package/src/core/testkit/index.ts +123 -0
- package/src/index.ts +170 -0
- package/src/runtime/adapter.ts +303 -0
- package/src/runtime/auto.ts +110 -0
- package/src/runtime/bun.ts +55 -0
- package/src/runtime/deno.ts +369 -0
- package/src/runtime/detect.ts +105 -0
- package/src/runtime/index.ts +21 -0
- package/src/runtime/node-builtins.d.ts +23 -0
- package/src/runtime/node.ts +300 -0
- package/src/runtime/paths.ts +62 -0
- package/src/runtime/support.ts +135 -0
- package/src/runtime.ts +31 -0
- package/src/testkit.ts +25 -0
- package/src/version.ts +20 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://cdn.jsdelivr.net/npm/@kjanat/dreamcli/schema",
|
|
4
|
+
"title": "@kjanat/dreamcli definition schema",
|
|
5
|
+
"description": "Runtime descriptor for the CLI program.\n\nStores the program name, version, description, and registered commands.\\\nBuilt incrementally by CLIBuilder.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"$schema": {
|
|
10
|
+
"const": "https://cdn.jsdelivr.net/npm/@kjanat/dreamcli/schema"
|
|
11
|
+
},
|
|
12
|
+
"name": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Program name (used in help text, usage lines, and completion scripts)."
|
|
15
|
+
},
|
|
16
|
+
"version": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Program version (shown by `--version`)."
|
|
19
|
+
},
|
|
20
|
+
"description": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Program description (shown in root help)."
|
|
23
|
+
},
|
|
24
|
+
"defaultCommand": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Default command dispatched when no subcommand matches.\n\nWhen set, the CLI root behaves like a hybrid command group: subcommands\ndispatch by name as usual, but empty argv or flags-only argv falls\nthrough to this command instead of showing root help.\n\nSet via the .default() builder method."
|
|
27
|
+
},
|
|
28
|
+
"commands": {
|
|
29
|
+
"type": "array",
|
|
30
|
+
"items": {
|
|
31
|
+
"$ref": "#/$defs/command"
|
|
32
|
+
},
|
|
33
|
+
"description": "Registered commands (type-erased for heterogeneous storage)."
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"required": [
|
|
37
|
+
"$schema",
|
|
38
|
+
"name",
|
|
39
|
+
"commands"
|
|
40
|
+
],
|
|
41
|
+
"$defs": {
|
|
42
|
+
"command": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"additionalProperties": false,
|
|
45
|
+
"properties": {
|
|
46
|
+
"name": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"description": "The command name (used for dispatch, e.g. `'deploy'`)."
|
|
49
|
+
},
|
|
50
|
+
"description": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"description": "Human-readable description for help text."
|
|
53
|
+
},
|
|
54
|
+
"aliases": {
|
|
55
|
+
"type": "array",
|
|
56
|
+
"items": {
|
|
57
|
+
"type": "string"
|
|
58
|
+
},
|
|
59
|
+
"description": "Alternative names for this command."
|
|
60
|
+
},
|
|
61
|
+
"hidden": {
|
|
62
|
+
"const": true,
|
|
63
|
+
"description": "Whether this command is hidden from help listings."
|
|
64
|
+
},
|
|
65
|
+
"examples": {
|
|
66
|
+
"type": "array",
|
|
67
|
+
"items": {
|
|
68
|
+
"$ref": "#/$defs/example"
|
|
69
|
+
},
|
|
70
|
+
"description": "Usage examples for help text."
|
|
71
|
+
},
|
|
72
|
+
"flags": {
|
|
73
|
+
"type": "object",
|
|
74
|
+
"additionalProperties": {
|
|
75
|
+
"$ref": "#/$defs/flag"
|
|
76
|
+
},
|
|
77
|
+
"description": "Named flag schemas, keyed by flag name."
|
|
78
|
+
},
|
|
79
|
+
"args": {
|
|
80
|
+
"type": "array",
|
|
81
|
+
"items": {
|
|
82
|
+
"$ref": "#/$defs/arg"
|
|
83
|
+
},
|
|
84
|
+
"description": "Ordered positional arg entries (name + schema)."
|
|
85
|
+
},
|
|
86
|
+
"commands": {
|
|
87
|
+
"type": "array",
|
|
88
|
+
"items": {
|
|
89
|
+
"$ref": "#/$defs/command"
|
|
90
|
+
},
|
|
91
|
+
"description": "Nested subcommand schemas (for help rendering and completion).\n\nPure data — no execution closures. Populated by `.command()` on\n`CommandBuilder`. Empty for leaf commands."
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"required": [
|
|
95
|
+
"name",
|
|
96
|
+
"flags",
|
|
97
|
+
"args",
|
|
98
|
+
"commands"
|
|
99
|
+
],
|
|
100
|
+
"description": "Runtime descriptor produced by CommandBuilder.\n\nConsumers (parser, help generator, CLI dispatcher) read this to\nunderstand the command's shape — flags, args, aliases, subcommands,\nmiddleware, and interactive resolver."
|
|
101
|
+
},
|
|
102
|
+
"flag": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"additionalProperties": false,
|
|
105
|
+
"properties": {
|
|
106
|
+
"kind": {
|
|
107
|
+
"enum": [
|
|
108
|
+
"string",
|
|
109
|
+
"number",
|
|
110
|
+
"boolean",
|
|
111
|
+
"enum",
|
|
112
|
+
"array",
|
|
113
|
+
"custom"
|
|
114
|
+
],
|
|
115
|
+
"description": "What kind of value this flag accepts."
|
|
116
|
+
},
|
|
117
|
+
"presence": {
|
|
118
|
+
"enum": [
|
|
119
|
+
"optional",
|
|
120
|
+
"required",
|
|
121
|
+
"defaulted"
|
|
122
|
+
],
|
|
123
|
+
"description": "Presence describes whether a flag value is guaranteed to exist when the\naction handler runs:\n\n- `'optional'` — not required; unresolved value follows the kind-specific\n optional fallback (`undefined` for most flags, `[]` for arrays)\n- `'required'` — must be supplied; error if missing\n- `'defaulted'` — always present (falls back to default value)"
|
|
124
|
+
},
|
|
125
|
+
"defaultValue": {
|
|
126
|
+
"description": "Runtime default value (if any)."
|
|
127
|
+
},
|
|
128
|
+
"aliases": {
|
|
129
|
+
"type": "array",
|
|
130
|
+
"items": {
|
|
131
|
+
"type": "string"
|
|
132
|
+
},
|
|
133
|
+
"description": "Short/long aliases (e.g. `[{ name: 'f', hidden: false }]` for `--force`)."
|
|
134
|
+
},
|
|
135
|
+
"envVar": {
|
|
136
|
+
"type": "string",
|
|
137
|
+
"description": "Environment variable name for v0.2+ resolution."
|
|
138
|
+
},
|
|
139
|
+
"configPath": {
|
|
140
|
+
"type": "string",
|
|
141
|
+
"description": "Dotted config path for v0.2+ resolution (e.g. `'deploy.region'`)."
|
|
142
|
+
},
|
|
143
|
+
"description": {
|
|
144
|
+
"type": "string",
|
|
145
|
+
"description": "Human-readable description for help text."
|
|
146
|
+
},
|
|
147
|
+
"enumValues": {
|
|
148
|
+
"type": "array",
|
|
149
|
+
"items": {
|
|
150
|
+
"type": "string"
|
|
151
|
+
},
|
|
152
|
+
"description": "Allowed literal values when `kind === 'enum'`."
|
|
153
|
+
},
|
|
154
|
+
"elementSchema": {
|
|
155
|
+
"$ref": "#/$defs/flag",
|
|
156
|
+
"description": "Element schema when `kind === 'array'`."
|
|
157
|
+
},
|
|
158
|
+
"prompt": {
|
|
159
|
+
"$ref": "#/$defs/prompt",
|
|
160
|
+
"description": "Interactive prompt configuration for v0.3+ resolution."
|
|
161
|
+
},
|
|
162
|
+
"deprecated": {
|
|
163
|
+
"oneOf": [
|
|
164
|
+
{
|
|
165
|
+
"type": "string"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"const": true
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
"description": "Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated flag is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`."
|
|
172
|
+
},
|
|
173
|
+
"propagate": {
|
|
174
|
+
"const": true,
|
|
175
|
+
"description": "Whether this flag propagates to subcommands in nested command trees.\n\nWhen `true`, the flag is automatically available to all descendant\ncommands. A child command that defines a flag with the same name\nshadows the propagated parent flag."
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
"required": [
|
|
179
|
+
"kind",
|
|
180
|
+
"presence"
|
|
181
|
+
],
|
|
182
|
+
"description": "The runtime descriptor stored inside every FlagBuilder. Consumers (parser,\nhelp generator, resolution chain) read this to understand the flag's shape\nwithout touching generics."
|
|
183
|
+
},
|
|
184
|
+
"arg": {
|
|
185
|
+
"type": "object",
|
|
186
|
+
"additionalProperties": false,
|
|
187
|
+
"properties": {
|
|
188
|
+
"name": {
|
|
189
|
+
"type": "string",
|
|
190
|
+
"description": "A named positional argument entry in the command schema.\n\nPairs a user-facing arg name with its ArgSchema descriptor.\nThe array ordering in CommandSchema.args determines CLI position."
|
|
191
|
+
},
|
|
192
|
+
"kind": {
|
|
193
|
+
"enum": [
|
|
194
|
+
"string",
|
|
195
|
+
"number",
|
|
196
|
+
"enum",
|
|
197
|
+
"custom"
|
|
198
|
+
],
|
|
199
|
+
"description": "What kind of value this arg accepts."
|
|
200
|
+
},
|
|
201
|
+
"presence": {
|
|
202
|
+
"enum": [
|
|
203
|
+
"required",
|
|
204
|
+
"optional",
|
|
205
|
+
"defaulted"
|
|
206
|
+
],
|
|
207
|
+
"description": "Presence describes whether a positional arg is guaranteed to exist when the\naction handler runs:\n\n- `'required'` — must be supplied; error if missing (default)\n- `'optional'` — may be `undefined` if not supplied\n- `'defaulted'` — always present (falls back to default value)"
|
|
208
|
+
},
|
|
209
|
+
"variadic": {
|
|
210
|
+
"const": true,
|
|
211
|
+
"description": "Whether this arg consumes all remaining positionals."
|
|
212
|
+
},
|
|
213
|
+
"stdinMode": {
|
|
214
|
+
"const": true,
|
|
215
|
+
"description": "Whether this arg may read from stdin during resolution."
|
|
216
|
+
},
|
|
217
|
+
"defaultValue": {
|
|
218
|
+
"description": "Runtime default value (if any)."
|
|
219
|
+
},
|
|
220
|
+
"description": {
|
|
221
|
+
"type": "string",
|
|
222
|
+
"description": "Human-readable description for help text."
|
|
223
|
+
},
|
|
224
|
+
"envVar": {
|
|
225
|
+
"type": "string",
|
|
226
|
+
"description": "Environment variable name for env resolution.\n\nWhen set and the CLI value is absent, the resolver reads this env var\nand coerces the string to the arg's declared kind."
|
|
227
|
+
},
|
|
228
|
+
"enumValues": {
|
|
229
|
+
"type": "array",
|
|
230
|
+
"items": {
|
|
231
|
+
"type": "string"
|
|
232
|
+
},
|
|
233
|
+
"description": "Allowed literal values when `kind === 'enum'`."
|
|
234
|
+
},
|
|
235
|
+
"deprecated": {
|
|
236
|
+
"oneOf": [
|
|
237
|
+
{
|
|
238
|
+
"type": "string"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"const": true
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
"description": "Deprecation marker.\n\n- `undefined` — not deprecated (default)\n- `true` — deprecated with no migration message\n- `string` — deprecated with a reason/migration message\n\nWhen a deprecated arg is used, a warning is emitted to stderr.\nHelp text shows `[deprecated]` or `[deprecated: <reason>]`."
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
"required": [
|
|
248
|
+
"name",
|
|
249
|
+
"kind",
|
|
250
|
+
"presence"
|
|
251
|
+
],
|
|
252
|
+
"description": "The runtime descriptor stored inside every ArgBuilder. Consumers (parser,\nhelp generator) read this to understand the arg's shape without touching\ngenerics."
|
|
253
|
+
},
|
|
254
|
+
"prompt": {
|
|
255
|
+
"type": "object",
|
|
256
|
+
"additionalProperties": false,
|
|
257
|
+
"properties": {
|
|
258
|
+
"kind": {
|
|
259
|
+
"enum": [
|
|
260
|
+
"confirm",
|
|
261
|
+
"input",
|
|
262
|
+
"select",
|
|
263
|
+
"multiselect"
|
|
264
|
+
],
|
|
265
|
+
"description": "The kind of interactive prompt to present.\n\n- `'confirm'` — yes/no boolean question\n- `'input'` — free-text string input\n- `'select'` — single selection from a list\n- `'multiselect'` — multiple selections from a list"
|
|
266
|
+
},
|
|
267
|
+
"message": {
|
|
268
|
+
"type": "string",
|
|
269
|
+
"description": "The question displayed to the user."
|
|
270
|
+
},
|
|
271
|
+
"placeholder": {
|
|
272
|
+
"type": "string",
|
|
273
|
+
"description": "Placeholder text shown before user types (informational only)."
|
|
274
|
+
},
|
|
275
|
+
"choices": {
|
|
276
|
+
"type": "array",
|
|
277
|
+
"items": {
|
|
278
|
+
"$ref": "#/$defs/choice"
|
|
279
|
+
},
|
|
280
|
+
"description": "Available choices. When omitted for `enum` flags, the enum values\nfrom the flag schema are used automatically."
|
|
281
|
+
},
|
|
282
|
+
"min": {
|
|
283
|
+
"type": "integer",
|
|
284
|
+
"description": "Minimum number of selections required."
|
|
285
|
+
},
|
|
286
|
+
"max": {
|
|
287
|
+
"type": "integer",
|
|
288
|
+
"description": "Maximum number of selections allowed."
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
"required": [
|
|
292
|
+
"kind",
|
|
293
|
+
"message"
|
|
294
|
+
],
|
|
295
|
+
"description": "Discriminated union of all prompt configurations.\n\nUse the `kind` field to narrow:\n```ts\nif (config.kind === 'select') {\n config.choices // readonly SelectChoice[] | undefined\n}\n```"
|
|
296
|
+
},
|
|
297
|
+
"choice": {
|
|
298
|
+
"type": "object",
|
|
299
|
+
"additionalProperties": false,
|
|
300
|
+
"properties": {
|
|
301
|
+
"value": {
|
|
302
|
+
"type": "string",
|
|
303
|
+
"description": "The value returned when this choice is selected."
|
|
304
|
+
},
|
|
305
|
+
"label": {
|
|
306
|
+
"type": "string",
|
|
307
|
+
"description": "Display label shown to the user."
|
|
308
|
+
},
|
|
309
|
+
"description": {
|
|
310
|
+
"type": "string",
|
|
311
|
+
"description": "Optional description shown alongside the choice."
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
"required": [
|
|
315
|
+
"value"
|
|
316
|
+
],
|
|
317
|
+
"description": "A selectable option for SelectPromptConfig and MultiselectPromptConfig prompts."
|
|
318
|
+
},
|
|
319
|
+
"example": {
|
|
320
|
+
"type": "object",
|
|
321
|
+
"additionalProperties": false,
|
|
322
|
+
"properties": {
|
|
323
|
+
"command": {
|
|
324
|
+
"type": "string",
|
|
325
|
+
"description": "The command invocation (e.g. `'deploy production --force'`)."
|
|
326
|
+
},
|
|
327
|
+
"description": {
|
|
328
|
+
"type": "string",
|
|
329
|
+
"description": "Optional description of what this example does."
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
"required": [
|
|
333
|
+
"command"
|
|
334
|
+
],
|
|
335
|
+
"description": "A single usage example shown in help text."
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Basic single-command CLI.
|
|
4
|
+
*
|
|
5
|
+
* Demonstrates: typed positional args, typed flags, aliases, and default values.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* npx tsx examples/basic.ts Alice
|
|
9
|
+
* npx tsx examples/basic.ts Alice --loud --times 3
|
|
10
|
+
* npx tsx examples/basic.ts Alice -l -t 3
|
|
11
|
+
* npx tsx examples/basic.ts --help
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { arg, cli, command, flag } from '@kjanat/dreamcli';
|
|
15
|
+
|
|
16
|
+
const greet = command('greet')
|
|
17
|
+
.description('Greet someone')
|
|
18
|
+
.example('greet Alice', 'Greet Alice once')
|
|
19
|
+
.example('greet Alice --loud --times 3', 'Shout the greeting three times')
|
|
20
|
+
.arg('name', arg.string().describe('Who to greet'))
|
|
21
|
+
.flag('loud', flag.boolean().alias('l').describe('Shout the greeting'))
|
|
22
|
+
.flag('times', flag.number().default(1).alias('t').describe('Repeat count'))
|
|
23
|
+
.action(({ args, flags, out }) => {
|
|
24
|
+
// args.name: string — required positional
|
|
25
|
+
// flags.loud: boolean — defaults to false (all booleans do)
|
|
26
|
+
// flags.times: number — defaults to 1 (never undefined)
|
|
27
|
+
for (let i = 0; i < flags.times; i++) {
|
|
28
|
+
const msg = `Hello, ${args.name}!`;
|
|
29
|
+
out.log(flags.loud ? msg.toUpperCase() : msg);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
void cli('greet').default(greet).run();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gh",
|
|
3
|
+
"version": "0.0.0-example",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "A minimal GitHub CLI clone — dreamcli walkthrough example",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/kjanat/dreamcli.git",
|
|
9
|
+
"directory": "examples/gh"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"module": "src/main.ts",
|
|
13
|
+
"bin": {
|
|
14
|
+
"gh": "src/main.ts"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src",
|
|
18
|
+
"!src/**/*.test.ts"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"bd": "bun run build",
|
|
22
|
+
"build": "bun build src/main.ts --install --outdir=dist --format=esm --target=node --external @kjanat/dreamcli",
|
|
23
|
+
"test": "bun test",
|
|
24
|
+
"typecheck": "tsc --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@kjanat/dreamcli": "link:@kjanat/dreamcli"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/bun": "catalog:",
|
|
31
|
+
"typescript": "catalog:"
|
|
32
|
+
},
|
|
33
|
+
"packageManager": "bun@1.3.11",
|
|
34
|
+
"engines": {
|
|
35
|
+
"bun": ">=1.3.11"
|
|
36
|
+
},
|
|
37
|
+
"devEngines": {
|
|
38
|
+
"runtime": {
|
|
39
|
+
"name": "bun",
|
|
40
|
+
"version": ">=1.3.11",
|
|
41
|
+
"onFail": "error"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication commands for the walkthrough `gh` example.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { command, group } from '@kjanat/dreamcli';
|
|
8
|
+
|
|
9
|
+
import { redactToken, requireAuth, tokenFlag } from '../lib/auth.ts';
|
|
10
|
+
|
|
11
|
+
const authLogin = command('login')
|
|
12
|
+
.description('Authenticate with GitHub')
|
|
13
|
+
.flag(
|
|
14
|
+
'token',
|
|
15
|
+
tokenFlag('Authentication token')
|
|
16
|
+
.required()
|
|
17
|
+
.prompt({ kind: 'input', message: 'Paste your GitHub token:' }),
|
|
18
|
+
)
|
|
19
|
+
.action(({ flags, out }) => {
|
|
20
|
+
const { token } = requireAuth(flags.token);
|
|
21
|
+
const login = {
|
|
22
|
+
host: 'github.com',
|
|
23
|
+
token: redactToken(token),
|
|
24
|
+
storedAt: '~/.config/gh/config.json',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (out.jsonMode) {
|
|
28
|
+
out.json(login);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// In a real CLI, validate the token via API and write to config.
|
|
33
|
+
out.log(`Logged in with token ${login.token}`);
|
|
34
|
+
out.info(`Token would be saved to ${login.storedAt}`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const authStatus = command('status')
|
|
38
|
+
.description('Show authentication status')
|
|
39
|
+
.flag('token', tokenFlag())
|
|
40
|
+
.action(({ flags, out }) => {
|
|
41
|
+
const token = flags.token?.trim();
|
|
42
|
+
const status =
|
|
43
|
+
token === undefined || token.length === 0
|
|
44
|
+
? { authenticated: false, host: 'github.com' }
|
|
45
|
+
: { authenticated: true, host: 'github.com', token: redactToken(token) };
|
|
46
|
+
|
|
47
|
+
if (out.jsonMode) {
|
|
48
|
+
out.json(status);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (status.authenticated) {
|
|
53
|
+
out.log(status.host);
|
|
54
|
+
out.log(`Logged in with token ${status.token}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
out.warn('Not logged in. Run `gh auth login`.');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export { authLogin, authStatus };
|
|
62
|
+
|
|
63
|
+
export const auth = group('auth')
|
|
64
|
+
.description('Manage authentication')
|
|
65
|
+
.command(authLogin)
|
|
66
|
+
.command(authStatus);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Issue commands for the walkthrough `gh` example.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { arg, CLIError, flag, group } from '@kjanat/dreamcli';
|
|
8
|
+
|
|
9
|
+
import issues from '../data/issues.yaml' with { type: 'yaml' };
|
|
10
|
+
import { authedCommand } from '../lib/auth.ts';
|
|
11
|
+
import { normalizeLimit } from '../lib/utils.ts';
|
|
12
|
+
|
|
13
|
+
const issueLabelChoices = Array.from(new Set(issues.flatMap((issue) => issue.labels)))
|
|
14
|
+
.sort()
|
|
15
|
+
.map((label) => ({ value: label }));
|
|
16
|
+
|
|
17
|
+
const issueList = authedCommand('list')
|
|
18
|
+
.description('List issues')
|
|
19
|
+
.flag(
|
|
20
|
+
'state',
|
|
21
|
+
flag.enum(['open', 'closed', 'all']).default('open').alias('s').describe('Filter by state'),
|
|
22
|
+
)
|
|
23
|
+
.flag('limit', flag.number().default(10).alias('L').describe('Maximum number of results'))
|
|
24
|
+
.flag('label', flag.string().alias('l').describe('Filter by label'))
|
|
25
|
+
.action(({ flags, out }) => {
|
|
26
|
+
let results = [...issues];
|
|
27
|
+
|
|
28
|
+
if (flags.state !== 'all') {
|
|
29
|
+
results = results.filter((issue) => issue.state === flags.state);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (flags.label !== undefined) {
|
|
33
|
+
const label = flags.label;
|
|
34
|
+
results = results.filter((issue) => issue.labels.includes(label));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
results = results.slice(0, normalizeLimit(flags.limit));
|
|
38
|
+
|
|
39
|
+
out.table(
|
|
40
|
+
results.map((issue) => ({
|
|
41
|
+
'#': issue.number,
|
|
42
|
+
title: issue.title,
|
|
43
|
+
state: issue.state,
|
|
44
|
+
author: issue.author,
|
|
45
|
+
})),
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const issueTriage = authedCommand('triage')
|
|
50
|
+
.description('Triage an issue with guided prompts')
|
|
51
|
+
.arg('number', arg.number().describe('Issue number'))
|
|
52
|
+
.flag('decision', flag.enum(['backlog', 'close']).required().describe('How to handle the issue'))
|
|
53
|
+
.flag('label', flag.array(flag.string()).describe('Labels to keep when leaving the issue open'))
|
|
54
|
+
.flag('comment', flag.boolean().describe('Post a follow-up comment'))
|
|
55
|
+
.interactive(({ flags }) => {
|
|
56
|
+
const labels = flags.label ?? [];
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
label:
|
|
60
|
+
flags.decision === 'backlog' && labels.length === 0
|
|
61
|
+
? {
|
|
62
|
+
kind: 'multiselect',
|
|
63
|
+
message: 'Which labels still fit?',
|
|
64
|
+
choices: issueLabelChoices,
|
|
65
|
+
}
|
|
66
|
+
: false,
|
|
67
|
+
comment:
|
|
68
|
+
flags.decision === 'close' && !flags.comment
|
|
69
|
+
? { kind: 'confirm', message: 'Post a follow-up comment?' }
|
|
70
|
+
: false,
|
|
71
|
+
};
|
|
72
|
+
})
|
|
73
|
+
.action(({ args, flags, out }) => {
|
|
74
|
+
const issue = issues.find((candidate) => candidate.number === args.number);
|
|
75
|
+
|
|
76
|
+
if (!issue) {
|
|
77
|
+
throw new CLIError(`Issue #${args.number} not found`, {
|
|
78
|
+
code: 'NOT_FOUND',
|
|
79
|
+
exitCode: 1,
|
|
80
|
+
suggest: 'Try: gh issue list',
|
|
81
|
+
details: { requested: args.number },
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const selectedLabels = flags.label ?? [];
|
|
86
|
+
const labels =
|
|
87
|
+
flags.decision === 'backlog' && selectedLabels.length > 0 ? selectedLabels : issue.labels;
|
|
88
|
+
const triage = {
|
|
89
|
+
number: issue.number,
|
|
90
|
+
title: issue.title,
|
|
91
|
+
decision: flags.decision,
|
|
92
|
+
state: flags.decision === 'close' ? 'closed' : 'open',
|
|
93
|
+
labels,
|
|
94
|
+
commented: flags.decision === 'close' ? (flags.comment ?? false) : false,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
if (out.jsonMode) {
|
|
98
|
+
out.json(triage);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
out.log(`#${triage.number} ${triage.title}`);
|
|
103
|
+
if (triage.decision === 'close') {
|
|
104
|
+
out.log('Status: closed');
|
|
105
|
+
if (triage.commented) {
|
|
106
|
+
out.info('Would post a follow-up comment');
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
out.log('Status: open (backlog)');
|
|
112
|
+
out.log(`Labels: ${triage.labels.length > 0 ? triage.labels.join(', ') : 'none'}`);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export { issueList, issueTriage };
|
|
116
|
+
|
|
117
|
+
export const issue = group('issue')
|
|
118
|
+
.description('Manage issues')
|
|
119
|
+
.command(issueList)
|
|
120
|
+
.command(issueTriage);
|