@di-framework/cli-plugin-platform 0.0.1 → 6.0.3

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 (169) hide show
  1. package/README.md +408 -0
  2. package/dist/actor-protocol.d.ts +4 -0
  3. package/dist/actor-protocol.js +162 -0
  4. package/dist/actors.d.ts +31 -0
  5. package/dist/actors.js +296 -0
  6. package/dist/args.d.ts +15 -0
  7. package/dist/args.js +66 -0
  8. package/dist/assets/http-adapter.js +876 -0
  9. package/dist/assets/platform/.gitignore.tmpl +6 -0
  10. package/dist/assets/platform/Pulumi.yaml.tmpl +6 -0
  11. package/dist/assets/platform/README.md +208 -0
  12. package/dist/assets/platform/index.ts.tmpl +2 -0
  13. package/dist/assets/platform/package.json.tmpl +18 -0
  14. package/dist/assets/platform/tsconfig.json +11 -0
  15. package/dist/assets/queue-adapter.js +60 -0
  16. package/dist/assets/sqlite/BUILD-INFO.txt +13 -0
  17. package/dist/assets/sqlite/SHA256SUMS +2 -0
  18. package/dist/assets/sqlite/di-framework-sqlite.wasm +0 -0
  19. package/dist/assets/sqlite/di-framework-sqlite.wit +337 -0
  20. package/dist/assets/wit/deps/LICENSE.md +8 -0
  21. package/dist/assets/wit/deps/di-framework-queues/package.wit +18 -0
  22. package/dist/assets/wit/deps/di-framework-sqlite/package.wit +211 -0
  23. package/dist/assets/wit/deps/wasi-cli/package.wit +70 -0
  24. package/dist/assets/wit/deps/wasi-clocks/package.wit +42 -0
  25. package/dist/assets/wit/deps/wasi-config/package.wit +15 -0
  26. package/dist/assets/wit/deps/wasi-filesystem/package.wit +184 -0
  27. package/dist/assets/wit/deps/wasi-http/package.wit +170 -0
  28. package/dist/assets/wit/deps/wasi-random/package.wit +17 -0
  29. package/dist/assets/wit/deps/wasi-sockets/package.wit +105 -0
  30. package/dist/assets/wit/deps/wasi-tls/package.wit +26 -0
  31. package/dist/assets/wit/deps/wasmcloud-blobstore/package.wit +153 -0
  32. package/dist/assets/wit/deps/wasmcloud-keyvalue/package.wit +370 -0
  33. package/dist/assets/wit/deps/wasmcloud-messaging/package.wit +125 -0
  34. package/dist/assets/wit/deps/wasmcloud-postgres/package.wit +435 -0
  35. package/dist/assets/wit/deps/wasmcloud-secrets/package.wit +80 -0
  36. package/dist/async-transform.d.ts +3 -0
  37. package/dist/async-transform.js +60 -0
  38. package/dist/bindings.d.ts +34 -0
  39. package/dist/bindings.js +307 -0
  40. package/dist/build.d.ts +29 -0
  41. package/dist/build.js +325 -0
  42. package/dist/command.d.ts +3 -0
  43. package/dist/command.js +141 -0
  44. package/dist/control/auth.d.ts +18 -0
  45. package/dist/control/auth.js +89 -0
  46. package/dist/control/cron.d.ts +7 -0
  47. package/dist/control/cron.js +86 -0
  48. package/dist/control/index.d.ts +4 -0
  49. package/dist/control/index.js +4 -0
  50. package/dist/control/network.d.ts +12 -0
  51. package/dist/control/network.js +49 -0
  52. package/dist/control/queues.d.ts +15 -0
  53. package/dist/control/queues.js +77 -0
  54. package/dist/cron.d.ts +26 -0
  55. package/dist/cron.js +239 -0
  56. package/dist/deploy.d.ts +29 -0
  57. package/dist/deploy.js +57 -0
  58. package/dist/deps.d.ts +96 -0
  59. package/dist/deps.js +303 -0
  60. package/dist/destroy.d.ts +3 -0
  61. package/dist/destroy.js +24 -0
  62. package/dist/dev-runner.d.ts +24 -0
  63. package/dist/dev-runner.js +83 -0
  64. package/dist/dev.d.ts +8 -0
  65. package/dist/dev.js +76 -0
  66. package/dist/discovery.d.ts +15 -0
  67. package/dist/discovery.js +182 -0
  68. package/dist/doctor.d.ts +8 -0
  69. package/dist/doctor.js +82 -0
  70. package/dist/guests.d.ts +9 -0
  71. package/dist/guests.js +56 -0
  72. package/dist/host-interface.d.ts +29 -0
  73. package/dist/host-interface.js +142 -0
  74. package/dist/index.d.ts +33 -0
  75. package/dist/index.js +39 -0
  76. package/dist/kubernetes.d.ts +9 -0
  77. package/dist/kubernetes.js +17 -0
  78. package/dist/managed-bindings.d.ts +9 -0
  79. package/dist/managed-bindings.js +150 -0
  80. package/dist/manifest.d.ts +36 -0
  81. package/dist/manifest.js +257 -0
  82. package/dist/namespace.d.ts +2 -0
  83. package/dist/namespace.js +4 -0
  84. package/dist/node-compat/async-hooks.d.ts +29 -0
  85. package/dist/node-compat/async-hooks.js +80 -0
  86. package/dist/node-compat/bootstrap.d.ts +1 -0
  87. package/dist/node-compat/bootstrap.js +9 -0
  88. package/dist/node-compat/bytes.d.ts +7 -0
  89. package/dist/node-compat/bytes.js +41 -0
  90. package/dist/node-compat/crypto-hash.d.ts +27 -0
  91. package/dist/node-compat/crypto-hash.js +108 -0
  92. package/dist/node-compat/crypto-subtle.d.ts +59 -0
  93. package/dist/node-compat/crypto-subtle.js +288 -0
  94. package/dist/node-compat/crypto.d.ts +136 -0
  95. package/dist/node-compat/crypto.js +142 -0
  96. package/dist/node-compat/dgram.d.ts +49 -0
  97. package/dist/node-compat/dgram.js +197 -0
  98. package/dist/node-compat/env.d.ts +6 -0
  99. package/dist/node-compat/env.js +88 -0
  100. package/dist/node-compat/fetch-runtime.d.ts +80 -0
  101. package/dist/node-compat/fetch-runtime.js +314 -0
  102. package/dist/node-compat/fs.d.ts +84 -0
  103. package/dist/node-compat/fs.js +285 -0
  104. package/dist/node-compat/http-parser.d.ts +40 -0
  105. package/dist/node-compat/http-parser.js +185 -0
  106. package/dist/node-compat/http.d.ts +130 -0
  107. package/dist/node-compat/http.js +688 -0
  108. package/dist/node-compat/https.d.ts +28 -0
  109. package/dist/node-compat/https.js +88 -0
  110. package/dist/node-compat/module.d.ts +11 -0
  111. package/dist/node-compat/module.js +35 -0
  112. package/dist/node-compat/net.d.ts +119 -0
  113. package/dist/node-compat/net.js +441 -0
  114. package/dist/node-compat/process.d.ts +25 -0
  115. package/dist/node-compat/process.js +63 -0
  116. package/dist/node-compat/runtime-application.d.ts +4 -0
  117. package/dist/node-compat/runtime-application.js +24 -0
  118. package/dist/node-compat/seed-virtual.d.ts +6 -0
  119. package/dist/node-compat/seed-virtual.js +6 -0
  120. package/dist/node-compat/seed.d.ts +20 -0
  121. package/dist/node-compat/seed.js +106 -0
  122. package/dist/node-compat/socket-address.d.ts +35 -0
  123. package/dist/node-compat/socket-address.js +162 -0
  124. package/dist/node-compat/timers.d.ts +32 -0
  125. package/dist/node-compat/timers.js +96 -0
  126. package/dist/node-compat/tls.d.ts +57 -0
  127. package/dist/node-compat/tls.js +290 -0
  128. package/dist/node-compat/wasi-random.d.ts +2 -0
  129. package/dist/node-compat/wasi-random.js +25 -0
  130. package/dist/node-compat/wasi-sockets.d.ts +47 -0
  131. package/dist/node-compat/wasi-sockets.js +134 -0
  132. package/dist/oci.d.ts +9 -0
  133. package/dist/oci.js +9 -0
  134. package/dist/paths.d.ts +7 -0
  135. package/dist/paths.js +13 -0
  136. package/dist/platform-init.d.ts +13 -0
  137. package/dist/platform-init.js +265 -0
  138. package/dist/platform.d.ts +22 -0
  139. package/dist/platform.js +170 -0
  140. package/dist/project.d.ts +39 -0
  141. package/dist/project.js +130 -0
  142. package/dist/publish.d.ts +15 -0
  143. package/dist/publish.js +57 -0
  144. package/dist/pulumi.d.ts +4 -0
  145. package/dist/pulumi.js +27 -0
  146. package/dist/queues-module.d.ts +4 -0
  147. package/dist/queues-module.js +89 -0
  148. package/dist/queues.d.ts +16 -0
  149. package/dist/queues.js +167 -0
  150. package/dist/registry.d.ts +16 -0
  151. package/dist/registry.js +27 -0
  152. package/dist/service.d.ts +162 -0
  153. package/dist/service.js +678 -0
  154. package/dist/support.d.ts +14 -0
  155. package/dist/support.js +37 -0
  156. package/dist/target.d.ts +18 -0
  157. package/dist/target.js +45 -0
  158. package/dist/toml.d.ts +6 -0
  159. package/dist/toml.js +245 -0
  160. package/dist/wash-dev.d.ts +18 -0
  161. package/dist/wash-dev.js +80 -0
  162. package/dist/wit.d.ts +76 -0
  163. package/dist/wit.js +248 -0
  164. package/dist/workload-members.d.ts +12 -0
  165. package/dist/workload-members.js +136 -0
  166. package/dist/workload.d.ts +45 -0
  167. package/dist/workload.js +457 -0
  168. package/package.json +55 -8
  169. package/src/index.ts +0 -2
