@prisma/cli 3.0.0-alpha.1 → 3.0.0-alpha.11

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.
Files changed (56) hide show
  1. package/README.md +1 -16
  2. package/dist/adapters/git.js +49 -0
  3. package/dist/adapters/local-state.js +39 -1
  4. package/dist/adapters/token-storage.js +57 -1
  5. package/dist/cli2.js +60 -4
  6. package/dist/commands/app/index.js +41 -21
  7. package/dist/commands/auth/index.js +3 -2
  8. package/dist/commands/branch/index.js +2 -1
  9. package/dist/commands/env.js +87 -0
  10. package/dist/commands/git/index.js +36 -0
  11. package/dist/commands/project/index.js +12 -14
  12. package/dist/commands/version/index.js +18 -0
  13. package/dist/controllers/app-env.js +223 -0
  14. package/dist/controllers/app.js +1026 -169
  15. package/dist/controllers/auth.js +9 -9
  16. package/dist/controllers/branch.js +6 -6
  17. package/dist/controllers/project.js +451 -161
  18. package/dist/controllers/version.js +12 -0
  19. package/dist/lib/app/bun-project.js +1 -1
  20. package/dist/lib/app/deploy-output.js +15 -0
  21. package/dist/lib/app/env-config.js +57 -0
  22. package/dist/lib/app/env-vars.js +4 -4
  23. package/dist/lib/app/local-dev.js +1 -1
  24. package/dist/lib/app/preview-build.js +128 -1
  25. package/dist/lib/app/preview-interaction.js +2 -35
  26. package/dist/lib/app/preview-progress.js +43 -58
  27. package/dist/lib/app/preview-provider.js +125 -24
  28. package/dist/lib/auth/auth-ops.js +58 -13
  29. package/dist/lib/auth/client.js +1 -1
  30. package/dist/lib/auth/guard.js +1 -1
  31. package/dist/lib/auth/login.js +115 -4
  32. package/dist/lib/project/local-pin.js +51 -0
  33. package/dist/lib/project/resolution.js +201 -0
  34. package/dist/lib/version.js +55 -0
  35. package/dist/output/patterns.js +15 -18
  36. package/dist/presenters/app-env.js +129 -0
  37. package/dist/presenters/app.js +16 -29
  38. package/dist/presenters/auth.js +2 -2
  39. package/dist/presenters/branch.js +6 -6
  40. package/dist/presenters/project.js +87 -44
  41. package/dist/presenters/version.js +29 -0
  42. package/dist/shell/command-meta.js +148 -91
  43. package/dist/shell/command-runner.js +45 -7
  44. package/dist/shell/errors.js +9 -3
  45. package/dist/shell/global-flags.js +13 -1
  46. package/dist/shell/help.js +8 -7
  47. package/dist/shell/output.js +29 -12
  48. package/dist/shell/prompt.js +12 -2
  49. package/dist/shell/runtime.js +1 -1
  50. package/dist/shell/ui.js +19 -1
  51. package/dist/use-cases/auth.js +9 -12
  52. package/dist/use-cases/branch.js +20 -20
  53. package/dist/use-cases/create-cli-gateways.js +3 -13
  54. package/dist/use-cases/project.js +2 -48
  55. package/package.json +3 -3
  56. package/dist/adapters/config.js +0 -74
