@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.
- package/CHANGELOG.md +35 -0
- package/README.md +22 -0
- package/dist/src/commander.factory.d.mts +59 -0
- package/dist/src/commander.factory.d.mts.map +1 -1
- package/dist/src/commands/help.command.d.mts.map +1 -1
- package/dist/src/decorators/command.decorator.d.mts +9 -2
- package/dist/src/decorators/command.decorator.d.mts.map +1 -1
- package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts +26 -0
- package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts.map +1 -0
- package/dist/src/legacy-compat/decorators/command.decorator.d.mts +34 -0
- package/dist/src/legacy-compat/decorators/command.decorator.d.mts.map +1 -0
- package/dist/src/legacy-compat/decorators/index.d.mts +3 -0
- package/dist/src/legacy-compat/decorators/index.d.mts.map +1 -0
- package/dist/src/legacy-compat/index.d.mts +28 -0
- package/dist/src/legacy-compat/index.d.mts.map +1 -0
- package/dist/src/overrides/help.command.d.mts +18 -0
- package/dist/src/overrides/help.command.d.mts.map +1 -0
- package/dist/src/tokens/help-command.token.d.mts +4 -0
- package/dist/src/tokens/help-command.token.d.mts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/cli-module.decorator-CkP22084.cjs +71 -0
- package/lib/cli-module.decorator-CkP22084.cjs.map +1 -0
- package/lib/cli-module.decorator-DGuGfpex.d.mts +411 -0
- package/lib/cli-module.decorator-DGuGfpex.d.mts.map +1 -0
- package/lib/cli-module.decorator-DVl8009Q.d.cts +213 -0
- package/lib/cli-module.decorator-DVl8009Q.d.cts.map +1 -0
- package/lib/cli-module.decorator-UGbtkRYc.mjs +66 -0
- package/lib/cli-module.decorator-UGbtkRYc.mjs.map +1 -0
- package/lib/command.decorator-DVLSAqYZ.mjs +135 -0
- package/lib/command.decorator-DVLSAqYZ.mjs.map +1 -0
- package/lib/command.decorator-UrNJmQN0.cjs +176 -0
- package/lib/command.decorator-UrNJmQN0.cjs.map +1 -0
- package/lib/help-command.token-C0Kgj60o.mjs +427 -0
- package/lib/help-command.token-C0Kgj60o.mjs.map +1 -0
- package/lib/help-command.token-CMWYI6em.cjs +438 -0
- package/lib/help-command.token-CMWYI6em.cjs.map +1 -0
- package/lib/help.command-DQyv6ali.cjs +317 -0
- package/lib/help.command-DQyv6ali.cjs.map +1 -0
- package/lib/help.command-dtZbhq0w.mjs +318 -0
- package/lib/help.command-dtZbhq0w.mjs.map +1 -0
- package/lib/index.cjs +45 -627
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +139 -281
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +62 -402
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +30 -612
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +108 -0
- package/lib/legacy-compat/index.cjs.map +1 -0
- package/lib/legacy-compat/index.d.cts +63 -0
- package/lib/legacy-compat/index.d.cts.map +1 -0
- package/lib/legacy-compat/index.d.mts +63 -0
- package/lib/legacy-compat/index.d.mts.map +1 -0
- package/lib/legacy-compat/index.mjs +101 -0
- package/lib/legacy-compat/index.mjs.map +1 -0
- package/package.json +20 -3
- package/src/commander.factory.mts +107 -8
- package/src/commands/help.command.mts +4 -3
- package/src/decorators/command.decorator.mts +17 -8
- package/src/legacy-compat/decorators/cli-module.decorator.mts +46 -0
- package/src/legacy-compat/decorators/command.decorator.mts +46 -0
- package/src/legacy-compat/decorators/index.mts +2 -0
- package/src/legacy-compat/index.mts +31 -0
- package/src/overrides/help.command.mts +40 -0
- package/src/tokens/help-command.token.mts +5 -0
- package/tsconfig.json +0 -3
- package/tsconfig.spec.json +1 -1
- package/tsdown.config.mts +1 -1
- package/dist/src/commander.application.d.mts +0 -147
- package/dist/src/commander.application.d.mts.map +0 -1
- package/dist/src/metadata/cli-module.metadata.d.mts +0 -60
- package/dist/src/metadata/cli-module.metadata.d.mts.map +0 -1
- package/dist/src/services/module-loader.service.d.mts +0 -74
- package/dist/src/services/module-loader.service.d.mts.map +0 -1
package/lib/index.d.cts
CHANGED
|
@@ -1,46 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as CommandHandler, i as CommandOptions, n as CliModuleOptions, r as Command, t as CliModule } from "./cli-module.decorator-DVl8009Q.cjs";
|
|
2
|
+
import { AbstractAdapterInterface, AdapterEnvironment, AnyInjectableType, ClassType, ClassTypeWithInstance, InjectionToken, LogLevel, ModuleMetadata, NaviosApplication, NaviosModule } from "@navios/core";
|
|
2
3
|
import { ZodObject, z } from "zod";
|
|
3
4
|
export * from "@navios/core";
|
|
4
5
|
|
|
5
|
-
//#region src/interfaces/command-handler.interface.d.mts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Interface that all command classes must implement.
|
|
9
|
-
*
|
|
10
|
-
* Commands decorated with `@Command` must implement this interface.
|
|
11
|
-
* The `execute` method is called when the command is invoked.
|
|
12
|
-
*
|
|
13
|
-
* @template TOptions - The type of options that the command accepts
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* import { Command, CommandHandler } from '@navios/commander'
|
|
18
|
-
* import { z } from 'zod'
|
|
19
|
-
*
|
|
20
|
-
* const optionsSchema = z.object({
|
|
21
|
-
* name: z.string()
|
|
22
|
-
* })
|
|
23
|
-
*
|
|
24
|
-
* type Options = z.infer<typeof optionsSchema>
|
|
25
|
-
*
|
|
26
|
-
* @Command({ path: 'greet', optionsSchema })
|
|
27
|
-
* export class GreetCommand implements CommandHandler<Options> {
|
|
28
|
-
* async execute(options: Options) {
|
|
29
|
-
* console.log(`Hello, ${options.name}!`)
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
interface CommandHandler<TOptions = any> {
|
|
35
|
-
/**
|
|
36
|
-
* Executes the command with the provided options.
|
|
37
|
-
*
|
|
38
|
-
* @param options - The validated command options (validated against the command's schema if provided)
|
|
39
|
-
* @returns A promise or void
|
|
40
|
-
*/
|
|
41
|
-
execute(options: TOptions): void | Promise<void>;
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
6
|
//#region src/commands/help.command.d.mts
|
|
45
7
|
declare const helpOptionsSchema: z.ZodObject<{
|
|
46
8
|
command: z.ZodOptional<z.ZodString>;
|
|
@@ -182,16 +144,75 @@ interface CommanderLoggerOptions {
|
|
|
182
144
|
*/
|
|
183
145
|
showTimeDiff?: boolean;
|
|
184
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* TUI-specific options for terminal UI mode.
|
|
149
|
+
* Only used when enableTUI is true.
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
interface CommanderTuiOptions {
|
|
154
|
+
/**
|
|
155
|
+
* Exit on Ctrl+C.
|
|
156
|
+
* @default true
|
|
157
|
+
*/
|
|
158
|
+
exitOnCtrlC?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Sidebar width in columns.
|
|
161
|
+
*/
|
|
162
|
+
sidebarWidth?: number;
|
|
163
|
+
/**
|
|
164
|
+
* Sidebar position.
|
|
165
|
+
*/
|
|
166
|
+
sidebarPosition?: 'left' | 'right';
|
|
167
|
+
/**
|
|
168
|
+
* Sidebar header title.
|
|
169
|
+
*/
|
|
170
|
+
sidebarTitle?: string;
|
|
171
|
+
/**
|
|
172
|
+
* Auto close after all screens complete successfully.
|
|
173
|
+
* Set to true for default delay (5000ms), or specify delay in milliseconds.
|
|
174
|
+
*/
|
|
175
|
+
autoClose?: boolean | number;
|
|
176
|
+
/**
|
|
177
|
+
* Theme preset name ('dark', 'light', 'high-contrast') or custom theme object.
|
|
178
|
+
*/
|
|
179
|
+
theme?: string | Record<string, unknown>;
|
|
180
|
+
/**
|
|
181
|
+
* Enable mouse support.
|
|
182
|
+
* @default false
|
|
183
|
+
*/
|
|
184
|
+
useMouse?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Hide the default console logger screen from the sidebar.
|
|
187
|
+
* @default false
|
|
188
|
+
*/
|
|
189
|
+
hideDefaultScreen?: boolean;
|
|
190
|
+
}
|
|
185
191
|
/**
|
|
186
192
|
* Configuration options for CommanderFactory.
|
|
187
193
|
*
|
|
188
194
|
* @public
|
|
189
195
|
*/
|
|
190
196
|
interface CommanderFactoryOptions {
|
|
197
|
+
/**
|
|
198
|
+
* Enabled log levels.
|
|
199
|
+
* @default ['log', 'error', 'warn', 'debug', 'verbose', 'fatal']
|
|
200
|
+
*/
|
|
201
|
+
logLevels?: LogLevel[];
|
|
191
202
|
/**
|
|
192
203
|
* Logger display options. These override the default CLI-friendly logger settings.
|
|
204
|
+
* Ignored when enableTUI is true.
|
|
193
205
|
*/
|
|
194
206
|
logger?: CommanderLoggerOptions;
|
|
207
|
+
/**
|
|
208
|
+
* Enable TUI mode with @navios/commander-tui.
|
|
209
|
+
* Requires @navios/commander-tui to be installed.
|
|
210
|
+
*/
|
|
211
|
+
enableTUI?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* TUI-specific options. Only used when enableTUI is true.
|
|
214
|
+
*/
|
|
215
|
+
tuiOptions?: CommanderTuiOptions;
|
|
195
216
|
}
|
|
196
217
|
/**
|
|
197
218
|
* Factory class for creating CLI applications.
|
|
@@ -247,168 +268,122 @@ declare class CommanderFactory {
|
|
|
247
268
|
static create<TModule extends NaviosModule = NaviosModule>(appModule: ClassTypeWithInstance<TModule>, options?: CommanderFactoryOptions): Promise<NaviosApplication<CliEnvironment>>;
|
|
248
269
|
}
|
|
249
270
|
//#endregion
|
|
250
|
-
//#region src/
|
|
271
|
+
//#region src/metadata/command.metadata.d.mts
|
|
251
272
|
/**
|
|
252
|
-
*
|
|
273
|
+
* @internal
|
|
274
|
+
* Symbol key used to store command metadata on classes.
|
|
275
|
+
*/
|
|
276
|
+
declare const CommandMetadataKey: unique symbol;
|
|
277
|
+
/**
|
|
278
|
+
* Metadata associated with a command.
|
|
253
279
|
*
|
|
254
280
|
* @public
|
|
255
281
|
*/
|
|
256
|
-
interface
|
|
282
|
+
interface CommandMetadata {
|
|
257
283
|
/**
|
|
258
|
-
* The command path
|
|
259
|
-
* Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').
|
|
284
|
+
* The command path (e.g., 'greet', 'user:create').
|
|
260
285
|
*/
|
|
261
286
|
path: string;
|
|
262
287
|
/**
|
|
263
288
|
* Optional description of the command for help text.
|
|
264
|
-
* Displayed when users run `help` or `--help`.
|
|
265
289
|
*/
|
|
266
290
|
description?: string;
|
|
267
291
|
/**
|
|
268
292
|
* Optional Zod schema for validating command options.
|
|
269
|
-
* If provided, options will be validated and parsed according to this schema.
|
|
270
293
|
*/
|
|
271
294
|
optionsSchema?: ZodObject;
|
|
272
295
|
/**
|
|
273
|
-
*
|
|
274
|
-
* Higher priority commands will be loaded first.
|
|
275
|
-
*/
|
|
276
|
-
priority?: number;
|
|
277
|
-
/**
|
|
278
|
-
* Registry to use for the command.
|
|
279
|
-
* Registry is used to store the command and its options schema.
|
|
296
|
+
* Map of custom attributes that can be attached to the command.
|
|
280
297
|
*/
|
|
281
|
-
|
|
298
|
+
customAttributes: Map<string | symbol, any>;
|
|
282
299
|
}
|
|
283
300
|
/**
|
|
284
|
-
*
|
|
301
|
+
* Gets or creates command metadata for a class.
|
|
285
302
|
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
303
|
+
* @internal
|
|
304
|
+
* @param target - The command class
|
|
305
|
+
* @param context - The decorator context
|
|
306
|
+
* @param path - The command path
|
|
307
|
+
* @param description - Optional description for help text
|
|
308
|
+
* @param optionsSchema - Optional Zod schema
|
|
309
|
+
* @returns The command metadata
|
|
310
|
+
*/
|
|
311
|
+
declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, description?: string, optionsSchema?: ZodObject): CommandMetadata;
|
|
312
|
+
/**
|
|
313
|
+
* Extracts command metadata from a class.
|
|
288
314
|
*
|
|
289
|
-
* @param
|
|
290
|
-
* @returns
|
|
315
|
+
* @param target - The command class
|
|
316
|
+
* @returns The command metadata
|
|
317
|
+
* @throws {Error} If the class is not decorated with @Command
|
|
291
318
|
*
|
|
292
319
|
* @example
|
|
293
320
|
* ```typescript
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* const optionsSchema = z.object({
|
|
298
|
-
* name: z.string(),
|
|
299
|
-
* greeting: z.string().optional().default('Hello')
|
|
300
|
-
* })
|
|
301
|
-
*
|
|
302
|
-
* @Command({
|
|
303
|
-
* path: 'greet',
|
|
304
|
-
* optionsSchema: optionsSchema
|
|
305
|
-
* })
|
|
306
|
-
* export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
307
|
-
* async execute(options) {
|
|
308
|
-
* console.log(`${options.greeting}, ${options.name}!`)
|
|
309
|
-
* }
|
|
310
|
-
* }
|
|
321
|
+
* const metadata = extractCommandMetadata(GreetCommand)
|
|
322
|
+
* console.log(metadata.path) // 'greet'
|
|
311
323
|
* ```
|
|
312
324
|
*/
|
|
313
|
-
declare function
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
325
|
+
declare function extractCommandMetadata(target: ClassType): CommandMetadata;
|
|
326
|
+
/**
|
|
327
|
+
* Checks if a class has command metadata.
|
|
328
|
+
*
|
|
329
|
+
* @param target - The class to check
|
|
330
|
+
* @returns `true` if the class is decorated with @Command, `false` otherwise
|
|
331
|
+
*/
|
|
332
|
+
declare function hasCommandMetadata(target: ClassType): boolean;
|
|
320
333
|
//#endregion
|
|
321
|
-
//#region src/
|
|
334
|
+
//#region src/interfaces/commander-execution-context.interface.d.mts
|
|
322
335
|
/**
|
|
323
|
-
*
|
|
336
|
+
* Execution context for a command execution.
|
|
324
337
|
*
|
|
325
|
-
*
|
|
338
|
+
* Provides access to command metadata, path, and validated options during command execution.
|
|
339
|
+
* This context is automatically injected and available via the `CommandExecutionContext` token.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* import { inject, Injectable } from '@navios/core'
|
|
344
|
+
* import { CommandExecutionContext } from '@navios/commander'
|
|
345
|
+
*
|
|
346
|
+
* @Injectable()
|
|
347
|
+
* class CommandLogger {
|
|
348
|
+
* private ctx = inject(CommandExecutionContext)
|
|
349
|
+
*
|
|
350
|
+
* log() {
|
|
351
|
+
* console.log('Command:', this.ctx.getCommandPath())
|
|
352
|
+
* console.log('Options:', this.ctx.getOptions())
|
|
353
|
+
* }
|
|
354
|
+
* }
|
|
355
|
+
* ```
|
|
326
356
|
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
*/
|
|
332
|
-
commands?: ClassType[] | Set<ClassType>;
|
|
333
|
-
/**
|
|
334
|
-
* Array or Set of controller classes for HTTP endpoints.
|
|
335
|
-
* Allows mixing HTTP and CLI functionality in the same module.
|
|
336
|
-
*/
|
|
337
|
-
controllers?: ClassType[] | Set<ClassType>;
|
|
338
|
-
/**
|
|
339
|
-
* Array or Set of other modules to import.
|
|
340
|
-
* Imported modules' commands and controllers will be available.
|
|
341
|
-
*/
|
|
342
|
-
imports?: ClassType[] | Set<ClassType>;
|
|
357
|
+
declare class CommanderExecutionContext {
|
|
358
|
+
private readonly command;
|
|
359
|
+
private readonly commandPath;
|
|
360
|
+
private readonly options;
|
|
343
361
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
362
|
+
* @internal
|
|
363
|
+
* Creates a new execution context.
|
|
346
364
|
*/
|
|
347
|
-
|
|
365
|
+
constructor(command: CommandMetadata, commandPath: string, options: any);
|
|
348
366
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* InjectionToken as the original service with a higher priority.
|
|
367
|
+
* Gets the command metadata.
|
|
368
|
+
*
|
|
369
|
+
* @returns The command metadata including path and options schema
|
|
353
370
|
*/
|
|
354
|
-
|
|
371
|
+
getCommand(): CommandMetadata;
|
|
355
372
|
/**
|
|
356
|
-
*
|
|
357
|
-
*
|
|
373
|
+
* Gets the command path that was invoked.
|
|
374
|
+
*
|
|
375
|
+
* @returns The command path (e.g., 'greet', 'user:create')
|
|
358
376
|
*/
|
|
359
|
-
|
|
377
|
+
getCommandPath(): string;
|
|
360
378
|
/**
|
|
361
|
-
*
|
|
362
|
-
*
|
|
379
|
+
* Gets the validated command options.
|
|
380
|
+
*
|
|
381
|
+
* Options are validated against the command's Zod schema if one was provided.
|
|
382
|
+
*
|
|
383
|
+
* @returns The validated options object
|
|
363
384
|
*/
|
|
364
|
-
|
|
385
|
+
getOptions(): any;
|
|
365
386
|
}
|
|
366
|
-
/**
|
|
367
|
-
* Decorator that marks a class as a CLI module.
|
|
368
|
-
*
|
|
369
|
-
* This decorator extends the standard @Module decorator, adding support for
|
|
370
|
-
* CLI commands while maintaining full compatibility with HTTP controllers.
|
|
371
|
-
* Modules organize commands and can import other modules to compose larger
|
|
372
|
-
* CLI applications.
|
|
373
|
-
*
|
|
374
|
-
* The module can optionally implement `NaviosModule` interface for lifecycle hooks.
|
|
375
|
-
*
|
|
376
|
-
* @param options - Configuration options for the module
|
|
377
|
-
* @returns A class decorator function
|
|
378
|
-
*
|
|
379
|
-
* @example
|
|
380
|
-
* ```typescript
|
|
381
|
-
* import { CliModule } from '@navios/commander'
|
|
382
|
-
* import { GreetCommand } from './greet.command'
|
|
383
|
-
* import { UserModule } from './user.module'
|
|
384
|
-
*
|
|
385
|
-
* @CliModule({
|
|
386
|
-
* commands: [GreetCommand],
|
|
387
|
-
* imports: [UserModule]
|
|
388
|
-
* })
|
|
389
|
-
* export class AppModule {}
|
|
390
|
-
* ```
|
|
391
|
-
*
|
|
392
|
-
* @example
|
|
393
|
-
* ```typescript
|
|
394
|
-
* // Mixed HTTP and CLI module
|
|
395
|
-
* @CliModule({
|
|
396
|
-
* controllers: [HealthController],
|
|
397
|
-
* commands: [MigrateCommand],
|
|
398
|
-
* imports: [DatabaseModule],
|
|
399
|
-
* })
|
|
400
|
-
* export class AppModule {}
|
|
401
|
-
* ```
|
|
402
|
-
*/
|
|
403
|
-
declare function CliModule({
|
|
404
|
-
commands,
|
|
405
|
-
controllers,
|
|
406
|
-
imports,
|
|
407
|
-
guards,
|
|
408
|
-
overrides,
|
|
409
|
-
priority,
|
|
410
|
-
registry
|
|
411
|
-
}?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
412
387
|
//#endregion
|
|
413
388
|
//#region src/services/commander-adapter.service.d.mts
|
|
414
389
|
/**
|
|
@@ -464,69 +439,6 @@ declare class CommanderAdapterService implements AbstractCliAdapterInterface {
|
|
|
464
439
|
}>;
|
|
465
440
|
}
|
|
466
441
|
//#endregion
|
|
467
|
-
//#region src/metadata/command.metadata.d.mts
|
|
468
|
-
/**
|
|
469
|
-
* @internal
|
|
470
|
-
* Symbol key used to store command metadata on classes.
|
|
471
|
-
*/
|
|
472
|
-
declare const CommandMetadataKey: unique symbol;
|
|
473
|
-
/**
|
|
474
|
-
* Metadata associated with a command.
|
|
475
|
-
*
|
|
476
|
-
* @public
|
|
477
|
-
*/
|
|
478
|
-
interface CommandMetadata {
|
|
479
|
-
/**
|
|
480
|
-
* The command path (e.g., 'greet', 'user:create').
|
|
481
|
-
*/
|
|
482
|
-
path: string;
|
|
483
|
-
/**
|
|
484
|
-
* Optional description of the command for help text.
|
|
485
|
-
*/
|
|
486
|
-
description?: string;
|
|
487
|
-
/**
|
|
488
|
-
* Optional Zod schema for validating command options.
|
|
489
|
-
*/
|
|
490
|
-
optionsSchema?: ZodObject;
|
|
491
|
-
/**
|
|
492
|
-
* Map of custom attributes that can be attached to the command.
|
|
493
|
-
*/
|
|
494
|
-
customAttributes: Map<string | symbol, any>;
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Gets or creates command metadata for a class.
|
|
498
|
-
*
|
|
499
|
-
* @internal
|
|
500
|
-
* @param target - The command class
|
|
501
|
-
* @param context - The decorator context
|
|
502
|
-
* @param path - The command path
|
|
503
|
-
* @param description - Optional description for help text
|
|
504
|
-
* @param optionsSchema - Optional Zod schema
|
|
505
|
-
* @returns The command metadata
|
|
506
|
-
*/
|
|
507
|
-
declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, description?: string, optionsSchema?: ZodObject): CommandMetadata;
|
|
508
|
-
/**
|
|
509
|
-
* Extracts command metadata from a class.
|
|
510
|
-
*
|
|
511
|
-
* @param target - The command class
|
|
512
|
-
* @returns The command metadata
|
|
513
|
-
* @throws {Error} If the class is not decorated with @Command
|
|
514
|
-
*
|
|
515
|
-
* @example
|
|
516
|
-
* ```typescript
|
|
517
|
-
* const metadata = extractCommandMetadata(GreetCommand)
|
|
518
|
-
* console.log(metadata.path) // 'greet'
|
|
519
|
-
* ```
|
|
520
|
-
*/
|
|
521
|
-
declare function extractCommandMetadata(target: ClassType): CommandMetadata;
|
|
522
|
-
/**
|
|
523
|
-
* Checks if a class has command metadata.
|
|
524
|
-
*
|
|
525
|
-
* @param target - The class to check
|
|
526
|
-
* @returns `true` if the class is decorated with @Command, `false` otherwise
|
|
527
|
-
*/
|
|
528
|
-
declare function hasCommandMetadata(target: ClassType): boolean;
|
|
529
|
-
//#endregion
|
|
530
442
|
//#region src/metadata/command-entry.metadata.d.mts
|
|
531
443
|
/**
|
|
532
444
|
* Symbol key for storing commands in ModuleMetadata.customEntries.
|
|
@@ -748,60 +660,6 @@ declare function defineCliEnvironment(): {
|
|
|
748
660
|
tokens: Map<InjectionToken<any, undefined, false>, AnyInjectableType>;
|
|
749
661
|
};
|
|
750
662
|
//#endregion
|
|
751
|
-
//#region src/interfaces/commander-execution-context.interface.d.mts
|
|
752
|
-
/**
|
|
753
|
-
* Execution context for a command execution.
|
|
754
|
-
*
|
|
755
|
-
* Provides access to command metadata, path, and validated options during command execution.
|
|
756
|
-
* This context is automatically injected and available via the `CommandExecutionContext` token.
|
|
757
|
-
*
|
|
758
|
-
* @example
|
|
759
|
-
* ```typescript
|
|
760
|
-
* import { inject, Injectable } from '@navios/core'
|
|
761
|
-
* import { CommandExecutionContext } from '@navios/commander'
|
|
762
|
-
*
|
|
763
|
-
* @Injectable()
|
|
764
|
-
* class CommandLogger {
|
|
765
|
-
* private ctx = inject(CommandExecutionContext)
|
|
766
|
-
*
|
|
767
|
-
* log() {
|
|
768
|
-
* console.log('Command:', this.ctx.getCommandPath())
|
|
769
|
-
* console.log('Options:', this.ctx.getOptions())
|
|
770
|
-
* }
|
|
771
|
-
* }
|
|
772
|
-
* ```
|
|
773
|
-
*/
|
|
774
|
-
declare class CommanderExecutionContext {
|
|
775
|
-
private readonly command;
|
|
776
|
-
private readonly commandPath;
|
|
777
|
-
private readonly options;
|
|
778
|
-
/**
|
|
779
|
-
* @internal
|
|
780
|
-
* Creates a new execution context.
|
|
781
|
-
*/
|
|
782
|
-
constructor(command: CommandMetadata, commandPath: string, options: any);
|
|
783
|
-
/**
|
|
784
|
-
* Gets the command metadata.
|
|
785
|
-
*
|
|
786
|
-
* @returns The command metadata including path and options schema
|
|
787
|
-
*/
|
|
788
|
-
getCommand(): CommandMetadata;
|
|
789
|
-
/**
|
|
790
|
-
* Gets the command path that was invoked.
|
|
791
|
-
*
|
|
792
|
-
* @returns The command path (e.g., 'greet', 'user:create')
|
|
793
|
-
*/
|
|
794
|
-
getCommandPath(): string;
|
|
795
|
-
/**
|
|
796
|
-
* Gets the validated command options.
|
|
797
|
-
*
|
|
798
|
-
* Options are validated against the command's Zod schema if one was provided.
|
|
799
|
-
*
|
|
800
|
-
* @returns The validated options object
|
|
801
|
-
*/
|
|
802
|
-
getOptions(): any;
|
|
803
|
-
}
|
|
804
|
-
//#endregion
|
|
805
663
|
//#region src/tokens/execution-context.token.d.mts
|
|
806
664
|
/**
|
|
807
665
|
* Injection token for accessing the current command execution context.
|
|
@@ -828,5 +686,5 @@ declare class CommanderExecutionContext {
|
|
|
828
686
|
*/
|
|
829
687
|
declare const CommandExecutionContext: InjectionToken<CommanderExecutionContext, undefined, false>;
|
|
830
688
|
//#endregion
|
|
831
|
-
export { AbstractCliAdapterInterface, CliAdapterOptions, CliEnvironment, CliModule, CliModuleOptions, CliParserService, Command, CommandEntryKey, CommandEntryValue, CommandExecutionContext, CommandHandler, CommandMetadata, CommandMetadataKey, CommandOptions, CommandRegistryService, CommanderAdapterService, CommanderExecutionContext, CommanderFactory, CommanderFactoryOptions, CommanderLoggerOptions, HelpCommand, ParsedCliArgs, RegisteredCommand, defineCliEnvironment, extractCommandMetadata, extractModuleCommands, getCommandMetadata, hasCommandMetadata };
|
|
689
|
+
export { AbstractCliAdapterInterface, CliAdapterOptions, CliEnvironment, CliModule, CliModuleOptions, CliParserService, Command, CommandEntryKey, CommandEntryValue, CommandExecutionContext, CommandHandler, CommandMetadata, CommandMetadataKey, CommandOptions, CommandRegistryService, CommanderAdapterService, CommanderExecutionContext, CommanderFactory, CommanderFactoryOptions, CommanderLoggerOptions, CommanderTuiOptions, HelpCommand, ParsedCliArgs, RegisteredCommand, defineCliEnvironment, extractCommandMetadata, extractModuleCommands, getCommandMetadata, hasCommandMetadata };
|
|
832
690
|
//# sourceMappingURL=index.d.cts.map
|