@prisma-next/cli 0.3.0-dev.3 → 0.3.0-dev.30

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 (101) hide show
  1. package/README.md +111 -27
  2. package/dist/{chunk-BZMBKEEQ.js → chunk-AGOTG4L3.js} +44 -76
  3. package/dist/chunk-AGOTG4L3.js.map +1 -0
  4. package/dist/chunk-HLLI4YL7.js +180 -0
  5. package/dist/chunk-HLLI4YL7.js.map +1 -0
  6. package/dist/chunk-VG2R7DGF.js +735 -0
  7. package/dist/chunk-VG2R7DGF.js.map +1 -0
  8. package/dist/cli.d.ts +2 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +1502 -968
  11. package/dist/cli.js.map +1 -1
  12. package/dist/commands/contract-emit.d.ts +2 -4
  13. package/dist/commands/contract-emit.d.ts.map +1 -0
  14. package/dist/commands/contract-emit.js +3 -2
  15. package/dist/commands/db-init.d.ts +2 -4
  16. package/dist/commands/db-init.d.ts.map +1 -0
  17. package/dist/commands/db-init.js +205 -289
  18. package/dist/commands/db-init.js.map +1 -1
  19. package/dist/commands/db-introspect.d.ts +2 -4
  20. package/dist/commands/db-introspect.d.ts.map +1 -0
  21. package/dist/commands/db-introspect.js +108 -143
  22. package/dist/commands/db-introspect.js.map +1 -1
  23. package/dist/commands/db-schema-verify.d.ts +2 -4
  24. package/dist/commands/db-schema-verify.d.ts.map +1 -0
  25. package/dist/commands/db-schema-verify.js +120 -113
  26. package/dist/commands/db-schema-verify.js.map +1 -1
  27. package/dist/commands/db-sign.d.ts +2 -4
  28. package/dist/commands/db-sign.d.ts.map +1 -0
  29. package/dist/commands/db-sign.js +152 -156
  30. package/dist/commands/db-sign.js.map +1 -1
  31. package/dist/commands/db-verify.d.ts +2 -4
  32. package/dist/commands/db-verify.d.ts.map +1 -0
  33. package/dist/commands/db-verify.js +142 -122
  34. package/dist/commands/db-verify.js.map +1 -1
  35. package/dist/config-loader.d.ts +3 -5
  36. package/dist/config-loader.d.ts.map +1 -0
  37. package/dist/control-api/client.d.ts +13 -0
  38. package/dist/control-api/client.d.ts.map +1 -0
  39. package/dist/control-api/operations/db-init.d.ts +29 -0
  40. package/dist/control-api/operations/db-init.d.ts.map +1 -0
  41. package/dist/control-api/types.d.ts +387 -0
  42. package/dist/control-api/types.d.ts.map +1 -0
  43. package/dist/exports/config-types.d.ts +3 -0
  44. package/dist/exports/config-types.d.ts.map +1 -0
  45. package/dist/exports/config-types.js.map +1 -0
  46. package/dist/exports/control-api.d.ts +13 -0
  47. package/dist/exports/control-api.d.ts.map +1 -0
  48. package/dist/exports/control-api.js +7 -0
  49. package/dist/exports/control-api.js.map +1 -0
  50. package/dist/exports/index.d.ts +4 -0
  51. package/dist/exports/index.d.ts.map +1 -0
  52. package/dist/{index.js → exports/index.js} +4 -3
  53. package/dist/exports/index.js.map +1 -0
  54. package/dist/{index.d.ts → load-ts-contract.d.ts} +4 -8
  55. package/dist/load-ts-contract.d.ts.map +1 -0
  56. package/dist/utils/cli-errors.d.ts +7 -0
  57. package/dist/utils/cli-errors.d.ts.map +1 -0
  58. package/dist/utils/command-helpers.d.ts +12 -0
  59. package/dist/utils/command-helpers.d.ts.map +1 -0
  60. package/dist/utils/framework-components.d.ts +70 -0
  61. package/dist/utils/framework-components.d.ts.map +1 -0
  62. package/dist/utils/global-flags.d.ts +25 -0
  63. package/dist/utils/global-flags.d.ts.map +1 -0
  64. package/dist/utils/output.d.ts +142 -0
  65. package/dist/utils/output.d.ts.map +1 -0
  66. package/dist/utils/progress-adapter.d.ts +26 -0
  67. package/dist/utils/progress-adapter.d.ts.map +1 -0
  68. package/dist/utils/result-handler.d.ts +15 -0
  69. package/dist/utils/result-handler.d.ts.map +1 -0
  70. package/package.json +30 -26
  71. package/src/cli.ts +260 -0
  72. package/src/commands/contract-emit.ts +259 -0
  73. package/src/commands/db-init.ts +360 -0
  74. package/src/commands/db-introspect.ts +227 -0
  75. package/src/commands/db-schema-verify.ts +238 -0
  76. package/src/commands/db-sign.ts +279 -0
  77. package/src/commands/db-verify.ts +258 -0
  78. package/src/config-loader.ts +76 -0
  79. package/src/control-api/client.ts +589 -0
  80. package/src/control-api/operations/db-init.ts +281 -0
  81. package/src/control-api/types.ts +461 -0
  82. package/src/exports/config-types.ts +6 -0
  83. package/src/exports/control-api.ts +46 -0
  84. package/src/exports/index.ts +4 -0
  85. package/src/load-ts-contract.ts +217 -0
  86. package/src/utils/cli-errors.ts +26 -0
  87. package/src/utils/command-helpers.ts +26 -0
  88. package/src/utils/framework-components.ts +177 -0
  89. package/src/utils/global-flags.ts +75 -0
  90. package/src/utils/output.ts +1471 -0
  91. package/src/utils/progress-adapter.ts +86 -0
  92. package/src/utils/result-handler.ts +44 -0
  93. package/dist/chunk-464LNZCE.js +0 -134
  94. package/dist/chunk-464LNZCE.js.map +0 -1
  95. package/dist/chunk-BZMBKEEQ.js.map +0 -1
  96. package/dist/chunk-ZKYEJROM.js +0 -94
  97. package/dist/chunk-ZKYEJROM.js.map +0 -1
  98. package/dist/config-types.d.ts +0 -1
  99. package/dist/config-types.js.map +0 -1
  100. package/dist/index.js.map +0 -1
  101. /package/dist/{config-types.js → exports/config-types.js} +0 -0