package/dist/actors.js ADDED
@@ -0,0 +1,296 @@
1
+ import * as fs from 'node:fs';
2
+ import { join, relative, sep } from 'node:path';
3
+ import ts from 'typescript';
4
+ import { ALWAYS_SKIP_DIRECTORIES } from './manifest.js';
5
+ export const WASMCLOUD_ACTORS_GLOBAL = 'di-framework.wasmcloud.actors';
6
+ import { ACTORS_INVOCATION_PATH, handleActorInvocationRequest } from './actor-protocol.js';
7
+ export { ACTORS_INVOCATION_PATH, handleActorInvocationRequest, isActorInvocationRequest, } from './actor-protocol.js';
8
+ export function createWasmcloudActorAdapter(actorRuntime) {
9
+ const dispatchActorInvocation = async (actorType, actorKey, method, args = []) => {
10
+ return await actorRuntime.invoke(actorType, actorKey, method, args);
11
+ };
12
+ const handle = async (request) => {
13
+ // Prefer the local dispatch path so mailbox serialization is preserved.
14
+ // HTTP adapters that need RPC deadline/auth semantics pass runtime without dispatchFn.
15
+ return await handleActorInvocationRequest(request, undefined, dispatchActorInvocation);
16
+ };
17
+ const invoke = async (actorType, actorKey, method, args = []) => {
18
+ const request = new Request(`http://localhost${ACTORS_INVOCATION_PATH}`, {
19
+ method: 'POST',
20
+ headers: { 'content-type': 'application/json' },
21
+ body: JSON.stringify({ actorType, actorKey, method, args }),
22
+ });
23
+ const response = await handle(request);
24
+ const data = await response.json();
25
+ if (!response.ok || !data.success) {
26
+ const err = new Error(data.error?.message ?? 'Actor invocation failed');
27
+ err.name = data.error?.name ?? 'Error';
28
+ Object.assign(err, data.error);
29
+ throw err;
30
+ }
31
+ return data.result;
32
+ };
33
+ return {
34
+ handle,
35
+ invoke,
36
+ dispatchActorInvocation,
37
+ actorRuntime,
38
+ };
39
+ }
40
+ function stringLiteral(node) {
41
+ if (node === undefined)
42
+ return undefined;
43
+ if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
44
+ return node.text;
45
+ return undefined;
46
+ }
47
+ function objectLiteral(node) {
48
+ if (node === undefined || !ts.isObjectLiteralExpression(node))
49
+ return undefined;
50
+ const result = {};
51
+ for (const property of node.properties) {
52
+ if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name))
53
+ continue;
54
+ const name = property.name.text;
55
+ const value = property.initializer;
56
+ if (ts.isStringLiteral(value) || ts.isNoSubstitutionTemplateLiteral(value)) {
57
+ result[name] = value.text;
58
+ }
59
+ else if (ts.isNumericLiteral(value)) {
60
+ result[name] = Number(value.text);
61
+ }
62
+ else if (value.kind === ts.SyntaxKind.TrueKeyword) {
63
+ result[name] = true;
64
+ }
65
+ else if (value.kind === ts.SyntaxKind.FalseKeyword) {
66
+ result[name] = false;
67
+ }
68
+ else if (ts.isArrayLiteralExpression(value)) {
69
+ result[name] = value.elements.map((el) => stringLiteral(el) ?? true);
70
+ }
71
+ }
72
+ return result;
73
+ }
74
+ function classDecorators(node) {
75
+ const fromModifiers = (node.modifiers ?? []).filter((modifier) => ts.isDecorator(modifier));
76
+ const legacy = node
77
+ .decorators;
78
+ return [...fromModifiers, ...(legacy ?? [])];
79
+ }
80
+ function methodDecorators(node) {
81
+ const fromModifiers = (node.modifiers ?? []).filter((modifier) => ts.isDecorator(modifier));
82
+ const legacy = node
83
+ .decorators;
84
+ return [...fromModifiers, ...(legacy ?? [])];
85
+ }
86
+ function parseActorFile(filePath, projectRoot) {
87
+ let content;
88
+ try {
89
+ content = fs.readFileSync(filePath, 'utf8');
90
+ }
91
+ catch {
92
+ return [];
93
+ }
94
+ // Quick heuristic before AST parsing
95
+ if (!content.includes('Actor') && !content.includes('@di-framework/actors')) {
96
+ return [];
97
+ }
98
+ const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, filePath.endsWith('.ts') ? ts.ScriptKind.TS : ts.ScriptKind.JS);
99
+ const records = [];
100
+ for (const statement of sourceFile.statements) {
101
+ if (!ts.isClassDeclaration(statement) || !statement.name)
102
+ continue;
103
+ const className = statement.name.text;
104
+ let isActor = false;
105
+ let actorName = className;
106
+ let namespace = 'default';
107
+ let hasMigrations = false;
108
+ for (const decorator of classDecorators(statement)) {
109
+ const expr = decorator.expression;
110
+ let decName;
111
+ if (ts.isIdentifier(expr)) {
112
+ decName = expr.text;
113
+ }
114
+ else if (ts.isCallExpression(expr)) {
115
+ if (ts.isIdentifier(expr.expression)) {
116
+ decName = expr.expression.text;
117
+ }
118
+ else if (ts.isPropertyAccessExpression(expr.expression)) {
119
+ decName = expr.expression.name.text;
120
+ }
121
+ if (decName === 'Actor') {
122
+ const arg = expr.arguments[0];
123
+ if (arg) {
124
+ const str = stringLiteral(arg);
125
+ if (str) {
126
+ actorName = str;
127
+ }
128
+ else {
129
+ const obj = objectLiteral(arg);
130
+ if (obj) {
131
+ if (typeof obj.name === 'string')
132
+ actorName = obj.name;
133
+ if (typeof obj.namespace === 'string')
134
+ namespace = obj.namespace;
135
+ if (obj.migrations)
136
+ hasMigrations = true;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ if (decName === 'Actor') {
143
+ isActor = true;
144
+ }
145
+ }
146
+ if (!isActor)
147
+ continue;
148
+ // Scan methods
149
+ const methods = [];
150
+ for (const member of statement.members) {
151
+ if (!ts.isMethodDeclaration(member) || !member.name || !ts.isIdentifier(member.name))
152
+ continue;
153
+ const methodName = member.name.text;
154
+ let isActorMethod = false;
155
+ let exposedName = methodName;
156
+ let timeout;
157
+ for (const dec of methodDecorators(member)) {
158
+ const expr = dec.expression;
159
+ let decName;
160
+ if (ts.isIdentifier(expr)) {
161
+ decName = expr.text;
162
+ }
163
+ else if (ts.isCallExpression(expr)) {
164
+ if (ts.isIdentifier(expr.expression)) {
165
+ decName = expr.expression.text;
166
+ }
167
+ else if (ts.isPropertyAccessExpression(expr.expression)) {
168
+ decName = expr.expression.name.text;
169
+ }
170
+ if (decName === 'ActorMethod') {
171
+ const arg = expr.arguments[0];
172
+ if (arg) {
173
+ const str = stringLiteral(arg);
174
+ if (str) {
175
+ exposedName = str;
176
+ }
177
+ else {
178
+ const obj = objectLiteral(arg);
179
+ if (obj) {
180
+ if (typeof obj.name === 'string')
181
+ exposedName = obj.name;
182
+ if (typeof obj.timeout === 'number')
183
+ timeout = obj.timeout;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ if (decName === 'ActorMethod') {
190
+ isActorMethod = true;
191
+ }
192
+ }
193
+ if (isActorMethod) {
194
+ methods.push({ name: exposedName, methodName, timeout });
195
+ }
196
+ }
197
+ // Relative import path from .di-framework/ to the source file
198
+ const generatedDir = join(projectRoot, '.di-framework');
199
+ let relPath = relative(generatedDir, filePath).split(sep).join('/');
200
+ if (!relPath.startsWith('.')) {
201
+ relPath = `./${relPath}`;
202
+ }
203
+ records.push({
204
+ className,
205
+ actorName,
206
+ namespace,
207
+ filePath,
208
+ importPath: relPath,
209
+ methods,
210
+ hasMigrations,
211
+ });
212
+ }
213
+ return records;
214
+ }
215
+ export function discoverActors(project) {
216
+ const root = project.projectRoot;
217
+ const actors = [];
218
+ const visited = new Set();
219
+ const scanDir = (dir) => {
220
+ if (visited.has(dir))
221
+ return;
222
+ visited.add(dir);
223
+ let entries = [];
224
+ try {
225
+ entries = fs.readdirSync(dir, { withFileTypes: true });
226
+ }
227
+ catch {
228
+ return;
229
+ }
230
+ for (const entry of entries) {
231
+ const fullPath = join(dir, entry.name);
232
+ if (entry.isDirectory()) {
233
+ if (ALWAYS_SKIP_DIRECTORIES.has(entry.name) ||
234
+ entry.name === 'dist' ||
235
+ entry.name === '.di-framework') {
236
+ continue;
237
+ }
238
+ scanDir(fullPath);
239
+ }
240
+ else if (entry.isFile() && (entry.name.endsWith('.ts') || entry.name.endsWith('.js'))) {
241
+ if (entry.name.endsWith('.d.ts') ||
242
+ entry.name.endsWith('.test.ts') ||
243
+ entry.name.endsWith('.spec.ts')) {
244
+ continue;
245
+ }
246
+ const fileActors = parseActorFile(fullPath, root);
247
+ actors.push(...fileActors);
248
+ }
249
+ }
250
+ };
251
+ // Check entry directory and src/
252
+ const srcDir = join(root, 'src');
253
+ if (fs.existsSync(srcDir)) {
254
+ scanDir(srcDir);
255
+ }
256
+ else {
257
+ scanDir(root);
258
+ }
259
+ // Also check entryPath directly if not visited
260
+ if (fs.existsSync(project.entryPath) && !actors.some((a) => a.filePath === project.entryPath)) {
261
+ const fileActors = parseActorFile(project.entryPath, root);
262
+ actors.push(...fileActors);
263
+ }
264
+ return actors;
265
+ }
266
+ export function renderActorsModule(actors, options = {}) {
267
+ const lines = [];
268
+ lines.push("import { ActorRuntime, SqliteActorStorage } from '@di-framework/actors';");
269
+ const importedClassNames = [];
270
+ for (const actor of actors) {
271
+ importedClassNames.push(actor.className);
272
+ lines.push(`import { ${actor.className} } from ${JSON.stringify(actor.importPath)};`);
273
+ }
274
+ lines.push('');
275
+ const defaultDir = options.defaultStorageDir ?? './.actors';
276
+ lines.push(`const defaultStorageDir = ${JSON.stringify(defaultDir)};`, 'let storage;', 'let runtime;', '', 'function resolveStorageDir() {', ' return process.env.ACTOR_STORAGE_DIR || process.env.DI_STORAGE_DIR || defaultStorageDir;', '}', '', 'function ensureActorRuntime() {', ' if (runtime) return runtime;', ' // WASI VFS has no file locking; exclusive ownership is enforced by replicas: 1.', ' // Defer until first use so WASI environment (ACTOR_STORAGE_DIR) is available.', ' storage = new SqliteActorStorage({ baseDir: resolveStorageDir(), fileLocking: false });', ' runtime = new ActorRuntime({ storage });');
277
+ for (const actor of actors) {
278
+ lines.push(` runtime.register(${actor.className}, {`, ` name: ${JSON.stringify(actor.actorName)},`, ` namespace: ${JSON.stringify(actor.namespace)},`, ' });');
279
+ }
280
+ lines.push(' return runtime;', '}', '', 'export async function dispatchActorInvocation(actorType, actorKey, method, args = []) {', ' return await ensureActorRuntime().invoke(actorType, actorKey, method, args);', '}', '', 'export function getActorRuntime() { return ensureActorRuntime(); }', 'export { getActorRuntime as actorRuntime, storage };', `export { ${importedClassNames.join(', ')} };`, '', `globalThis[Symbol.for(${JSON.stringify(WASMCLOUD_ACTORS_GLOBAL)})] = {`, ' get actorRuntime() { return ensureActorRuntime(); },', ' dispatchActorInvocation,', ' actors: [');
281
+ for (const actor of actors) {
282
+ lines.push(` { className: ${JSON.stringify(actor.className)}, actorName: ${JSON.stringify(actor.actorName)}, namespace: ${JSON.stringify(actor.namespace)} },`);
283
+ }
284
+ lines.push(' ],', '};', '');
285
+ return lines.join('\n');
286
+ }
287
+ export function emptyActorsModule() {
288
+ return [
289
+ 'export const actorRuntime = undefined;',
290
+ 'export function getActorRuntime() { return undefined; }',
291
+ 'export const dispatchActorInvocation = undefined;',
292
+ 'export const actors = [];',
293
+ `globalThis[Symbol.for(${JSON.stringify(WASMCLOUD_ACTORS_GLOBAL)})] = { actors: [] };`,
294
+ '',
295
+ ].join('\n');
296
+ }
package/dist/args.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export type AppCommandOptions = {
2
+ name?: string;
3
+ target?: string;
4
+ yes: boolean;
5
+ };
6
+ export type PlatformCommandOptions = {
7
+ target: string;
8
+ yes: boolean;
9
+ };
10
+ export declare function parseAppCommandArgs(args: readonly string[], command: string): AppCommandOptions;
11
+ export type PlatformInitOptions = {
12
+ force: boolean;
13
+ };
14
+ export declare function parsePlatformInitArgs(args: readonly string[]): PlatformInitOptions;
15
+ export declare function parsePlatformCommandArgs(args: readonly string[], command: string): PlatformCommandOptions;
package/dist/args.js ADDED
@@ -0,0 +1,66 @@
1
+ import { invalidUsage, readOptionValue } from './support.js';
2
+ export function parseAppCommandArgs(args, command) {
3
+ let name;
4
+ let target;
5
+ let yes = false;
6
+ for (let position = 0; position < args.length; position++) {
7
+ const token = args[position] ?? '';
8
+ switch (token) {
9
+ case '--target':
10
+ if (target !== undefined)
11
+ invalidUsage(`Option may be provided only once: ${token}`, token);
12
+ target = readOptionValue(args, ++position, token);
13
+ break;
14
+ case '--yes':
15
+ if (yes)
16
+ invalidUsage(`Option may be provided only once: ${token}`, token);
17
+ yes = true;
18
+ break;
19
+ default:
20
+ if (token.startsWith('--')) {
21
+ invalidUsage(`Unknown option: ${token}`, token, { command });
22
+ }
23
+ if (name !== undefined) {
24
+ invalidUsage(`Unexpected argument: ${token}`, token, { command });
25
+ }
26
+ name = token;
27
+ }
28
+ }
29
+ return { name, target, yes };
30
+ }
31
+ export function parsePlatformInitArgs(args) {
32
+ let force = false;
33
+ for (const token of args) {
34
+ if (token === '--force' || token === '-f') {
35
+ if (force)
36
+ invalidUsage(`Option may be provided only once: ${token}`, token);
37
+ force = true;
38
+ continue;
39
+ }
40
+ invalidUsage(token.startsWith('--') ? `Unknown option: ${token}` : `Unexpected argument: ${token}`, token, { command: 'platform cluster init' });
41
+ }
42
+ return { force };
43
+ }
44
+ export function parsePlatformCommandArgs(args, command) {
45
+ let target;
46
+ let yes = false;
47
+ for (const token of args) {
48
+ if (token === '--yes') {
49
+ if (yes)
50
+ invalidUsage(`Option may be provided only once: ${token}`, token);
51
+ yes = true;
52
+ continue;
53
+ }
54
+ if (token.startsWith('--')) {
55
+ invalidUsage(`Unknown option: ${token}`, token, { command });
56
+ }
57
+ if (target !== undefined) {
58
+ invalidUsage(`Unexpected argument: ${token}`, token, { command });
59
+ }
60
+ target = token;
61
+ }
62
+ if (target === undefined) {
63
+ invalidUsage(`Missing target name for ${command}`, command, { command });
64
+ }
65
+ return { target, yes };
66
+ }