Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit e34e612

Browse files
committed
feat(packages/core): allow commands to tailor yargs-parser narg setting
Fixes #3471
1 parent f9d24bd commit e34e612

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/core/src/models/command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export type CommandTreeResolution<T extends KResponse, O extends ParsedOptions>
257257
export interface YargsParserFlags {
258258
configuration?: Yargs.Configuration
259259
boolean?: string[]
260+
narg?: Record<string, number>
260261
alias?: Record<string, string[]>
261262
}
262263

packages/core/src/repl/exec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,20 @@ class InProcessExecutor implements Executor {
323323
),
324324
boolean: (commandFlags.boolean || []).concat(optionalBooleans || []),
325325
alias: Object.assign({}, commandFlags.alias || {}, optionalAliases || {}),
326-
narg:
327-
optional &&
328-
optional.reduce((N: ArgCount, { name, alias, narg }) => {
329-
if (narg) {
330-
N[unflag(name)] = narg
331-
N[unflag(alias)] = narg
332-
}
333-
return N
334-
}, {})
326+
narg: Object.assign(
327+
{},
328+
commandFlags.narg || {}, // narg from registrar.listen(route, handler, { flags: { narg: ... }})
329+
(optional &&
330+
optional.reduce((N, { name, alias, narg }) => {
331+
// narg from listen(route, handler, { usage: { optional: [...] }})
332+
if (narg) {
333+
N[unflag(name)] = narg
334+
N[unflag(alias)] = narg
335+
}
336+
return N
337+
}, {} as Record<string, number>)) ||
338+
{}
339+
)
335340
}
336341

337342
// now use minimist to parse the command line options

0 commit comments

Comments
 (0)