@@ -0,0 +1,142 @@
1
+ import type { Command } from 'commander';
2
+ export interface EmitContractResult {
3
+ readonly coreHash: string;
4
+ readonly profileHash: string;
5
+ readonly outDir: string;
6
+ readonly files: {
7
+ readonly json: string;
8
+ readonly dts: string;
9
+ };
10
+ readonly timings: {
11
+ readonly total: number;
12
+ };
13
+ }
14
+ import type { CoreSchemaView } from '@prisma-next/core-control-plane/schema-view';
15
+ import type { IntrospectSchemaResult, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult } from '@prisma-next/core-control-plane/types';
16
+ import type { CliErrorEnvelope } from './cli-errors';
17
+ import type { GlobalFlags } from './global-flags';
18
+ /**
19
+ * Formats human-readable output for contract emit.
20
+ */
21
+ export declare function formatEmitOutput(result: EmitContractResult, flags: GlobalFlags): string;
22
+ /**
23
+ * Formats JSON output for contract emit.
24
+ */
25
+ export declare function formatEmitJson(result: EmitContractResult): string;
26
+ /**
27
+ * Formats error output for human-readable display.
28
+ */
29
+ export declare function formatErrorOutput(error: CliErrorEnvelope, flags: GlobalFlags): string;
30
+ /**
31
+ * Formats error output as JSON.
32
+ */
33
+ export declare function formatErrorJson(error: CliErrorEnvelope): string;
34
+ /**
35
+ * Formats human-readable output for database verify.
36
+ */
37
+ export declare function formatVerifyOutput(result: VerifyDatabaseResult, flags: GlobalFlags): string;
38
+ /**
39
+ * Formats JSON output for database verify.
40
+ */
41
+ export declare function formatVerifyJson(result: VerifyDatabaseResult): string;
42
+ /**
43
+ * Formats JSON output for database introspection.
44
+ */
45
+ export declare function formatIntrospectJson(result: IntrospectSchemaResult<unknown>): string;
46
+ /**
47
+ * Formats human-readable output for database introspection.
48
+ */
49
+ export declare function formatIntrospectOutput(result: IntrospectSchemaResult<unknown>, schemaView: CoreSchemaView | undefined, flags: GlobalFlags): string;
50
+ /**
51
+ * Formats human-readable output for database schema verification.
52
+ */
53
+ export declare function formatSchemaVerifyOutput(result: VerifyDatabaseSchemaResult, flags: GlobalFlags): string;
54
+ /**
55
+ * Formats JSON output for database schema verification.
56
+ */
57
+ export declare function formatSchemaVerifyJson(result: VerifyDatabaseSchemaResult): string;
58
+ /**
59
+ * Formats human-readable output for database sign.
60
+ */
61
+ export declare function formatSignOutput(result: SignDatabaseResult, flags: GlobalFlags): string;
62
+ /**
63
+ * Formats JSON output for database sign.
64
+ */
65
+ export declare function formatSignJson(result: SignDatabaseResult): string;
66
+ /**
67
+ * Result type for db init command.
68
+ */
69
+ export interface DbInitResult {
70
+ readonly ok: boolean;
71
+ readonly mode: 'plan' | 'apply';
72
+ readonly plan?: {
73
+ readonly targetId: string;
74
+ readonly destination: {
75
+ readonly coreHash: string;
76
+ readonly profileHash?: string;
77
+ };
78
+ readonly operations: readonly {
79
+ readonly id: string;
80
+ readonly label: string;
81
+ readonly operationClass: string;
82
+ }[];
83
+ };
84
+ readonly execution?: {
85
+ readonly operationsPlanned: number;
86
+ readonly operationsExecuted: number;
87
+ };
88
+ readonly marker?: {
89
+ readonly coreHash: string;
90
+ readonly profileHash?: string;
91
+ };
92
+ readonly summary: string;
93
+ readonly timings: {
94
+ readonly total: number;
95
+ };
96
+ }
97
+ /**
98
+ * Formats human-readable output for db init plan mode.
99
+ */
100
+ export declare function formatDbInitPlanOutput(result: DbInitResult, flags: GlobalFlags): string;
101
+ /**
102
+ * Formats human-readable output for db init apply mode.
103
+ */
104
+ export declare function formatDbInitApplyOutput(result: DbInitResult, flags: GlobalFlags): string;
105
+ /**
106
+ * Formats JSON output for db init command.
107
+ */
108
+ export declare function formatDbInitJson(result: DbInitResult): string;
109
+ /**
110
+ * Formats the header in the new experimental visual style.
111
+ * This header appears at the start of command output, showing the operation,
112
+ * intent, documentation link, and parameters.
113
+ */
114
+ export declare function formatStyledHeader(options: {
115
+ readonly command: string;
116
+ readonly description: string;
117
+ readonly url?: string;
118
+ readonly details: ReadonlyArray<{
119
+ readonly label: string;
120
+ readonly value: string;
121
+ }>;
122
+ readonly flags: GlobalFlags;
123
+ }): string;
124
+ /**
125
+ * Formats a success message in the styled output format.
126
+ */
127
+ export declare function formatSuccessMessage(flags: GlobalFlags): string;
128
+ /**
129
+ * Formats help output for a command using the styled format.
130
+ */
131
+ export declare function formatCommandHelp(options: {
132
+ readonly command: Command;
133
+ readonly flags: GlobalFlags;
134
+ }): string;
135
+ /**
136
+ * Formats help output for the root program using the styled format.
137
+ */
138
+ export declare function formatRootHelp(options: {
139
+ readonly program: Command;
140
+ readonly flags: GlobalFlags;
141
+ }): string;
142
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,MAAM,WAAW,kBAA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C7B,GAAG,MAAM,CAyGT;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B,GAAG,MAAM,CA2FT"}
@@ -0,0 +1,26 @@
1
+ import type { OnControlProgress } from '../control-api/types';
2
+ import type { GlobalFlags } from './global-flags';
3
+ /**
4
+ * Options for creating a progress adapter.
5
+ */
6
+ interface ProgressAdapterOptions {
7
+ /**
8
+ * Global flags that control progress output behavior (quiet, json, color).
9
+ */
10
+ readonly flags: GlobalFlags;
11
+ }
12
+ /**
13
+ * Creates a progress adapter that converts control-api progress events
14
+ * into CLI spinner/progress output.
15
+ *
16
+ * The adapter:
17
+ * - Starts/succeeds spinners for top-level span boundaries
18
+ * - Prints per-operation lines for nested spans (e.g., migration operations under 'apply')
19
+ * - Respects quiet/json/non-TTY flags (no-op in those cases)
20
+ *
21
+ * @param options - Progress adapter configuration
22
+ * @returns An onProgress callback compatible with control-api operations
23
+ */
24
+ export declare function createProgressAdapter(options: ProgressAdapterOptions): OnControlProgress;
25
+ export {};
26
+ //# sourceMappingURL=progress-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress-adapter.d.ts","sourceRoot":"","sources":["../../src/utils/progress-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AACH,UAAU,sBAAsB;IAC9B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAUD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,iBAAiB,CAmDxF"}
@@ -0,0 +1,15 @@
1
+ import type { Result } from '@prisma-next/utils/result';
2
+ import type { CliStructuredError } from './cli-errors';
3
+ import type { GlobalFlags } from './global-flags';
4
+ /**
5
+ * Processes a CLI command result, handling both success and error cases.
6
+ * Formats output appropriately and returns the exit code.
7
+ * Never throws - returns exit code for commands to use with process.exit().
8
+ *
9
+ * @param result - The result from a CLI command
10
+ * @param flags - Global flags for output formatting
11
+ * @param onSuccess - Optional callback for successful results (for custom success output)
12
+ * @returns The exit code that should be used (0 for success, non-zero for errors)
13
+ */
14
+ export declare function handleResult<T>(result: Result<T, CliStructuredError>, flags: GlobalFlags, onSuccess?: (value: T) => void): number;
15
+ //# sourceMappingURL=result-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-handler.d.ts","sourceRoot":"","sources":["../../src/utils/result-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,kBAAkB,CAAC,EACrC,KAAK,EAAE,WAAW,EAClB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC7B,MAAM,CAwBR"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@prisma-next/cli",
3
- "version": "0.3.0-dev.3",
3
+ "version": "0.3.0-dev.30",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
7
- "dist"
7
+ "dist",
8
+ "src"
8
9
  ],