@@ -4,17 +4,21 @@ const DESCRIPTORS = [
4
4
  {
5
5
  id: "root",
6
6
  path: ["prisma"],
7
- description: "Unified Prisma CLI.",
8
- docsPath: "docs/product/command-principles.md",
9
- examples: ["prisma auth login", "prisma project list"],
10
- longDescription: "The Prisma CLI groups commands by developer workflow and keeps human and agent behavior aligned."
7
+ description: "The Prisma Developer Platform, from your terminal",
8
+ examples: ["prisma-cli auth login", "prisma-cli app deploy"],
9
+ longDescription: "Deploy your app with isolated infrastructure for every branch"
10
+ },
11
+ {
12
+ id: "version",
13
+ path: ["prisma", "version"],
14
+ description: "Show CLI build and environment",
15
+ examples: ["prisma-cli version", "prisma-cli version --json"]
11
16
  },
12
17
  {
13
18
  id: "auth",
14
19
  path: ["prisma", "auth"],
15
- description: "Authentication and identity commands.",
16
- docsPath: "docs/product/command-spec.md#prisma-auth-login",
17
- examples: ["prisma auth login", "prisma auth whoami"]
20
+ description: "Manage local authentication for the CLI",
21
+ examples: ["prisma-cli auth login", "prisma-cli auth whoami"]
18
22
  },
19
23
  {
20
24
  id: "auth.login",
@@ -23,9 +27,8 @@ const DESCRIPTORS = [
23
27
  "auth",
24
28
  "login"
25
29
  ],
26
- description: "Start an authenticated CLI session.",
27
- docsPath: "docs/product/command-spec.md#prisma-auth-login",
28
- examples: ["prisma auth login"]
30
+ description: "Log in to your Prisma platform account",
31
+ examples: ["prisma-cli auth login"]
29
32
  },
30
33
  {
31
34
  id: "auth.logout",
@@ -34,9 +37,8 @@ const DESCRIPTORS = [
34
37
  "auth",
35
38
  "logout"
36
39
  ],
37
- description: "Clear the current CLI session.",
38
- docsPath: "docs/product/command-spec.md#prisma-auth-logout",
39
- examples: ["prisma auth logout"]
40
+ description: "Clear stored authentication credentials",
41
+ examples: ["prisma-cli auth logout"]
40
42
  },
41
43
  {
42
44
  id: "auth.whoami",
@@ -45,34 +47,32 @@ const DESCRIPTORS = [
45
47
  "auth",
46
48
  "whoami"
47
49
  ],
48
- description: "Show the current authenticated identity.",
49
- docsPath: "docs/product/command-spec.md#prisma-auth-whoami",
50
- examples: ["prisma auth whoami", "prisma auth whoami --json"]
50
+ description: "Show the authenticated user and accessible workspace",
51
+ examples: ["prisma-cli auth whoami", "prisma-cli auth whoami --json"]
51
52
  },
52
53
  {
53
54
  id: "project",
54
55
  path: ["prisma", "project"],
55
- description: "Project discovery and repo linking commands.",
56
- docsPath: "docs/product/command-spec.md#prisma-project-list",
57
- examples: ["prisma project list", "prisma project show"]
56
+ description: "Manage and inspect your Prisma projects",
57
+ examples: ["prisma-cli project list", "prisma-cli project show"]
58
58
  },
59
59
  {
60
60
  id: "app",
61
61
  path: ["prisma", "app"],
62
- description: "App deployment and release commands.",
63
- docsPath: "docs/product/command-spec.md#prisma-app-deploy---app-name---entry-path---build-type-autobunnextjsnuxtastrotanstack-start---http-port-port---env-namevalue",
64
- examples: [
65
- "prisma app build --build-type nextjs",
66
- "prisma app deploy --app hello-world --build-type nextjs --http-port 3000",
67
- "prisma app deploy --app hello-world --build-type nuxt"
68
- ]
62
+ description: "Manage apps and deployments for a project",
63
+ examples: ["prisma-cli app deploy", "prisma-cli app deploy --app my-app --framework nextjs --http-port 3000"]
69
64
  },
70
65
  {
71
66
  id: "branch",
72
67
  path: ["prisma", "branch"],
73
- description: "Branch context and safety commands.",
74
- docsPath: "docs/product/command-spec.md#prisma-branch-list",
75
- examples: ["prisma branch list", "prisma branch use production"]
68
+ description: "View your active Platform branches",
69
+ examples: ["prisma-cli branch list", "prisma-cli branch show"]
70
+ },
71
+ {
72
+ id: "git",
73
+ path: ["prisma", "git"],
74
+ description: "Manage Git repository connections for a project",
75
+ examples: ["prisma-cli git connect", "prisma-cli git disconnect"]
76
76
  },
77
77
  {
78
78
  id: "project.list",
@@ -81,9 +81,8 @@ const DESCRIPTORS = [
81
81
  "project",
82
82
  "list"
83
83
  ],
84
- description: "List projects for the authenticated workspace.",
85
- docsPath: "docs/product/command-spec.md#prisma-project-list",
86
- examples: ["prisma project list", "prisma project list --json"]
84
+ description: "List all projects in your workspace",
85
+ examples: ["prisma-cli project list", "prisma-cli project list --json"]
87
86
  },
88
87
  {
89
88
  id: "project.show",
@@ -92,20 +91,32 @@ const DESCRIPTORS = [
92
91
  "project",
93
92
  "show"
94
93
  ],
95
- description: "Show the linked project for the current repo.",
96
- docsPath: "docs/product/command-spec.md#prisma-project-show",
97
- examples: ["prisma project show", "prisma project show --json"]
94
+ description: "Show which project is active for this directory",
95
+ examples: ["prisma-cli project show", "prisma-cli project show --project proj_123 --json"]
98
96
  },
99
97
  {
100
- id: "project.link",
98
+ id: "git.connect",
101
99
  path: [
102
100
  "prisma",
103
- "project",
104
- "link"
101
+ "git",
102
+ "connect"
105
103
  ],
106
- description: "Link the current repo to an existing project.",
107
- docsPath: "docs/product/command-spec.md#prisma-project-link-project",
108
- examples: ["prisma project link", "prisma project link proj_123"]
104
+ description: "Connect the resolved project to a GitHub repository",
105
+ examples: [
106
+ "prisma-cli git connect",
107
+ "prisma-cli git connect git@github.com:prisma/prisma-cli.git",
108
+ "prisma-cli git connect --project proj_123"
109
+ ]
110
+ },
111
+ {
112
+ id: "git.disconnect",
113
+ path: [
114
+ "prisma",
115
+ "git",
116
+ "disconnect"
117
+ ],
118
+ description: "Disconnect the GitHub repository from the resolved project",
119
+ examples: ["prisma-cli git disconnect", "prisma-cli git disconnect --project proj_123"]
109
120
  },
110
121
  {
111
122
  id: "branch.list",
@@ -114,9 +125,8 @@ const DESCRIPTORS = [
114
125
  "branch",
115
126
  "list"
116
127
  ],
117
- description: "List branches for the linked project.",
118
- docsPath: "docs/product/command-spec.md#prisma-branch-list",
119
- examples: ["prisma branch list", "prisma branch list --json"]
128
+ description: "List active Platform branches for the resolved project",
129
+ examples: ["prisma-cli branch list", "prisma-cli branch list --json"]
120
130
  },
121
131
  {
122
132
  id: "branch.show",
@@ -125,9 +135,8 @@ const DESCRIPTORS = [
125
135
  "branch",
126
136
  "show"
127
137
  ],
128
- description: "Show the current active branch context.",
129
- docsPath: "docs/product/command-spec.md#prisma-branch-show",
130
- examples: ["prisma branch show", "prisma branch show --json"]
138
+ description: "Show the Platform branch matching your current Git branch",
139
+ examples: ["prisma-cli branch show", "prisma-cli branch show --json"]
131
140
  },
132
141
  {
133
142
  id: "branch.use",
@@ -137,8 +146,7 @@ const DESCRIPTORS = [
137
146
  "use"
138
147
  ],
139
148
  description: "Change the local default branch context.",
140
- docsPath: "docs/product/command-spec.md#prisma-branch-use-name",
141
- examples: ["prisma branch use", "prisma branch use production"]
149
+ examples: ["prisma-cli branch use", "prisma-cli branch use production"]
142
150
  },
143
151
  {
144
152
  id: "app.build",
@@ -147,12 +155,11 @@ const DESCRIPTORS = [
147
155
  "app",
148
156
  "build"
149
157
  ],
150
- description: "Build the local app into a deployable artifact.",
151
- docsPath: "docs/product/command-spec.md#prisma-app-build---entry-path---build-type-autobunnextjsnuxtastrotanstack-start",
158
+ description: "Build the app locally into a deployable artifact",
152
159
  examples: [
153
- "prisma app build --build-type nextjs",
154
- "prisma app build --build-type nuxt",
155
- "prisma app build --build-type bun --entry server.ts"
160
+ "prisma-cli app build --build-type nextjs",
161
+ "prisma-cli app build --build-type nuxt",
162
+ "prisma-cli app build --build-type bun --entry server.ts"
156
163
  ]
157
164
  },
158
165
  {
@@ -162,9 +169,8 @@ const DESCRIPTORS = [
162
169
  "app",
163
170
  "run"
164
171
  ],
165
- description: "Start a local framework dev server.",
166
- docsPath: "docs/product/command-spec.md#prisma-app-run---entry-path---build-type-autobunnextjs---port-port",
167
- examples: ["prisma app run --build-type nextjs", "prisma app run --build-type bun --entry server.ts --port 3000"]
172
+ description: "Run your app locally",
173
+ examples: ["prisma-cli app run --build-type nextjs", "prisma-cli app run --build-type bun --entry server.ts --port 3000"]
168
174
  },
169
175
  {
170
176
  id: "app.deploy",
@@ -173,13 +179,12 @@ const DESCRIPTORS = [
173
179
  "app",
174
180
  "deploy"
175
181
  ],
176
- description: "Build and release the selected app.",
177
- docsPath: "docs/product/command-spec.md#prisma-app-deploy---app-name---entry-path---build-type-autobunnextjsnuxtastrotanstack-start---http-port-port---env-namevalue",
182
+ description: "Creates a new deployment for the app",
178
183
  examples: [
179
- "prisma app deploy",
180
- "prisma app deploy --app hello-world --env DATABASE_URL=postgresql://example",
181
- "prisma app deploy --app hello-world --build-type nextjs --http-port 3000",
182
- "prisma app deploy --app hello-world --build-type nuxt"
184
+ "prisma-cli app deploy",
185
+ "prisma-cli app deploy --app my-app --env DATABASE_URL=postgresql://example",
186
+ "prisma-cli app deploy --app my-app --framework nextjs --http-port 3000",
187
+ "prisma-cli app deploy --branch feat-login --framework hono"
183
188
  ]
184
189
  },
185
190
  {
@@ -190,8 +195,7 @@ const DESCRIPTORS = [
190
195
  "update-env"
191
196
  ],
192
197
  description: "Create a new deployment with updated environment variables.",
193
- docsPath: "docs/product/command-spec.md#prisma-app-update-env---app-name---env-namevalue",
194
- examples: ["prisma app update-env --env DATABASE_URL=postgresql://example", "prisma app update-env --app hello-world --env DATABASE_URL=postgresql://another"]
198
+ examples: ["prisma-cli app update-env --env DATABASE_URL=postgresql://example", "prisma-cli app update-env --app hello-world --env DATABASE_URL=postgresql://another"]
195
199
  },
196
200
  {
197
201
  id: "app.list-env",
@@ -201,8 +205,7 @@ const DESCRIPTORS = [
201
205
  "list-env"
202
206
  ],
203
207
  description: "List environment variable names for the selected app.",
204
- docsPath: "docs/product/command-spec.md#prisma-app-list-env---app-name",
205
- examples: ["prisma app list-env", "prisma app list-env --app hello-world"]
208
+ examples: ["prisma-cli app list-env", "prisma-cli app list-env --app hello-world"]
206
209
  },
207
210
  {
208
211
  id: "app.show",
@@ -211,9 +214,8 @@ const DESCRIPTORS = [
211
214
  "app",
212
215
  "show"
213
216
  ],
214
- description: "Show the current state of the selected app.",
215
- docsPath: "docs/product/command-spec.md#prisma-app-show---app-name",
216
- examples: ["prisma app show", "prisma app show --app hello-world"]
217
+ description: "Show the app and its current deployment",
218
+ examples: ["prisma-cli app show", "prisma-cli app show --app hello-world"]
217
219
  },
218
220
  {
219
221
  id: "app.open",
@@ -222,9 +224,8 @@ const DESCRIPTORS = [
222
224
  "app",
223
225
  "open"
224
226
  ],
225
- description: "Open the live URL for the selected app.",
226
- docsPath: "docs/product/command-spec.md#prisma-app-open---app-name",
227
- examples: ["prisma app open", "prisma app open --app hello-world"]
227
+ description: "Open the app's live URL",
228
+ examples: ["prisma-cli app open", "prisma-cli app open --app hello-world"]
228
229
  },
229
230
  {
230
231
  id: "app.logs",
@@ -233,9 +234,8 @@ const DESCRIPTORS = [
233
234
  "app",
234
235
  "logs"
235
236
  ],
236
- description: "Show or stream logs for a deployment.",
237
- docsPath: "docs/product/command-spec.md#prisma-app-logs---app-name---deployment-id",
238
- examples: ["prisma app logs", "prisma app logs --deployment dep_123"]
237
+ description: "Stream logs for the app's current deployment",
238
+ examples: ["prisma-cli app logs", "prisma-cli app logs --deployment dep_123"]
239
239
  },
240
240
  {
241
241
  id: "app.list-deploys",
@@ -244,9 +244,8 @@ const DESCRIPTORS = [
244
244
  "app",
245
245
  "list-deploys"
246
246
  ],
247
- description: "List deployments for the selected app.",
248
- docsPath: "docs/product/command-spec.md#prisma-app-list-deploys---app-name",
249
- examples: ["prisma app list-deploys", "prisma app list-deploys --app hello-world"]
247
+ description: "List deployments for the app",
248
+ examples: ["prisma-cli app list-deploys", "prisma-cli app list-deploys --app hello-world"]
250
249
  },
251
250
  {
252
251
  id: "app.show-deploy",
@@ -255,9 +254,8 @@ const DESCRIPTORS = [
255
254
  "app",
256
255
  "show-deploy"
257
256
  ],
258
- description: "Show one deployment in detail.",
259
- docsPath: "docs/product/command-spec.md#prisma-app-show-deploy-deployment",
260
- examples: ["prisma app show-deploy dep_123"]
257
+ description: "Show a deployment in detail",
258
+ examples: ["prisma-cli app show-deploy dep_123"]
261
259
  },
262
260
  {
263
261
  id: "app.promote",
@@ -266,9 +264,8 @@ const DESCRIPTORS = [
266
264
  "app",
267
265
  "promote"
268
266
  ],
269
- description: "Switch the live deployment for the selected app.",
270
- docsPath: "docs/product/command-spec.md#prisma-app-promote-deployment---app-name",
271
- examples: ["prisma app promote dep_123", "prisma app promote dep_123 --app hello-world"]
267
+ description: "Promote a deployment to production by rebuilding with production env vars",
268
+ examples: ["prisma-cli app promote dep_123", "prisma-cli app promote dep_123 --app hello-world"]
272
269
  },
273
270
  {
274
271
  id: "app.rollback",
@@ -277,9 +274,8 @@ const DESCRIPTORS = [
277
274
  "app",
278
275
  "rollback"
279
276
  ],
280
- description: "Restore the selected app to an earlier deployment.",
281
- docsPath: "docs/product/command-spec.md#prisma-app-rollback---app-name---to-deployment",
282
- examples: ["prisma app rollback", "prisma app rollback --app hello-world --to dep_123"]
277
+ description: "Roll back production to a previous deployment",
278
+ examples: ["prisma-cli app rollback", "prisma-cli app rollback --app hello-world --to dep_123"]
283
279
  },
284
280
  {
285
281
  id: "app.remove",
@@ -288,9 +284,70 @@ const DESCRIPTORS = [
288
284
  "app",
289
285
  "remove"
290
286
  ],
291
- description: "Remove the selected app from the linked project.",
292
- docsPath: "docs/product/command-spec.md#prisma-app-remove---app-name--y---yes",
293
- examples: ["prisma app remove --app hello-world", "prisma app remove --app hello-world --yes"]
287
+ description: "Remove the app from the current branch",
288
+ examples: ["prisma-cli app remove --app hello-world", "prisma-cli app remove --app hello-world --yes"]
289
+ },
290
+ {
291
+ id: "project.env",
292
+ path: [
293
+ "prisma",
294
+ "project",
295
+ "env"
296
+ ],
297
+ description: "Manage environment variables for the active project",
298
+ examples: [
299
+ "prisma-cli project env list --role production",
300
+ "prisma-cli project env add STRIPE_KEY=sk_test_xxx --role production",
301
+ "prisma-cli project env rm STRIPE_KEY --role preview"
302
+ ]
303
+ },
304
+ {
305
+ id: "project.env.add",
306
+ path: [
307
+ "prisma",
308
+ "project",
309
+ "env",
310
+ "add"
311
+ ],
312
+ description: "Create a new environment variable.",
313
+ examples: [
314
+ "prisma-cli project env add STRIPE_KEY=sk_test_xxx --role production",
315
+ "prisma-cli project env add STRIPE_KEY=sk_test_xxx --role preview",
316
+ "API_URL=https://api.example prisma-cli project env add API_URL --project proj_123 --role preview"
317
+ ]
318
+ },
319
+ {
320
+ id: "project.env.update",
321
+ path: [
322
+ "prisma",
323
+ "project",
324
+ "env",
325
+ "update"
326
+ ],
327
+ description: "Replace an existing environment variable's value.",
328
+ examples: ["prisma-cli project env update STRIPE_KEY=sk_new_xxx --role production", "prisma-cli project env update STRIPE_KEY=sk_new_xxx --role preview"]
329
+ },
330
+ {
331
+ id: "project.env.list",
332
+ path: [
333
+ "prisma",
334
+ "project",
335
+ "env",
336
+ "list"
337
+ ],
338
+ description: "List environment variable metadata for a scope (no values).",
339
+ examples: ["prisma-cli project env list --role production", "prisma-cli project env list --role preview"]
340
+ },
341
+ {
342
+ id: "project.env.rm",
343
+ path: [
344
+ "prisma",
345
+ "project",
346
+ "env",
347
+ "rm"
348
+ ],
349
+ description: "Remove an environment variable from a scope.",
350
+ examples: ["prisma-cli project env rm STRIPE_KEY --role production", "prisma-cli project env rm STRIPE_KEY --role preview"]
294
351
  }
295
352
  ];
