@navios/commander 1.4.0 → 1.5.1
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/.turbo/turbo-build.log +49 -0
- package/.turbo/turbo-check.log +2 -0
- package/.turbo/turbo-lint.log +3 -0
- package/.turbo/turbo-test$colon$ci.log +117 -0
- package/CHANGELOG.md +9 -3
- package/README.md +8 -16
- package/dist/src/commander.factory.d.mts +126 -122
- package/dist/src/commander.factory.d.mts.map +1 -1
- package/dist/src/commands/help.command.d.mts +15 -11
- package/dist/src/commands/help.command.d.mts.map +1 -1
- package/dist/src/commands/index.d.mts +2 -2
- package/dist/src/decorators/cli-module.decorator.d.mts +51 -40
- package/dist/src/decorators/cli-module.decorator.d.mts.map +1 -1
- package/dist/src/decorators/command.decorator.d.mts +49 -37
- package/dist/src/decorators/command.decorator.d.mts.map +1 -1
- package/dist/src/decorators/index.d.mts +3 -3
- package/dist/src/define-environment.d.mts +9 -8
- package/dist/src/define-environment.d.mts.map +1 -1
- package/dist/src/index.d.mts +10 -10
- package/dist/src/interfaces/abstract-cli-adapter.interface.d.mts +45 -45
- package/dist/src/interfaces/command-handler.interface.d.mts +9 -9
- package/dist/src/interfaces/commander-execution-context.interface.d.mts +30 -30
- package/dist/src/interfaces/commander-execution-context.interface.d.mts.map +1 -1
- package/dist/src/interfaces/environment.interface.d.mts +7 -7
- package/dist/src/interfaces/index.d.mts +5 -5
- package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts +6 -5
- package/dist/src/legacy-compat/decorators/cli-module.decorator.d.mts.map +1 -1
- package/dist/src/legacy-compat/decorators/command.decorator.d.mts +7 -6
- package/dist/src/legacy-compat/decorators/command.decorator.d.mts.map +1 -1
- package/dist/src/legacy-compat/decorators/index.d.mts +3 -3
- package/dist/src/legacy-compat/index.d.mts +3 -3
- package/dist/src/metadata/command-entry.metadata.d.mts +5 -5
- package/dist/src/metadata/command-entry.metadata.d.mts.map +1 -1
- package/dist/src/metadata/command.metadata.d.mts +30 -24
- package/dist/src/metadata/command.metadata.d.mts.map +1 -1
- package/dist/src/metadata/index.d.mts +3 -3
- package/dist/src/overrides/help.command.d.mts +15 -11
- package/dist/src/overrides/help.command.d.mts.map +1 -1
- package/dist/src/services/cli-parser.service.d.mts +54 -54
- package/dist/src/services/cli-parser.service.d.mts.map +1 -1
- package/dist/src/services/command-registry.service.d.mts +75 -74
- package/dist/src/services/command-registry.service.d.mts.map +1 -1
- package/dist/src/services/commander-adapter.service.d.mts +49 -48
- package/dist/src/services/commander-adapter.service.d.mts.map +1 -1
- package/dist/src/services/index.d.mts +4 -4
- package/dist/src/tokens/execution-context.token.d.mts +9 -4
- package/dist/src/tokens/execution-context.token.d.mts.map +1 -1
- package/dist/src/tokens/help-command.token.d.mts +5 -4
- package/dist/src/tokens/index.d.mts +2 -2
- package/dist/src/utils/index.d.mts +2 -2
- package/dist/src/utils/runtime.d.mts +2 -2
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsdown.config.d.mts +3 -3
- package/dist/vitest.config.d.mts +3 -3
- package/lib/{cli-module.decorator-DVl8009Q.d.cts → cli-module.decorator-BzsOEMPH.d.cts} +8 -8
- package/lib/cli-module.decorator-BzsOEMPH.d.cts.map +1 -0
- package/lib/{cli-module.decorator-DGuGfpex.d.mts → cli-module.decorator-CCV_elPP.d.mts} +13 -13
- package/lib/cli-module.decorator-CCV_elPP.d.mts.map +1 -0
- package/lib/{cli-module.decorator-CkP22084.cjs → cli-module.decorator-CXt38aqF.cjs} +2 -2
- package/lib/cli-module.decorator-CXt38aqF.cjs.map +1 -0
- package/lib/{cli-module.decorator-UGbtkRYc.mjs → cli-module.decorator-DAjf_r_W.mjs} +2 -2
- package/lib/cli-module.decorator-DAjf_r_W.mjs.map +1 -0
- package/lib/{command.decorator-UrNJmQN0.cjs → command.decorator-HziankUv.cjs} +3 -3
- package/lib/command.decorator-HziankUv.cjs.map +1 -0
- package/lib/{command.decorator-DVLSAqYZ.mjs → command.decorator-QiRU7ny3.mjs} +3 -3
- package/lib/command.decorator-QiRU7ny3.mjs.map +1 -0
- package/lib/{help-command.token-CMWYI6em.cjs → help-command.token-DamE31Aw.cjs} +4 -4
- package/lib/{help-command.token-CMWYI6em.cjs.map → help-command.token-DamE31Aw.cjs.map} +1 -1
- package/lib/{help-command.token-C0Kgj60o.mjs → help-command.token-XHx3WkoD.mjs} +4 -4
- package/lib/{help-command.token-C0Kgj60o.mjs.map → help-command.token-XHx3WkoD.mjs.map} +1 -1
- package/lib/{help.command-dtZbhq0w.mjs → help.command-Bynoll_7.mjs} +5 -8
- package/lib/help.command-Bynoll_7.mjs.map +1 -0
- package/lib/{help.command-DQyv6ali.cjs → help.command-DvKmMpB7.cjs} +6 -9
- package/lib/help.command-DvKmMpB7.cjs.map +1 -0
- package/lib/index.cjs +103 -103
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +95 -95
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +90 -90
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +102 -102
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +6 -28
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +2 -2
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +2 -2
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +4 -25
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/package.json +26 -16
- package/src/__tests__/commander.factory.e2e.spec.mts +22 -66
- package/src/commander.factory.mts +3 -1
- package/src/commands/help.command.mts +1 -1
- package/src/decorators/cli-module.decorator.mts +4 -9
- package/src/decorators/command.decorator.mts +4 -4
- package/src/define-environment.mts +4 -4
- package/src/interfaces/command-handler.interface.mts +1 -1
- package/src/interfaces/commander-execution-context.interface.mts +1 -1
- package/src/legacy-compat/decorators/cli-module.decorator.mts +2 -1
- package/src/legacy-compat/decorators/command.decorator.mts +3 -2
- package/src/metadata/command-entry.metadata.mts +3 -6
- package/src/metadata/command.metadata.mts +6 -8
- package/src/overrides/help.command.mts +2 -2
- package/src/services/__tests__/cli-parser.service.spec.mts +23 -178
- package/src/services/cli-parser.service.mts +23 -27
- package/src/services/command-registry.service.mts +5 -5
- package/src/services/commander-adapter.service.mts +10 -27
- package/src/tokens/execution-context.token.mts +4 -6
- package/tsconfig.json +3 -0
- package/lib/cli-module.decorator-CkP22084.cjs.map +0 -1
- package/lib/cli-module.decorator-DGuGfpex.d.mts.map +0 -1
- package/lib/cli-module.decorator-DVl8009Q.d.cts.map +0 -1
- package/lib/cli-module.decorator-UGbtkRYc.mjs.map +0 -1
- package/lib/command.decorator-DVLSAqYZ.mjs.map +0 -1
- package/lib/command.decorator-UrNJmQN0.cjs.map +0 -1
- package/lib/help.command-DQyv6ali.cjs.map +0 -1
- package/lib/help.command-dtZbhq0w.mjs.map +0 -1
- package/project.json +0 -66
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
|
|
4
|
-
import type { CommandHandler } from '../interfaces/command-handler.interface.mjs'
|
|
2
|
+
import { z } from 'zod/v4'
|
|
5
3
|
|
|
6
4
|
import { CommanderFactory } from '../commander.factory.mjs'
|
|
7
5
|
import { CliModule } from '../decorators/cli-module.decorator.mjs'
|
|
8
6
|
import { Command } from '../decorators/command.decorator.mjs'
|
|
9
7
|
|
|
8
|
+
import type { CommandHandler } from '../interfaces/command-handler.interface.mjs'
|
|
9
|
+
|
|
10
10
|
describe('CommanderApplication E2E - run() with different argv', () => {
|
|
11
11
|
describe('simple command without options', () => {
|
|
12
12
|
const executeMock = vi.fn()
|
|
@@ -112,9 +112,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
112
112
|
})
|
|
113
113
|
|
|
114
114
|
@Command({ path: 'deploy', optionsSchema })
|
|
115
|
-
class DeployCommand implements CommandHandler<
|
|
116
|
-
z.infer<typeof optionsSchema>
|
|
117
|
-
> {
|
|
115
|
+
class DeployCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
118
116
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
119
117
|
executeMock(options)
|
|
120
118
|
}
|
|
@@ -144,9 +142,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
144
142
|
})
|
|
145
143
|
|
|
146
144
|
@Command({ path: 'build', optionsSchema })
|
|
147
|
-
class BuildCommand implements CommandHandler<
|
|
148
|
-
z.infer<typeof optionsSchema>
|
|
149
|
-
> {
|
|
145
|
+
class BuildCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
150
146
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
151
147
|
executeMock(options)
|
|
152
148
|
}
|
|
@@ -181,9 +177,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
181
177
|
})
|
|
182
178
|
|
|
183
179
|
@Command({ path: 'greet', optionsSchema })
|
|
184
|
-
class GreetCommand implements CommandHandler<
|
|
185
|
-
z.infer<typeof optionsSchema>
|
|
186
|
-
> {
|
|
180
|
+
class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
187
181
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
188
182
|
executeMock(options)
|
|
189
183
|
}
|
|
@@ -243,13 +237,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
243
237
|
await app.init()
|
|
244
238
|
|
|
245
239
|
const adapter = app.getAdapter()
|
|
246
|
-
await adapter.run([
|
|
247
|
-
'node',
|
|
248
|
-
'script.js',
|
|
249
|
-
'greet',
|
|
250
|
-
'--name=Charlie',
|
|
251
|
-
'--greeting=Hey',
|
|
252
|
-
])
|
|
240
|
+
await adapter.run(['node', 'script.js', 'greet', '--name=Charlie', '--greeting=Hey'])
|
|
253
241
|
|
|
254
242
|
expect(executeMock).toHaveBeenCalledWith({
|
|
255
243
|
name: 'Charlie',
|
|
@@ -293,9 +281,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
293
281
|
})
|
|
294
282
|
|
|
295
283
|
@Command({ path: 'serve', optionsSchema })
|
|
296
|
-
class ServeCommand implements CommandHandler<
|
|
297
|
-
z.infer<typeof optionsSchema>
|
|
298
|
-
> {
|
|
284
|
+
class ServeCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
299
285
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
300
286
|
executeMock(options)
|
|
301
287
|
}
|
|
@@ -378,9 +364,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
378
364
|
})
|
|
379
365
|
|
|
380
366
|
@Command({ path: 'start', optionsSchema })
|
|
381
|
-
class StartCommand implements CommandHandler<
|
|
382
|
-
z.infer<typeof optionsSchema>
|
|
383
|
-
> {
|
|
367
|
+
class StartCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
384
368
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
385
369
|
executeMock(options)
|
|
386
370
|
}
|
|
@@ -520,9 +504,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
520
504
|
})
|
|
521
505
|
|
|
522
506
|
@Command({ path: 'db rollback', optionsSchema })
|
|
523
|
-
class DbRollbackWithOptionsCommand implements CommandHandler<
|
|
524
|
-
z.infer<typeof optionsSchema>
|
|
525
|
-
> {
|
|
507
|
+
class DbRollbackWithOptionsCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
526
508
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
527
509
|
executeMock(options)
|
|
528
510
|
}
|
|
@@ -562,9 +544,9 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
562
544
|
await app.init()
|
|
563
545
|
|
|
564
546
|
const adapter = app.getAdapter()
|
|
565
|
-
await expect(
|
|
566
|
-
|
|
567
|
-
)
|
|
547
|
+
await expect(adapter.run(['node', 'script.js', 'invalid'])).rejects.toThrow(
|
|
548
|
+
'[Navios Commander] Command not found: invalid',
|
|
549
|
+
)
|
|
568
550
|
|
|
569
551
|
await app.close()
|
|
570
552
|
})
|
|
@@ -648,9 +630,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
648
630
|
})
|
|
649
631
|
|
|
650
632
|
@Command({ path: 'app deploy', optionsSchema: deploySchema })
|
|
651
|
-
class DeployCommand implements CommandHandler<
|
|
652
|
-
z.infer<typeof deploySchema>
|
|
653
|
-
> {
|
|
633
|
+
class DeployCommand implements CommandHandler<z.infer<typeof deploySchema>> {
|
|
654
634
|
async execute(options: z.infer<typeof deploySchema>) {
|
|
655
635
|
executeMock(options)
|
|
656
636
|
}
|
|
@@ -768,9 +748,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
768
748
|
})
|
|
769
749
|
|
|
770
750
|
@Command({ path: 'process', optionsSchema })
|
|
771
|
-
class ProcessCommand implements CommandHandler<
|
|
772
|
-
z.infer<typeof optionsSchema>
|
|
773
|
-
> {
|
|
751
|
+
class ProcessCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
774
752
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
775
753
|
executeMock(options)
|
|
776
754
|
}
|
|
@@ -790,13 +768,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
790
768
|
await app.init()
|
|
791
769
|
|
|
792
770
|
const adapter = app.getAdapter()
|
|
793
|
-
await adapter.run([
|
|
794
|
-
'node',
|
|
795
|
-
'script.js',
|
|
796
|
-
'process',
|
|
797
|
-
'--path',
|
|
798
|
-
'/usr/local/bin',
|
|
799
|
-
])
|
|
771
|
+
await adapter.run(['node', 'script.js', 'process', '--path', '/usr/local/bin'])
|
|
800
772
|
|
|
801
773
|
expect(executeMock).toHaveBeenCalledWith({
|
|
802
774
|
path: '/usr/local/bin',
|
|
@@ -835,9 +807,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
835
807
|
})
|
|
836
808
|
|
|
837
809
|
@Command({ path: 'json-process', optionsSchema: jsonSchema })
|
|
838
|
-
class JsonProcessCommand implements CommandHandler<
|
|
839
|
-
z.infer<typeof jsonSchema>
|
|
840
|
-
> {
|
|
810
|
+
class JsonProcessCommand implements CommandHandler<z.infer<typeof jsonSchema>> {
|
|
841
811
|
async execute(options: z.infer<typeof jsonSchema>) {
|
|
842
812
|
executeMock(options)
|
|
843
813
|
}
|
|
@@ -902,9 +872,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
902
872
|
})
|
|
903
873
|
|
|
904
874
|
@Command({ path: 'welcome', optionsSchema })
|
|
905
|
-
class WelcomeCommand implements CommandHandler<
|
|
906
|
-
z.infer<typeof optionsSchema>
|
|
907
|
-
> {
|
|
875
|
+
class WelcomeCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
908
876
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
909
877
|
executeMock(options)
|
|
910
878
|
}
|
|
@@ -971,15 +939,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
971
939
|
await app.init()
|
|
972
940
|
|
|
973
941
|
const adapter = app.getAdapter()
|
|
974
|
-
await adapter.run([
|
|
975
|
-
'node',
|
|
976
|
-
'script.js',
|
|
977
|
-
'welcome',
|
|
978
|
-
'--name',
|
|
979
|
-
'Charlie',
|
|
980
|
-
'--count',
|
|
981
|
-
'3',
|
|
982
|
-
])
|
|
942
|
+
await adapter.run(['node', 'script.js', 'welcome', '--name', 'Charlie', '--count', '3'])
|
|
983
943
|
|
|
984
944
|
expect(executeMock).toHaveBeenCalledWith({
|
|
985
945
|
name: 'Charlie',
|
|
@@ -1076,16 +1036,14 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
1076
1036
|
await app.close()
|
|
1077
1037
|
})
|
|
1078
1038
|
|
|
1079
|
-
it('should validate options with
|
|
1039
|
+
it('should validate options with zod/v4 schema', async () => {
|
|
1080
1040
|
const optionsSchema = z.object({
|
|
1081
1041
|
name: z.string().min(1),
|
|
1082
1042
|
email: z.string().email(),
|
|
1083
1043
|
})
|
|
1084
1044
|
|
|
1085
1045
|
@Command({ path: 'create-user', optionsSchema })
|
|
1086
|
-
class CreateUserCommand implements CommandHandler<
|
|
1087
|
-
z.infer<typeof optionsSchema>
|
|
1088
|
-
> {
|
|
1046
|
+
class CreateUserCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
1089
1047
|
async execute(options: z.infer<typeof optionsSchema>) {
|
|
1090
1048
|
executeMock(options)
|
|
1091
1049
|
}
|
|
@@ -1145,9 +1103,7 @@ describe('CommanderApplication E2E - run() with different argv', () => {
|
|
|
1145
1103
|
|
|
1146
1104
|
// 3 commands: cmd1, cmd2, and the built-in help command
|
|
1147
1105
|
expect(commands).toHaveLength(3)
|
|
1148
|
-
expect(commands.map((c) => c.path)).toEqual(
|
|
1149
|
-
expect.arrayContaining(['cmd1', 'cmd2', 'help']),
|
|
1150
|
-
)
|
|
1106
|
+
expect(commands.map((c) => c.path)).toEqual(expect.arrayContaining(['cmd1', 'cmd2', 'help']))
|
|
1151
1107
|
|
|
1152
1108
|
await app.close()
|
|
1153
1109
|
})
|
|
@@ -245,7 +245,9 @@ export class CommanderFactory {
|
|
|
245
245
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
246
246
|
theme: options.tuiOptions?.theme as any,
|
|
247
247
|
useMouse: options.tuiOptions?.useMouse,
|
|
248
|
-
useOpenTUI:
|
|
248
|
+
useOpenTUI:
|
|
249
|
+
options.tuiOptions?.useOpenTUI ??
|
|
250
|
+
(options.tuiOptions?.adapter === 'ink' ? true : undefined),
|
|
249
251
|
})
|
|
250
252
|
|
|
251
253
|
return app
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type { ClassType, Registry } from '@navios/core'
|
|
2
|
-
|
|
3
1
|
import { Module, getModuleMetadata, getModuleCustomEntry } from '@navios/core'
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '../metadata/command-entry.metadata.mjs'
|
|
3
|
+
import type { ClassType, Registry } from '@navios/core'
|
|
4
|
+
|
|
5
|
+
import { CommandEntryKey, type CommandEntryValue } from '../metadata/command-entry.metadata.mjs'
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* Options for the `@CliModule` decorator.
|
|
@@ -108,9 +105,7 @@ export function CliModule(
|
|
|
108
105
|
) {
|
|
109
106
|
return (target: ClassType, context: ClassDecoratorContext) => {
|
|
110
107
|
if (context.kind !== 'class') {
|
|
111
|
-
throw new Error(
|
|
112
|
-
'[Navios Commander] @CliModule decorator can only be used on classes.',
|
|
113
|
-
)
|
|
108
|
+
throw new Error('[Navios Commander] @CliModule decorator can only be used on classes.')
|
|
114
109
|
}
|
|
115
110
|
|
|
116
111
|
// Apply standard @Module decorator first
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Injectable, InjectableScope, InjectionToken } from '@navios/core'
|
|
2
2
|
|
|
3
3
|
import type { ClassType, ClassTypeWithInstance, Registry } from '@navios/core'
|
|
4
|
-
import type {
|
|
4
|
+
import type { z } from 'zod/v4'
|
|
5
5
|
|
|
6
6
|
import { getCommandMetadata } from '../metadata/index.mjs'
|
|
7
7
|
|
|
@@ -29,10 +29,10 @@ export interface CommandOptions {
|
|
|
29
29
|
*/
|
|
30
30
|
description?: string
|
|
31
31
|
/**
|
|
32
|
-
* Optional
|
|
32
|
+
* Optional zod/v4 schema for validating command options.
|
|
33
33
|
* If provided, options will be validated and parsed according to this schema.
|
|
34
34
|
*/
|
|
35
|
-
optionsSchema?: ZodObject
|
|
35
|
+
optionsSchema?: z.ZodObject
|
|
36
36
|
/**
|
|
37
37
|
* Priority level for the command.
|
|
38
38
|
* Higher priority commands will be loaded first.
|
|
@@ -57,7 +57,7 @@ export interface CommandOptions {
|
|
|
57
57
|
* @example
|
|
58
58
|
* ```typescript
|
|
59
59
|
* import { Command, CommandHandler } from '@navios/commander'
|
|
60
|
-
* import { z } from 'zod'
|
|
60
|
+
* import { z } from 'zod/v4'
|
|
61
61
|
*
|
|
62
62
|
* const optionsSchema = z.object({
|
|
63
63
|
* name: z.string(),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { AnyInjectableType, InjectionToken } from '@navios/core'
|
|
2
|
-
|
|
3
1
|
import { AdapterToken } from '@navios/core'
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import type { AnyInjectableType, InjectionToken } from '@navios/core'
|
|
4
|
+
|
|
7
5
|
import { CliParserService } from './services/cli-parser.service.mjs'
|
|
6
|
+
import { CommandRegistryService } from './services/command-registry.service.mjs'
|
|
7
|
+
import { CommanderAdapterService } from './services/commander-adapter.service.mjs'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Defines the CLI environment configuration for use with NaviosFactory.
|
|
@@ -54,7 +54,7 @@ export class CommanderExecutionContext {
|
|
|
54
54
|
/**
|
|
55
55
|
* Gets the validated command options.
|
|
56
56
|
*
|
|
57
|
-
* Options are validated against the command's
|
|
57
|
+
* Options are validated against the command's zod/v4 schema if one was provided.
|
|
58
58
|
*
|
|
59
59
|
* @returns The validated options object
|
|
60
60
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createClassContext } from '@navios/core/legacy-compat'
|
|
2
|
+
|
|
1
3
|
import type { ClassType } from '@navios/core'
|
|
2
|
-
import { createClassContext } from '@navios/di/legacy-compat'
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
Command as OriginalCommand,
|
|
@@ -19,7 +20,7 @@ export type { CommandOptions }
|
|
|
19
20
|
* @example
|
|
20
21
|
* ```typescript
|
|
21
22
|
* import { Command, CommandHandler } from '@navios/commander/legacy-compat'
|
|
22
|
-
* import { z } from 'zod'
|
|
23
|
+
* import { z } from 'zod/v4'
|
|
23
24
|
*
|
|
24
25
|
* const optionsSchema = z.object({
|
|
25
26
|
* name: z.string(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ClassType } from '@navios/core'
|
|
2
|
-
|
|
3
1
|
import { extractModuleMetadata } from '@navios/core'
|
|
4
2
|
|
|
3
|
+
import type { ClassType } from '@navios/core'
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* Symbol key for storing commands in ModuleMetadata.customEntries.
|
|
7
7
|
* Used by @CliModule to store command classes.
|
|
@@ -34,8 +34,5 @@ export type CommandEntryValue = Set<ClassType>
|
|
|
34
34
|
*/
|
|
35
35
|
export function extractModuleCommands(moduleClass: ClassType): Set<ClassType> {
|
|
36
36
|
const metadata = extractModuleMetadata(moduleClass)
|
|
37
|
-
return (
|
|
38
|
-
(metadata.customEntries.get(CommandEntryKey) as CommandEntryValue) ??
|
|
39
|
-
new Set()
|
|
40
|
-
)
|
|
37
|
+
return (metadata.customEntries.get(CommandEntryKey) as CommandEntryValue) ?? new Set()
|
|
41
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClassType } from '@navios/core'
|
|
2
|
-
import type {
|
|
2
|
+
import type { z } from 'zod/v4'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
@@ -22,9 +22,9 @@ export interface CommandMetadata {
|
|
|
22
22
|
*/
|
|
23
23
|
description?: string
|
|
24
24
|
/**
|
|
25
|
-
* Optional
|
|
25
|
+
* Optional zod/v4 schema for validating command options.
|
|
26
26
|
*/
|
|
27
|
-
optionsSchema?: ZodObject
|
|
27
|
+
optionsSchema?: z.ZodObject
|
|
28
28
|
/**
|
|
29
29
|
* Map of custom attributes that can be attached to the command.
|
|
30
30
|
*/
|
|
@@ -39,7 +39,7 @@ export interface CommandMetadata {
|
|
|
39
39
|
* @param context - The decorator context
|
|
40
40
|
* @param path - The command path
|
|
41
41
|
* @param description - Optional description for help text
|
|
42
|
-
* @param optionsSchema - Optional
|
|
42
|
+
* @param optionsSchema - Optional zod/v4 schema
|
|
43
43
|
* @returns The command metadata
|
|
44
44
|
*/
|
|
45
45
|
export function getCommandMetadata(
|
|
@@ -47,12 +47,10 @@ export function getCommandMetadata(
|
|
|
47
47
|
context: ClassDecoratorContext,
|
|
48
48
|
path: string,
|
|
49
49
|
description?: string,
|
|
50
|
-
optionsSchema?: ZodObject,
|
|
50
|
+
optionsSchema?: z.ZodObject,
|
|
51
51
|
): CommandMetadata {
|
|
52
52
|
if (context.metadata) {
|
|
53
|
-
const metadata = context.metadata[CommandMetadataKey] as
|
|
54
|
-
| CommandMetadata
|
|
55
|
-
| undefined
|
|
53
|
+
const metadata = context.metadata[CommandMetadataKey] as CommandMetadata | undefined
|
|
56
54
|
if (metadata) {
|
|
57
55
|
return metadata
|
|
58
56
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ScreenLogger } from '@navios/commander-tui'
|
|
2
2
|
import { inject } from '@navios/core'
|
|
3
|
-
import { z } from 'zod'
|
|
3
|
+
import { z } from 'zod/v4'
|
|
4
4
|
|
|
5
5
|
import { Command } from '../decorators/command.decorator.mjs'
|
|
6
6
|
import { CommandRegistryService } from '../services/command-registry.service.mjs'
|
|
@@ -27,7 +27,7 @@ type HelpOptions = z.infer<typeof helpOptionsSchema>
|
|
|
27
27
|
priority: 1000,
|
|
28
28
|
})
|
|
29
29
|
export class HelpCommand implements CommandHandler<HelpOptions> {
|
|
30
|
-
private logger = inject(ScreenLogger, { screen:
|
|
30
|
+
private logger = inject(ScreenLogger, { screen: 'Help', context: 'Help' })
|
|
31
31
|
private commandRegistry = inject(CommandRegistryService)
|
|
32
32
|
|
|
33
33
|
async execute(options: HelpOptions): Promise<void> {
|