9
10
  "bin": {
10
11
  "prisma-next": "./dist/cli.js"
@@ -19,33 +20,32 @@
19
20
  "string-width": "^7.2.0",
20
21
  "strip-ansi": "^7.1.2",
21
22
  "wrap-ansi": "^9.0.2",
22
- "@prisma-next/contract": "0.3.0-dev.3",
23
- "@prisma-next/core-control-plane": "0.3.0-dev.3",
24
- "@prisma-next/emitter": "0.3.0-dev.3",
25
- "@prisma-next/utils": "0.3.0-dev.3"
23
+ "@prisma-next/contract": "0.3.0-dev.30",
24
+ "@prisma-next/core-control-plane": "0.3.0-dev.30",
25
+ "@prisma-next/emitter": "0.3.0-dev.30",
26
+ "@prisma-next/utils": "0.3.0-dev.30"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@types/node": "24.10.4",
29
- "@vitest/coverage-v8": "^4.0.0",
30
- "tsup": "^8.3.0",
31
- "typescript": "^5.9.3",
32
- "vite-tsconfig-paths": "^5.1.4",
33
- "vitest": "^4.0.16",
34
- "@prisma-next/sql-contract": "0.3.0-dev.3",
35
- "@prisma-next/sql-contract-emitter": "0.3.0-dev.3",
36
- "@prisma-next/sql-contract-ts": "0.3.0-dev.3",
37
- "@prisma-next/sql-operations": "0.3.0-dev.3",
38
- "@prisma-next/sql-runtime": "0.3.0-dev.3",
39
- "@prisma-next/test-utils": "0.0.1"
30
+ "tsup": "8.5.1",
31
+ "typescript": "5.9.3",
32
+ "vitest": "4.0.16",
33
+ "@prisma-next/sql-contract": "0.3.0-dev.30",
34
+ "@prisma-next/sql-contract-emitter": "0.3.0-dev.30",
35
+ "@prisma-next/sql-contract-ts": "0.3.0-dev.30",
36
+ "@prisma-next/sql-operations": "0.3.0-dev.30",
37
+ "@prisma-next/sql-runtime": "0.3.0-dev.30",
38
+ "@prisma-next/test-utils": "0.0.1",
39
+ "@prisma-next/tsconfig": "0.0.0"
40
40
  },