296
353
  const DESCRIPTORS_BY_ID = new Map(DESCRIPTORS.map((descriptor) => [descriptor.id, descriptor]));
@@ -1,9 +1,15 @@
1
- import { CliError } from "./errors.js";
1
+ import { CliError, authRequiredError } from "./errors.js";
2
+ import { cliErrorToJson, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess } from "./output.js";
2
3
  import { getCommandDescriptor } from "./command-meta.js";
3
4
  import { resolveGlobalFlags } from "./global-flags.js";
4
5
  import { createCommandContext } from "./runtime.js";
5
- import { writeHumanError, writeHumanLines, writeJsonError, writeJsonSuccess } from "./output.js";
6
+ import { AuthError } from "@prisma/management-api-sdk";
6
7
  //#region src/shell/command-runner.ts
8
+ function toCliError(error) {
9
+ if (error instanceof CliError) return error;
10
+ if (error instanceof AuthError) return authRequiredError(["prisma-cli auth login"], { debug: error.message });
11
+ return null;
12
+ }
7
13
  async function runCommand(runtime, commandName, options, handler, presenter) {
8
14
  const flags = resolveGlobalFlags(runtime.argv, options);
9
15
  const context = await createCommandContext(runtime, flags);
@@ -20,14 +26,46 @@ async function runCommand(runtime, commandName, options, handler, presenter) {
20
26
  if (flags.quiet) return;
21
27
  writeHumanLines(context.output, presenter.renderHuman(context, descriptor, success.result));
22
28
  } catch (error) {
23
- if (error instanceof CliError) {
24
- if (flags.json) writeJsonError(context.output, commandName, error);
25
- else writeHumanError(context.output, context.ui, error, { trace: flags.trace });
26
- process.exitCode = error.exitCode;
29
+ const cliError = toCliError(error);
30
+ if (cliError) {
31
+ if (flags.json) writeJsonError(context.output, commandName, cliError);
32
+ else writeHumanError(context.output, context.ui, cliError, { trace: flags.trace });
33
+ process.exitCode = cliError.exitCode;
34
+ return;
35
+ }
36
+ throw error;
37
+ }
38
+ }
39
+ async function runStreamingCommand(runtime, commandName, options, handler) {
40
+ const flags = resolveGlobalFlags(runtime.argv, options);
41
+ const context = await createCommandContext(runtime, flags);
42
+ try {
43
+ await handler(context);
44
+ if (flags.json) writeJsonEvent(context.output, {
45
+ type: "success",
46
+ command: commandName,
47
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
48
+ result: null,
49
+ warnings: [],
50
+ nextSteps: []
51
+ });
52
+ } catch (error) {
53
+ const cliError = toCliError(error);
54
+ if (cliError) {
55
+ if (flags.json) writeJsonEvent(context.output, {
56
+ type: "error",
57
+ command: commandName,
58
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
59
+ error: cliErrorToJson(cliError),
60
+ warnings: [],
61
+ nextSteps: cliError.nextSteps
62
+ });
63
+ else writeHumanError(context.output, context.ui, cliError, { trace: flags.trace });
64
+ process.exitCode = cliError.exitCode;
27
65
  return;
28
66
  }
29
67
  throw error;
30
68
  }
31
69
  }
32
70
  //#endregion
33
- export { runCommand };
71
+ export { runCommand, runStreamingCommand };
@@ -12,6 +12,7 @@ var CliError = class extends Error {
12
12
  docsUrl;
13
13
  exitCode;
14
14
  nextSteps;
15
+ humanLines;
15
16
  constructor(options) {
16
17
  super(options.summary);
17
18
  this.name = "CliError";
@@ -27,6 +28,7 @@ var CliError = class extends Error {
27
28
  this.docsUrl = options.docsUrl ?? null;
28
29
  this.exitCode = options.exitCode ?? 1;
29
30
  this.nextSteps = options.nextSteps ?? [];
31
+ this.humanLines = options.humanLines && options.humanLines.length > 0 ? [...options.humanLines] : null;
30
32
  }
31
33
  };
32
34
  function usageError(summary, why, fix, nextSteps = [], domain = "cli") {
@@ -40,17 +42,21 @@ function usageError(summary, why, fix, nextSteps = [], domain = "cli") {
40
42
  nextSteps
41
43
  });
42
44
  }
43
- function authRequiredError(nextSteps = ["prisma auth login"]) {
45
+ function authRequiredError(nextSteps = ["prisma-cli auth login"], options = {}) {
44
46
  return new CliError({
45
47
  code: "AUTH_REQUIRED",
46
48
  domain: "auth",
47
49
  summary: "Authentication required",
48
50
  why: "This command needs an authenticated session.",
49
- fix: "Run prisma auth login, or rerun the command in a TTY to sign in interactively.",
51
+ fix: "Run prisma-cli auth login, or rerun the command in a TTY to sign in interactively.",
52
+ debug: options.debug,
50
53
  exitCode: 1,
51
54
  nextSteps
52
55
  });
53
56
  }
57
+ function workspaceRequiredError() {
58
+ return usageError("Workspace required", "This command needs an active workspace, but the authenticated session does not have one.", "Run prisma-cli auth login and choose a workspace.", ["prisma-cli auth login"], "auth");
59
+ }
54
60
  function featureUnavailableError(summary, why, fix, nextSteps = [], domain = "cli") {
55
61
  return new CliError({
56
62
  code: "FEATURE_UNAVAILABLE",
@@ -63,4 +69,4 @@ function featureUnavailableError(summary, why, fix, nextSteps = [], domain = "cl
63
69
  });
64
70
  }
65
71
  //#endregion
66
- export { CliError, authRequiredError, featureUnavailableError, usageError };
72
+ export { CliError, authRequiredError, featureUnavailableError, usageError, workspaceRequiredError };
@@ -1,8 +1,20 @@
1
1
  import { Option } from "commander";
2
2
  //#region src/shell/global-flags.ts
3
+ const COMPACT_GLOBAL_OPTION_FLAGS = [
4
+ "--json",
5
+ "-q, --quiet",
6
+ "-v, --verbose",
7
+ "--trace",
8
+ "--no-interactive",
9
+ "-y, --yes",
10
+ "--version"
11
+ ];
3
12
  function addGlobalFlags(command) {
4
13
  return command.option("--json", "Emit structured JSON output.").option("-q, --quiet", "Reduce human-oriented output.").option("-v, --verbose", "Increase human-oriented output detail.").option("--trace", "Show deeper diagnostics for failures.").option("-y, --yes", "Accept supported confirmation prompts.").addOption(new Option("--interactive", "Force interactive behavior when prompts are supported.")).addOption(new Option("--no-interactive", "Disable interactive behavior and prompts.")).addOption(new Option("--color", "Force color output in supported terminals.")).addOption(new Option("--no-color", "Disable color output."));
5
14
  }
15
+ function addCompactGlobalFlags(command) {
16
+ return command.option("--json", "Emit structured JSON output.").option("-q, --quiet", "Reduce human-oriented output.").option("-v, --verbose", "Increase human-oriented output detail.").option("--trace", "Show deeper diagnostics for failures.").addOption(new Option("--no-interactive", "Disable interactive behavior and prompts.")).option("-y, --yes", "Accept supported confirmation prompts.");
17
+ }
6
18
  function getExplicitBoolean(argv, positive, negative) {
7
19
  for (let index = argv.length - 1; index >= 0; index -= 1) {
8
20
  const value = argv[index];
@@ -22,4 +34,4 @@ function resolveGlobalFlags(argv, options) {
22
34
  };
23
35
  }
24
36
  //#endregion
25
- export { addGlobalFlags, resolveGlobalFlags };
37
+ export { COMPACT_GLOBAL_OPTION_FLAGS, addCompactGlobalFlags, addGlobalFlags, resolveGlobalFlags };
@@ -1,6 +1,6 @@
1
- import { formatDescriptorLabel, getDescriptorForCommand } from "./command-meta.js";
2
- import { resolveGlobalFlags } from "./global-flags.js";
3
1
  import { createShellUi, padDisplay, wrapText } from "./ui.js";
2
+ import { formatDescriptorLabel, getDescriptorForCommand } from "./command-meta.js";
3
+ import { COMPACT_GLOBAL_OPTION_FLAGS, resolveGlobalFlags } from "./global-flags.js";
4
4
  //#region src/shell/help.ts
5
5
  function renderHelp(command, runtime) {
6
6
  const descriptor = getDescriptorForCommand(command);
@@ -10,8 +10,14 @@ function renderHelp(command, runtime) {
10
10
  const visibleCommands = command.commands.filter((candidate) => candidate.name() !== "help" && !candidate.hidden);
11
11
  const visibleOptions = command.options.filter((candidate) => !candidate.hidden);
12
12
  if (visibleCommands.length > 0) lines.push(...renderCommandRows(rail, ui, visibleCommands));
13
+ if (descriptor.longDescription) {
14
+ lines.push(`${rail}`);
15
+ const wrapped = wrapText(descriptor.longDescription, Math.max(ui.width - 3, 40));
16
+ for (const line of wrapped) lines.push(`${rail} ${line}`);
17
+ }
13
18
  if (visibleOptions.length > 0) {
14
19
  if (visibleCommands.length > 0) lines.push(`${rail}`);
20
+ if (visibleCommands.length > 0 && visibleOptions.every((option) => COMPACT_GLOBAL_OPTION_FLAGS.includes(option.flags))) lines.push(`${rail} Global options:`);
15
21
  lines.push(...renderOptionRows(rail, ui, visibleOptions));
16
22
  }
17
23
  if (descriptor.examples && descriptor.examples.length > 0) {
@@ -19,11 +25,6 @@ function renderHelp(command, runtime) {
19
25
  lines.push(`${rail} Examples:`);
20
26
  for (const example of descriptor.examples) lines.push(`${rail} $ ${example}`);
21
27
  }
22
- if (descriptor.longDescription) {
23
- lines.push(`${rail}`);
24
- const wrapped = wrapText(descriptor.longDescription, Math.max(ui.width - 3, 40));
25
- for (const line of wrapped) lines.push(`${rail} ${line}`);
26
- }
27
28
  if (descriptor.docsPath) {
28
29
  lines.push(`${rail}`);
29
30
  lines.push(`${rail} ${ui.accent(padDisplay("Read more", 16))} ${ui.link(descriptor.docsPath)}`);
@@ -6,21 +6,27 @@ function writeJsonSuccess(output, success) {
6
6
  ...success
7
7
  }, null, 2)}\n`);
8
8
  }
9
+ function writeJsonEvent(output, event) {
10
+ output.stdout.write(`${JSON.stringify(event)}\n`);
11
+ }
12
+ function cliErrorToJson(error) {
13
+ return {
14
+ code: error.code,
15
+ domain: error.domain,
16
+ severity: error.severity,
17
+ summary: error.summary,
18
+ why: error.why,
19
+ fix: error.fix,
20
+ where: error.where,
21
+ meta: error.meta,
22
+ docsUrl: error.docsUrl
23
+ };
24
+ }
9
25
  function writeJsonError(output, command, error) {
10
26
  output.stdout.write(`${JSON.stringify({
11
27
  ok: false,
12
28
  command,
13
- error: {
14
- code: error.code,
15
- domain: error.domain,
16
- severity: error.severity,
17
- summary: error.summary,
18
- why: error.why,
19
- fix: error.fix,
20
- where: error.where,
21
- meta: error.meta,
22
- docsUrl: error.docsUrl
23
- },
29
+ error: cliErrorToJson(error),
24
30
  warnings: [],
25
31
  nextSteps: error.nextSteps
26
32
  }, null, 2)}\n`);
@@ -30,6 +36,17 @@ function writeHumanLines(output, lines) {
30
36
  output.stderr.write(`${lines.join("\n")}\n`);
31
37
  }
32
38
  function writeHumanError(output, ui, error, options) {
39
+ if (error.humanLines && error.humanLines.length > 0) {
40
+ const lines = [...error.humanLines];
41
+ if (options.trace && error.debug) {
42
+ lines.push("");
43
+ lines.push("Trace:");
44
+ lines.push(...error.debug.trimEnd().split("\n"));
45
+ }
46
+ lines.push(...renderNextSteps(error.nextSteps));
47
+ writeHumanLines(output, lines);
48
+ return;
49
+ }
33
50
  const lines = [renderSummaryLine(ui, "error", `${error.summary} [${error.code}]`)];
34
51
  if (error.where) lines.push(...["", `Where: ${error.where}`]);
35
52
  if (error.why) {
@@ -51,4 +68,4 @@ function writeHumanError(output, ui, error, options) {
51
68
  writeHumanLines(output, lines);
52
69
  }
53
70
  //#endregion
54
- export { writeHumanError, writeHumanLines, writeJsonError, writeJsonSuccess };
71
+ export { cliErrorToJson, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess };