@navios/commander 1.0.0 → 1.2.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +22 -0
  3. package/dist/src/commander.factory.d.mts +59 -0
  4. package/dist/src/commander.factory.d.mts.map +1 -1
  5. package/dist/src/commands/help.command.d.mts.map +1 -1
  6. package/dist/src/decorators/command.decorator.d.mts +9 -2
  7. package/dist/src/decorators/command.decorator.d.mts.map +1 -1
  8. package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts +26 -0
  9. package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts.map +1 -0
  10. package/dist/src/legacy-compat/decorators/command.decorator.d.mts +34 -0
  11. package/dist/src/legacy-compat/decorators/command.decorator.d.mts.map +1 -0
  12. package/dist/src/legacy-compat/decorators/index.d.mts +3 -0
  13. package/dist/src/legacy-compat/decorators/index.d.mts.map +1 -0
  14. package/dist/src/legacy-compat/index.d.mts +28 -0
  15. package/dist/src/legacy-compat/index.d.mts.map +1 -0
  16. package/dist/src/overrides/help.command.d.mts +18 -0
  17. package/dist/src/overrides/help.command.d.mts.map +1 -0
  18. package/dist/src/tokens/help-command.token.d.mts +4 -0
  19. package/dist/src/tokens/help-command.token.d.mts.map +1 -0
  20. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  21. package/dist/tsconfig.tsbuildinfo +1 -1
  22. package/lib/cli-module.decorator-CkP22084.cjs +71 -0
  23. package/lib/cli-module.decorator-CkP22084.cjs.map +1 -0
  24. package/lib/cli-module.decorator-DGuGfpex.d.mts +411 -0
  25. package/lib/cli-module.decorator-DGuGfpex.d.mts.map +1 -0
  26. package/lib/cli-module.decorator-DVl8009Q.d.cts +213 -0
  27. package/lib/cli-module.decorator-DVl8009Q.d.cts.map +1 -0
  28. package/lib/cli-module.decorator-UGbtkRYc.mjs +66 -0
  29. package/lib/cli-module.decorator-UGbtkRYc.mjs.map +1 -0
  30. package/lib/command.decorator-DVLSAqYZ.mjs +135 -0
  31. package/lib/command.decorator-DVLSAqYZ.mjs.map +1 -0
  32. package/lib/command.decorator-UrNJmQN0.cjs +176 -0
  33. package/lib/command.decorator-UrNJmQN0.cjs.map +1 -0
  34. package/lib/help-command.token-C0Kgj60o.mjs +427 -0
  35. package/lib/help-command.token-C0Kgj60o.mjs.map +1 -0
  36. package/lib/help-command.token-CMWYI6em.cjs +438 -0
  37. package/lib/help-command.token-CMWYI6em.cjs.map +1 -0
  38. package/lib/help.command-DQyv6ali.cjs +317 -0
  39. package/lib/help.command-DQyv6ali.cjs.map +1 -0
  40. package/lib/help.command-dtZbhq0w.mjs +318 -0
  41. package/lib/help.command-dtZbhq0w.mjs.map +1 -0
  42. package/lib/index.cjs +45 -627
  43. package/lib/index.cjs.map +1 -1
  44. package/lib/index.d.cts +139 -281
  45. package/lib/index.d.cts.map +1 -1
  46. package/lib/index.d.mts +62 -402
  47. package/lib/index.d.mts.map +1 -1
  48. package/lib/index.mjs +30 -612
  49. package/lib/index.mjs.map +1 -1
  50. package/lib/legacy-compat/index.cjs +108 -0
  51. package/lib/legacy-compat/index.cjs.map +1 -0
  52. package/lib/legacy-compat/index.d.cts +63 -0
  53. package/lib/legacy-compat/index.d.cts.map +1 -0
  54. package/lib/legacy-compat/index.d.mts +63 -0
  55. package/lib/legacy-compat/index.d.mts.map +1 -0
  56. package/lib/legacy-compat/index.mjs +101 -0
  57. package/lib/legacy-compat/index.mjs.map +1 -0
  58. package/package.json +20 -3
  59. package/src/commander.factory.mts +107 -8
  60. package/src/commands/help.command.mts +4 -3
  61. package/src/decorators/command.decorator.mts +17 -8
  62. package/src/legacy-compat/decorators/cli-module.decorator.mts +46 -0
  63. package/src/legacy-compat/decorators/command.decorator.mts +46 -0
  64. package/src/legacy-compat/decorators/index.mts +2 -0
  65. package/src/legacy-compat/index.mts +31 -0
  66. package/src/overrides/help.command.mts +40 -0
  67. package/src/tokens/help-command.token.mts +5 -0
  68. package/tsconfig.json +0 -3
  69. package/tsconfig.spec.json +1 -1
  70. package/tsdown.config.mts +1 -1
  71. package/dist/src/commander.application.d.mts +0 -147
  72. package/dist/src/commander.application.d.mts.map +0 -1
  73. package/dist/src/metadata/cli-module.metadata.d.mts +0 -60
  74. package/dist/src/metadata/cli-module.metadata.d.mts.map +0 -1
  75. package/dist/src/services/module-loader.service.d.mts +0 -74
  76. package/dist/src/services/module-loader.service.d.mts.map +0 -1
package/lib/index.mjs CHANGED
@@ -1,558 +1,11 @@
1
- import { AdapterToken, ConsoleLogger, Container, Injectable, InjectableScope, InjectionToken, Logger, Module, NaviosFactory, extractModuleMetadata, getModuleCustomEntry, getModuleMetadata, inject } from "@navios/core";
1
+ import { a as extractCommandMetadata, i as CommandMetadataKey, n as CommandEntryKey, o as getCommandMetadata, r as extractModuleCommands, s as hasCommandMetadata, t as Command } from "./command.decorator-DVLSAqYZ.mjs";
2
+ import { n as _CommandRegistryService, t as HelpCommandToken } from "./help-command.token-C0Kgj60o.mjs";
3
+ import { t as CliModule } from "./cli-module.decorator-UGbtkRYc.mjs";
4
+ import { AdapterToken, ConsoleLogger, Container, Injectable, InjectionToken, Logger, NaviosFactory, inject } from "@navios/core";
2
5
  import { z } from "zod";
3
6
 
4
7
  export * from "@navios/core"
5
8
 
6
- //#region src/metadata/command.metadata.mts
7
- /**
8
- * @internal
9
- * Symbol key used to store command metadata on classes.
10
- */ const CommandMetadataKey = Symbol("CommandMetadataKey");
11
- /**
12
- * Gets or creates command metadata for a class.
13
- *
14
- * @internal
15
- * @param target - The command class
16
- * @param context - The decorator context
17
- * @param path - The command path
18
- * @param description - Optional description for help text
19
- * @param optionsSchema - Optional Zod schema
20
- * @returns The command metadata
21
- */ function getCommandMetadata(target, context, path, description, optionsSchema) {
22
- if (context.metadata) {
23
- const metadata = context.metadata[CommandMetadataKey];
24
- if (metadata) return metadata;
25
- else {
26
- const newMetadata = {
27
- path,
28
- description,
29
- optionsSchema,
30
- customAttributes: /* @__PURE__ */ new Map()
31
- };
32
- context.metadata[CommandMetadataKey] = newMetadata;
33
- target[CommandMetadataKey] = newMetadata;
34
- return newMetadata;
35
- }
36
- }
37
- throw new Error("[Navios Commander] Wrong environment.");
38
- }
39
- /**
40
- * Extracts command metadata from a class.
41
- *
42
- * @param target - The command class
43
- * @returns The command metadata
44
- * @throws {Error} If the class is not decorated with @Command
45
- *
46
- * @example
47
- * ```typescript
48
- * const metadata = extractCommandMetadata(GreetCommand)
49
- * console.log(metadata.path) // 'greet'
50
- * ```
51
- */ function extractCommandMetadata(target) {
52
- const metadata = target[CommandMetadataKey];
53
- if (!metadata) throw new Error("[Navios Commander] Command metadata not found. Make sure to use @Command decorator.");
54
- return metadata;
55
- }
56
- /**
57
- * Checks if a class has command metadata.
58
- *
59
- * @param target - The class to check
60
- * @returns `true` if the class is decorated with @Command, `false` otherwise
61
- */ function hasCommandMetadata(target) {
62
- return !!target[CommandMetadataKey];
63
- }
64
-
65
- //#endregion
66
- //#region src/metadata/command-entry.metadata.mts
67
- /**
68
- * Symbol key for storing commands in ModuleMetadata.customEntries.
69
- * Used by @CliModule to store command classes.
70
- *
71
- * @public
72
- */ const CommandEntryKey = Symbol("CommandEntryKey");
73
- /**
74
- * Extracts commands from a module's metadata.
75
- * Returns empty set if no commands are defined.
76
- *
77
- * @param moduleClass - The module class decorated with @CliModule or @Module
78
- * @returns Set of command classes registered in the module
79
- *
80
- * @example
81
- * ```typescript
82
- * const commands = extractModuleCommands(AppModule)
83
- * for (const command of commands) {
84
- * console.log(command.name)
85
- * }
86
- * ```
87
- */ function extractModuleCommands(moduleClass) {
88
- return extractModuleMetadata(moduleClass).customEntries.get(CommandEntryKey) ?? /* @__PURE__ */ new Set();
89
- }
90
-
91
- //#endregion
92
- //#region src/decorators/command.decorator.mts
93
- /**
94
- * Decorator that marks a class as a CLI command.
95
- *
96
- * The decorated class must implement the `CommandHandler` interface with an `execute` method.
97
- * The command will be automatically registered when its module is loaded.
98
- *
99
- * @param options - Configuration options for the command
100
- * @returns A class decorator function
101
- *
102
- * @example
103
- * ```typescript
104
- * import { Command, CommandHandler } from '@navios/commander'
105
- * import { z } from 'zod'
106
- *
107
- * const optionsSchema = z.object({
108
- * name: z.string(),
109
- * greeting: z.string().optional().default('Hello')
110
- * })
111
- *
112
- * @Command({
113
- * path: 'greet',
114
- * optionsSchema: optionsSchema
115
- * })
116
- * export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
117
- * async execute(options) {
118
- * console.log(`${options.greeting}, ${options.name}!`)
119
- * }
120
- * }
121
- * ```
122
- */ function Command({ path, description, optionsSchema, priority, registry }) {
123
- return function(target, context) {
124
- if (context.kind !== "class") throw new Error("[Navios Commander] @Command decorator can only be used on classes.");
125
- const token = InjectionToken.create(target);
126
- if (context.metadata) getCommandMetadata(target, context, path, description, optionsSchema);
127
- return Injectable({
128
- token,
129
- scope: InjectableScope.Singleton,
130
- priority,
131
- registry
132
- })(target, context);
133
- };
134
- }
135
-
136
- //#endregion
137
- //#region src/services/command-registry.service.mts
138
- function applyDecs2203RFactory$3() {
139
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
140
- return function addInitializer(initializer) {
141
- assertNotFinished(decoratorFinishedRef, "addInitializer");
142
- assertCallable(initializer, "An initializer");
143
- initializers.push(initializer);
144
- };
145
- }
146
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
147
- var kindStr;
148
- switch (kind) {
149
- case 1:
150
- kindStr = "accessor";
151
- break;
152
- case 2:
153
- kindStr = "method";
154
- break;
155
- case 3:
156
- kindStr = "getter";
157
- break;
158
- case 4:
159
- kindStr = "setter";
160
- break;
161
- default: kindStr = "field";
162
- }
163
- var ctx = {
164
- kind: kindStr,
165
- name: isPrivate ? "#" + name : name,
166
- static: isStatic,
167
- private: isPrivate,
168
- metadata
169
- };
170
- var decoratorFinishedRef = { v: false };
171
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
172
- var get, set;
173
- if (kind === 0) if (isPrivate) {
174
- get = desc.get;
175
- set = desc.set;
176
- } else {
177
- get = function() {
178
- return this[name];
179
- };
180
- set = function(v) {
181
- this[name] = v;
182
- };
183
- }
184
- else if (kind === 2) get = function() {
185
- return desc.value;
186
- };
187
- else {
188
- if (kind === 1 || kind === 3) get = function() {
189
- return desc.get.call(this);
190
- };
191
- if (kind === 1 || kind === 4) set = function(v) {
192
- desc.set.call(this, v);
193
- };
194
- }
195
- ctx.access = get && set ? {
196
- get,
197
- set
198
- } : get ? { get } : { set };
199
- try {
200
- return dec(value, ctx);
201
- } finally {
202
- decoratorFinishedRef.v = true;
203
- }
204
- }
205
- function assertNotFinished(decoratorFinishedRef, fnName) {
206
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
207
- }
208
- function assertCallable(fn, hint) {
209
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
210
- }
211
- function assertValidReturnValue(kind, value) {
212
- var type = typeof value;
213
- if (kind === 1) {
214
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
215
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
216
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
217
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
218
- } else if (type !== "function") {
219
- var hint;
220
- if (kind === 0) hint = "field";
221
- else if (kind === 10) hint = "class";
222
- else hint = "method";
223
- throw new TypeError(hint + " decorators must return a function or void 0");
224
- }
225
- }
226
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
227
- var decs = decInfo[0];
228
- var desc, init, value;
229
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
230
- get: decInfo[3],
231
- set: decInfo[4]
232
- };
233
- else if (kind === 3) desc = { get: decInfo[3] };
234
- else if (kind === 4) desc = { set: decInfo[3] };
235
- else desc = { value: decInfo[3] };
236
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
237
- if (kind === 1) value = {
238
- get: desc.get,
239
- set: desc.set
240
- };
241
- else if (kind === 2) value = desc.value;
242
- else if (kind === 3) value = desc.get;
243
- else if (kind === 4) value = desc.set;
244
- var newValue, get, set;
245
- if (typeof decs === "function") {
246
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
247
- if (newValue !== void 0) {
248
- assertValidReturnValue(kind, newValue);
249
- if (kind === 0) init = newValue;
250
- else if (kind === 1) {
251
- init = newValue.init;
252
- get = newValue.get || value.get;
253
- set = newValue.set || value.set;
254
- value = {
255
- get,
256
- set
257
- };
258
- } else value = newValue;
259
- }
260
- } else for (var i = decs.length - 1; i >= 0; i--) {
261
- var dec = decs[i];
262
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
263
- if (newValue !== void 0) {
264
- assertValidReturnValue(kind, newValue);
265
- var newInit;
266
- if (kind === 0) newInit = newValue;
267
- else if (kind === 1) {
268
- newInit = newValue.init;
269
- get = newValue.get || value.get;
270
- set = newValue.set || value.set;
271
- value = {
272
- get,
273
- set
274
- };
275
- } else value = newValue;
276
- if (newInit !== void 0) if (init === void 0) init = newInit;
277
- else if (typeof init === "function") init = [init, newInit];
278
- else init.push(newInit);
279
- }
280
- }
281
- if (kind === 0 || kind === 1) {
282
- if (init === void 0) init = function(instance, init$1) {
283
- return init$1;
284
- };
285
- else if (typeof init !== "function") {
286
- var ownInitializers = init;
287
- init = function(instance, init$1) {
288
- var value$1 = init$1;
289
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
290
- return value$1;
291
- };
292
- } else {
293
- var originalInitializer = init;
294
- init = function(instance, init$1) {
295
- return originalInitializer.call(instance, init$1);
296
- };
297
- }
298
- ret.push(init);
299
- }
300
- if (kind !== 0) {
301
- if (kind === 1) {
302
- desc.get = value.get;
303
- desc.set = value.set;
304
- } else if (kind === 2) desc.value = value;
305
- else if (kind === 3) desc.get = value;
306
- else if (kind === 4) desc.set = value;
307
- if (isPrivate) if (kind === 1) {
308
- ret.push(function(instance, args) {
309
- return value.get.call(instance, args);
310
- });
311
- ret.push(function(instance, args) {
312
- return value.set.call(instance, args);
313
- });
314
- } else if (kind === 2) ret.push(value);
315
- else ret.push(function(instance, args) {
316
- return value.call(instance, args);
317
- });
318
- else Object.defineProperty(base, name, desc);
319
- }
320
- }
321
- function applyMemberDecs(Class, decInfos, metadata) {
322
- var ret = [];
323
- var protoInitializers;
324
- var staticInitializers;
325
- var existingProtoNonFields = /* @__PURE__ */ new Map();
326
- var existingStaticNonFields = /* @__PURE__ */ new Map();
327
- for (var i = 0; i < decInfos.length; i++) {
328
- var decInfo = decInfos[i];
329
- if (!Array.isArray(decInfo)) continue;
330
- var kind = decInfo[1];
331
- var name = decInfo[2];
332
- var isPrivate = decInfo.length > 3;
333
- var isStatic = kind >= 5;
334
- var base;
335
- var initializers;
336
- if (isStatic) {
337
- base = Class;
338
- kind = kind - 5;
339
- staticInitializers = staticInitializers || [];
340
- initializers = staticInitializers;
341
- } else {
342
- base = Class.prototype;
343
- protoInitializers = protoInitializers || [];
344
- initializers = protoInitializers;
345
- }
346
- if (kind !== 0 && !isPrivate) {
347
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
348
- var existingKind = existingNonFields.get(name) || 0;
349
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
350
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
351
- else existingNonFields.set(name, true);
352
- }
353
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
354
- }
355
- pushInitializers(ret, protoInitializers);
356
- pushInitializers(ret, staticInitializers);
357
- return ret;
358
- }
359
- function pushInitializers(ret, initializers) {
360
- if (initializers) ret.push(function(instance) {
361
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
362
- return instance;
363
- });
364
- }
365
- function applyClassDecs(targetClass, classDecs, metadata) {
366
- if (classDecs.length > 0) {
367
- var initializers = [];
368
- var newClass = targetClass;
369
- var name = targetClass.name;
370
- for (var i = classDecs.length - 1; i >= 0; i--) {
371
- var decoratorFinishedRef = { v: false };
372
- try {
373
- var nextNewClass = classDecs[i](newClass, {
374
- kind: "class",
375
- name,
376
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
377
- metadata
378
- });
379
- } finally {
380
- decoratorFinishedRef.v = true;
381
- }
382
- if (nextNewClass !== void 0) {
383
- assertValidReturnValue(10, nextNewClass);
384
- newClass = nextNewClass;
385
- }
386
- }
387
- return [defineMetadata(newClass, metadata), function() {
388
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
389
- }];
390
- }
391
- }
392
- function defineMetadata(Class, metadata) {
393
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
394
- configurable: true,
395
- enumerable: true,
396
- value: metadata
397
- });
398
- }
399
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
400
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
401
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
402
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
403
- if (!classDecs.length) defineMetadata(targetClass, metadata);
404
- return {
405
- e,
406
- get c() {
407
- return applyClassDecs(targetClass, classDecs, metadata);
408
- }
409
- };
410
- };
411
- }
412
- function _apply_decs_2203_r$3(targetClass, memberDecs, classDecs, parentClass) {
413
- return (_apply_decs_2203_r$3 = applyDecs2203RFactory$3())(targetClass, memberDecs, classDecs, parentClass);
414
- }
415
- var _dec$3, _initClass$3;
416
- let _CommandRegistryService;
417
- _dec$3 = Injectable();
418
- var CommandRegistryService = class {
419
- static {
420
- ({c: [_CommandRegistryService, _initClass$3]} = _apply_decs_2203_r$3(this, [], [_dec$3]));
421
- }
422
- commands = /* @__PURE__ */ new Map();
423
- /**
424
- * Register a command with its metadata.
425
- *
426
- * @param path - The command path (e.g., 'greet', 'user:create')
427
- * @param command - The registered command data
428
- * @throws Error if a command with the same path is already registered
429
- */ register(path, command) {
430
- if (this.commands.has(path)) throw new Error(`[Navios Commander] Duplicate command path: ${path}`);
431
- this.commands.set(path, command);
432
- }
433
- /**
434
- * Get a command by its path.
435
- *
436
- * @param path - The command path
437
- * @returns The registered command or undefined if not found
438
- */ getByPath(path) {
439
- return this.commands.get(path);
440
- }
441
- /**
442
- * Get all registered commands.
443
- *
444
- * @returns Map of path to registered command
445
- */ getAll() {
446
- return new Map(this.commands);
447
- }
448
- /**
449
- * Get all registered commands as an array of path and class pairs.
450
- * Useful for listing available commands.
451
- *
452
- * @returns Array of objects containing path and class
453
- */ getAllAsArray() {
454
- const result = [];
455
- for (const [path, { class: cls }] of this.commands) result.push({
456
- path,
457
- class: cls
458
- });
459
- return result;
460
- }
461
- /**
462
- * Formats help text listing all available commands with descriptions.
463
- *
464
- * @returns Formatted string listing all commands
465
- */ formatCommandList() {
466
- const lines = ["Available commands:", ""];
467
- for (const [path, { metadata }] of this.commands) {
468
- const description = metadata.description;
469
- if (description) lines.push(` ${path.padEnd(20)} ${description}`);
470
- else lines.push(` ${path}`);
471
- }
472
- return lines.join("\n");
473
- }
474
- /**
475
- * Formats help text for a specific command.
476
- *
477
- * @param commandPath - The command path to show help for
478
- * @returns Formatted string with command help
479
- */ formatCommandHelp(commandPath) {
480
- const command = this.commands.get(commandPath);
481
- if (!command) return `Unknown command: ${commandPath}\n\n${this.formatCommandList()}`;
482
- const { metadata } = command;
483
- const lines = [];
484
- lines.push(`Usage: ${metadata.path} [options]`);
485
- lines.push("");
486
- if (metadata.description) {
487
- lines.push(metadata.description);
488
- lines.push("");
489
- }
490
- if (metadata.optionsSchema) {
491
- lines.push("Options:");
492
- try {
493
- const shape = metadata.optionsSchema.def.shape;
494
- if (shape && typeof shape === "object") for (const [key, fieldSchema] of Object.entries(shape)) {
495
- const optionFlag = `--${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
496
- const fieldType = this.getSchemaTypeName(fieldSchema);
497
- lines.push(` ${optionFlag.padEnd(20)} ${fieldType}`);
498
- }
499
- } catch {}
500
- }
501
- return lines.join("\n");
502
- }
503
- /**
504
- * Gets a human-readable type name from a Zod schema.
505
- */ getSchemaTypeName(schema) {
506
- try {
507
- let currentSchema = schema;
508
- let typeName = currentSchema?.def?.type;
509
- let isOptional = false;
510
- let defaultValue;
511
- while (typeName === "optional" || typeName === "default") {
512
- if (typeName === "optional") isOptional = true;
513
- if (typeName === "default") {
514
- isOptional = true;
515
- defaultValue = currentSchema?.def?.defaultValue?.();
516
- }
517
- currentSchema = currentSchema?.def?.innerType;
518
- typeName = currentSchema?.def?.type;
519
- }
520
- let result = `<${typeName || "unknown"}>`;
521
- if (defaultValue !== void 0) result += ` (default: ${JSON.stringify(defaultValue)})`;
522
- else if (isOptional) result += " (optional)";
523
- const description = this.getSchemaMeta(schema)?.description;
524
- if (description) result += ` - ${description}`;
525
- return result;
526
- } catch {
527
- return "<unknown>";
528
- }
529
- }
530
- /**
531
- * Gets metadata from a Zod schema, traversing innerType if needed.
532
- * Zod v4 stores meta at the outermost layer when .meta() is called last,
533
- * or in innerType when .meta() is called before .optional()/.default().
534
- */ getSchemaMeta(schema) {
535
- try {
536
- const directMeta = schema.meta?.();
537
- if (directMeta) return directMeta;
538
- const innerType = schema.def?.innerType;
539
- if (innerType) return this.getSchemaMeta(innerType);
540
- return;
541
- } catch {
542
- return;
543
- }
544
- }
545
- /**
546
- * Clear all registered commands.
547
- */ clear() {
548
- this.commands.clear();
549
- }
550
- static {
551
- _initClass$3();
552
- }
553
- };
554
-
555
- //#endregion
556
9
  //#region src/commands/help.command.mts
557
10
  function applyDecs2203RFactory$2() {
558
11
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
@@ -835,6 +288,7 @@ var _dec$2, _initClass$2;
835
288
  const helpOptionsSchema = z.object({ command: z.string().optional() });
836
289
  let _HelpCommand;
837
290
  _dec$2 = Command({
291
+ token: HelpCommandToken,
838
292
  path: "help",
839
293
  description: "Show available commands or help for a specific command",
840
294
  optionsSchema: helpOptionsSchema
@@ -1883,6 +1337,31 @@ var CommanderAdapterService = class {
1883
1337
  * await adapter.run(process.argv)
1884
1338
  * ```
1885
1339
  */ static async create(appModule, options = {}) {
1340
+ if (options.enableTUI) {
1341
+ let tuiModule;
1342
+ try {
1343
+ tuiModule = await import("@navios/commander-tui");
1344
+ } catch {
1345
+ throw new Error("TUI mode requires @navios/commander-tui package. Install it with: npm install @navios/commander-tui");
1346
+ }
1347
+ const { overrideConsoleLogger, ScreenManager } = tuiModule;
1348
+ overrideConsoleLogger(options.tuiOptions?.hideDefaultScreen ?? false);
1349
+ if (options.tuiOptions?.hideDefaultScreen) await import("./help.command-dtZbhq0w.mjs");
1350
+ const app = await NaviosFactory.create(appModule, {
1351
+ adapter: defineCliEnvironment(),
1352
+ logger: options.logLevels
1353
+ });
1354
+ await (await app.get(ScreenManager)).bind({
1355
+ exitOnCtrlC: options.tuiOptions?.exitOnCtrlC,
1356
+ sidebarWidth: options.tuiOptions?.sidebarWidth,
1357
+ sidebarPosition: options.tuiOptions?.sidebarPosition,
1358
+ sidebarTitle: options.tuiOptions?.sidebarTitle,
1359
+ autoClose: options.tuiOptions?.autoClose,
1360
+ theme: options.tuiOptions?.theme,
1361
+ useMouse: options.tuiOptions?.useMouse
1362
+ });
1363
+ return app;
1364
+ }
1886
1365
  return await NaviosFactory.create(appModule, {
1887
1366
  adapter: defineCliEnvironment(),
1888
1367
  logger: ConsoleLogger.create({
@@ -1898,67 +1377,6 @@ var CommanderAdapterService = class {
1898
1377
  }
1899
1378
  };
1900
1379
 
1901
- //#endregion
1902
- //#region src/decorators/cli-module.decorator.mts
1903
- /**
1904
- * Decorator that marks a class as a CLI module.
1905
- *
1906
- * This decorator extends the standard @Module decorator, adding support for
1907
- * CLI commands while maintaining full compatibility with HTTP controllers.
1908
- * Modules organize commands and can import other modules to compose larger
1909
- * CLI applications.
1910
- *
1911
- * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
1912
- *
1913
- * @param options - Configuration options for the module
1914
- * @returns A class decorator function
1915
- *
1916
- * @example
1917
- * ```typescript
1918
- * import { CliModule } from '@navios/commander'
1919
- * import { GreetCommand } from './greet.command'
1920
- * import { UserModule } from './user.module'
1921
- *
1922
- * @CliModule({
1923
- * commands: [GreetCommand],
1924
- * imports: [UserModule]
1925
- * })
1926
- * export class AppModule {}
1927
- * ```
1928
- *
1929
- * @example
1930
- * ```typescript
1931
- * // Mixed HTTP and CLI module
1932
- * @CliModule({
1933
- * controllers: [HealthController],
1934
- * commands: [MigrateCommand],
1935
- * imports: [DatabaseModule],
1936
- * })
1937
- * export class AppModule {}
1938
- * ```
1939
- */ function CliModule({ commands = [], controllers = [], imports = [], guards = [], overrides = [], priority, registry } = {
1940
- commands: [],
1941
- controllers: [],
1942
- imports: [],
1943
- guards: [],
1944
- overrides: []
1945
- }) {
1946
- return (target, context) => {
1947
- if (context.kind !== "class") throw new Error("[Navios Commander] @CliModule decorator can only be used on classes.");
1948
- const result = Module({
1949
- controllers,
1950
- imports,
1951
- guards,
1952
- overrides,
1953
- priority,
1954
- registry
1955
- })(target, context);
1956
- const commandSet = getModuleCustomEntry(getModuleMetadata(target, context), CommandEntryKey, () => /* @__PURE__ */ new Set());
1957
- for (const command of commands) commandSet.add(command);
1958
- return result;
1959
- };
1960
- }
1961
-
1962
1380
  //#endregion
1963
1381
  export { CliModule, _CliParserService as CliParserService, Command, CommandEntryKey, CommandExecutionContext, CommandMetadataKey, _CommandRegistryService as CommandRegistryService, _CommanderAdapterService as CommanderAdapterService, CommanderExecutionContext, CommanderFactory, _HelpCommand as HelpCommand, defineCliEnvironment, extractCommandMetadata, extractModuleCommands, getCommandMetadata, hasCommandMetadata };
1964
1382
  //# sourceMappingURL=index.mjs.map