41
41
  "exports": {
42
42
  ".": {
43
- "types": "./dist/index.d.ts",
44
- "import": "./dist/index.js"
43
+ "types": "./dist/exports/index.d.ts",
44
+ "import": "./dist/exports/index.js"
45
45
  },
46
46
  "./config-types": {
47
- "types": "./dist/config-types.d.ts",
48
- "import": "./dist/config-types.js"
47
+ "types": "./dist/exports/config-types.d.ts",
48
+ "import": "./dist/exports/config-types.js"
49
49
  },
50
50
  "./commands/db-init": {
51
51
  "types": "./dist/commands/db-init.d.ts",
@@ -74,16 +74,20 @@
74
74
  "./config-loader": {
75
75
  "types": "./dist/config-loader.d.ts",
76
76
  "import": "./dist/config-loader.js"
77
+ },
78
+ "./control-api": {
79
+ "types": "./dist/exports/control-api.d.ts",
80
+ "import": "./dist/exports/control-api.js"
77
81
  }
78
82
  },
79
83
  "scripts": {
80
- "build": "tsup --config tsup.config.ts",
84
+ "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
81
85
  "test": "vitest run",
82
86
  "test:coverage": "vitest run --coverage",
83
87
  "typecheck": "tsc --project tsconfig.json --noEmit",
84
- "lint": "biome check . --config-path ../../../../biome.json --error-on-warnings",
85
- "lint:fix": "biome check --write . --config-path ../../../../biome.json",
86
- "lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../../biome.json",
87
- "clean": "node ../../../../scripts/clean.mjs"
88
+ "lint": "biome check . --error-on-warnings",
89
+ "lint:fix": "biome check --write .",
90
+ "lint:fix:unsafe": "biome check --write --unsafe .",
91
+ "clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
88
92
  }
89
93
  }
package/src/cli.ts ADDED
@@ -0,0 +1,260 @@
1
+ import { Command } from 'commander';
2
+ import { createContractEmitCommand } from './commands/contract-emit';
3
+ import { createDbInitCommand } from './commands/db-init';
4
+ import { createDbIntrospectCommand } from './commands/db-introspect';
5
+ import { createDbSchemaVerifyCommand } from './commands/db-schema-verify';
6
+ import { createDbSignCommand } from './commands/db-sign';
7
+ import { createDbVerifyCommand } from './commands/db-verify';
8
+ import { setCommandDescriptions } from './utils/command-helpers';
9
+ import { parseGlobalFlags } from './utils/global-flags';
10
+ import { formatCommandHelp, formatRootHelp } from './utils/output';
11
+
12
+ const program = new Command();
13
+
14
+ program.name('prisma-next').description('Prisma Next CLI').version('0.0.1');
15
+
16
+ // Override version option description to match capitalization style
17
+ const versionOption = program.options.find((opt) => opt.flags.includes('--version'));
18
+ if (versionOption) {
19
+ versionOption.description = 'Output the version number';
20
+ }
21
+
22
+ program.configureOutput({
23
+ writeErr: () => {
24
+ // Suppress all default error output - we handle errors in exitOverride
25
+ },
26
+ writeOut: () => {
27
+ // Suppress all default output - our custom formatters handle everything
28
+ },
29
+ });
30
+
31
+ // Customize root help output to use our styled format
32
+ const rootHelpFormatter = (cmd: Command) => {
33
+ const flags = parseGlobalFlags({});
34
+ return formatRootHelp({ program: cmd, flags });
35
+ };
36
+
37
+ program.configureHelp({
38
+ formatHelp: rootHelpFormatter,
39
+ subcommandDescription: () => '',
40
+ });
41
+
42
+ // Override exit to handle unhandled errors (fail fast cases)
43
+ // Commands handle structured errors themselves via process.exit()
44
+ program.exitOverride((err) => {
45
+ if (err) {
46
+ // Help requests are not errors - allow Commander to output help and exit normally
47
+ // Commander throws errors with codes like 'commander.help', 'commander.helpDisplayed', or 'outputHelp'
48
+ const errorCode = (err as { code?: string }).code;
49
+ const errorMessage = String(err.message ?? '');
50
+ const errorName = err.name ?? '';
51
+
52
+ // Check for unknown command errors first (before other checks)
53
+ // Commander.js uses code 'commander.unknownCommand' or error message contains 'unknown command'
54
+ const isUnknownCommandError =
55
+ errorCode === 'commander.unknownCommand' ||
56
+ errorCode === 'commander.unknownArgument' ||
57
+ (errorName === 'CommanderError' &&
58
+ (errorMessage.includes('unknown command') || errorMessage.includes('unknown argument')));
59
+ if (isUnknownCommandError) {
60
+ const flags = parseGlobalFlags({});
61
+ // Extract the command/subcommand name from the error message
62
+ // Error message format: "unknown command 'command-name'"
63
+ const match = errorMessage.match(/unknown command ['"]([^'"]+)['"]/);
64
+ const commandName = match ? match[1] : process.argv[3] || process.argv[2] || 'unknown';
65
+
66
+ // Determine which command context we're in
67
+ // Check if the first argument is a recognized parent command
68
+ const firstArg = process.argv[2];
69
+ const parentCommand = firstArg
70
+ ? program.commands.find((cmd) => cmd.name() === firstArg)
71
+ : undefined;
72
+
73
+ if (parentCommand && commandName !== firstArg) {
74
+ // Unrecognized subcommand - show parent command help
75
+ // eslint-disable-next-line no-console
76
+ console.error(`Unknown command: ${commandName}`);
77
+ // eslint-disable-next-line no-console
78
+ console.error('');
79
+ const helpText = formatCommandHelp({ command: parentCommand, flags });
80
+ // eslint-disable-next-line no-console
81
+ console.log(helpText);
82
+ } else {
83
+ // Unrecognized top-level command - show root help
84
+ // eslint-disable-next-line no-console
85
+ console.error(`Unknown command: ${commandName}`);
86
+ // eslint-disable-next-line no-console
87
+ console.error('');
88
+ const helpText = formatRootHelp({ program, flags });
89
+ // eslint-disable-next-line no-console
90
+ console.log(helpText);
91
+ }
92
+ process.exit(1);
93
+ return;
94
+ }
95
+ const isHelpError =
96
+ errorCode === 'commander.help' ||
97
+ errorCode === 'commander.helpDisplayed' ||
98
+ errorCode === 'outputHelp' ||
99
+ errorMessage === '(outputHelp)' ||
100
+ errorMessage.includes('outputHelp') ||
101
+ (errorName === 'CommanderError' && errorMessage.includes('outputHelp'));
102
+ if (isHelpError) {
103
+ process.exit(0);
104
+ return;
105
+ }
106
+ // Missing required arguments/subcommands - show help and exit with 0
107
+ // Commander throws errors with code 'commander.missingArgument' or 'commander.missingMandatoryOptionValue'
108
+ // or when a command with subcommands is called without a subcommand
109
+ const isMissingArgumentError =
110
+ errorCode === 'commander.missingArgument' ||
111
+ errorCode === 'commander.missingMandatoryOptionValue' ||
112
+ (errorName === 'CommanderError' &&
113
+ (errorMessage.includes('missing') || errorMessage.includes('required')));
114
+ if (isMissingArgumentError) {
115
+ // Help was already displayed by Commander.js, just exit with 0
116
+ process.exit(0);
117
+ return;
118
+ }
119
+ // Unhandled error - fail fast with exit code 1
120
+ // eslint-disable-next-line no-console
121
+ console.error(`Unhandled error: ${err.message}`);
122
+ if (err.stack) {
123
+ // eslint-disable-next-line no-console
124
+ console.error(err.stack);
125
+ }
126
+ process.exit(1);
127
+ }
128
+ process.exit(0);
129
+ });
130
+
131
+ // Register contract subcommand
132
+ const contractCommand = new Command('contract');
133
+ setCommandDescriptions(
134
+ contractCommand,
135
+ 'Contract management commands',
136
+ 'Define and emit your application data contract. The contract describes your schema as a\n' +
137
+ 'declarative data structure that can be signed and verified against your database.',
138
+ );
139
+ contractCommand.configureHelp({
140
+ formatHelp: (cmd) => {
141
+ const flags = parseGlobalFlags({});
142
+ return formatCommandHelp({ command: cmd, flags });
143
+ },
144
+ subcommandDescription: () => '',
145
+ });
146
+
147
+ // Add emit subcommand to contract
148
+ const contractEmitCommand = createContractEmitCommand();
149
+ contractCommand.addCommand(contractEmitCommand);
150
+
151
+ // Register contract command
152
+ program.addCommand(contractCommand);
153
+
154
+ // Register db subcommand
155
+ const dbCommand = new Command('db');
156
+ setCommandDescriptions(
157
+ dbCommand,
158
+ 'Database management commands',
159
+ 'Verify and sign your database with your contract. Ensure your database schema matches\n' +
160
+ 'your contract, and sign it to record the contract hash for future verification.',
161
+ );
162
+ dbCommand.configureHelp({
163
+ formatHelp: (cmd) => {
164
+ const flags = parseGlobalFlags({});
165
+ return formatCommandHelp({ command: cmd, flags });
166
+ },
167
+ subcommandDescription: () => '',
168
+ });
169
+
170
+ // Add verify subcommand to db
171
+ const dbVerifyCommand = createDbVerifyCommand();
172
+ dbCommand.addCommand(dbVerifyCommand);
173
+
174
+ // Add init subcommand to db
175
+ const dbInitCommand = createDbInitCommand();
176
+ dbCommand.addCommand(dbInitCommand);
177
+
178
+ // Add introspect subcommand to db
179
+ const dbIntrospectCommand = createDbIntrospectCommand();
180
+ dbCommand.addCommand(dbIntrospectCommand);
181
+
182
+ // Add schema-verify subcommand to db
183
+ const dbSchemaVerifyCommand = createDbSchemaVerifyCommand();
184
+ dbCommand.addCommand(dbSchemaVerifyCommand);
185
+
186
+ // Add sign subcommand to db
187
+ const dbSignCommand = createDbSignCommand();
188
+ dbCommand.addCommand(dbSignCommand);
189
+
190
+ // Register db command
191
+ program.addCommand(dbCommand);
192
+
193
+ // Create help command
194
+ const helpCommand = new Command('help')
195
+ .description('Show usage instructions')
196
+ .configureHelp({
197
+ formatHelp: (cmd) => {
198
+ const flags = parseGlobalFlags({});
199
+ return formatCommandHelp({ command: cmd, flags });
200
+ },
201
+ })
202
+ .action(() => {
203
+ const flags = parseGlobalFlags({});
204
+ const helpText = formatRootHelp({ program, flags });
205
+ // eslint-disable-next-line no-console
206
+ console.log(helpText);
207
+ process.exit(0);
208
+ });
209
+
210
+ program.addCommand(helpCommand);
211
+
212
+ // Set help as the default action when no command is provided
213
+ program.action(() => {
214
+ const flags = parseGlobalFlags({});
215
+ const helpText = formatRootHelp({ program, flags });
216
+ // eslint-disable-next-line no-console
217
+ console.log(helpText);
218
+ process.exit(0);
219
+ });
220
+
221
+ // Check if a command was invoked with no arguments (just the command name)
222
+ // or if an unrecognized command was provided
223
+ const args = process.argv.slice(2);
224
+ if (args.length > 0) {
225
+ const commandName = args[0];
226
+ // Handle version option explicitly since we suppress default output
227
+ if (commandName === '--version' || commandName === '-V') {
228
+ // eslint-disable-next-line no-console
229
+ console.log(program.version());
230
+ process.exit(0);
231
+ }
232
+ // Skip command check for global options like --help, -h
233
+ const isGlobalOption = commandName === '--help' || commandName === '-h';
234
+ if (!isGlobalOption) {
235
+ // Check if this is a recognized command
236
+ const command = program.commands.find((cmd) => cmd.name() === commandName);
237
+
238
+ if (!command) {
239
+ // Unrecognized command - show error message and usage
240
+ const flags = parseGlobalFlags({});
241
+ // eslint-disable-next-line no-console
242
+ console.error(`Unknown command: ${commandName}`);
243
+ // eslint-disable-next-line no-console
244
+ console.error('');
245
+ const helpText = formatRootHelp({ program, flags });
246
+ // eslint-disable-next-line no-console
247
+ console.log(helpText);
248
+ process.exit(1);
249
+ } else if (command.commands.length > 0 && args.length === 1) {
250
+ // Parent command called with no subcommand - show help and exit with 0
251
+ const flags = parseGlobalFlags({});
252
+ const helpText = formatCommandHelp({ command, flags });
253
+ // eslint-disable-next-line no-console
254
+ console.log(helpText);
255
+ process.exit(0);
256
+ }
257
+ }
258
+ }
259
+
260
+ program.parse();