Skip to content

Commit c91d890

Browse files
author
Anders Brams
committed
Fixed onProcess hooks on subcommands, usage formatting
1 parent 66e3d3d commit c91d890

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"preLaunchTask": "tsc: build - tsconfig.json",
1111
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
1212
"autoAttachChildProcesses": true,
13-
"args": ["demo", "--help"]
13+
"args": ["todd", "--help"]
1414
},
1515
{
1616
"type": "node",

src/cli-command.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ export class CliCommand {
276276
const command = this.getCommand(opts.raw ? processArgs : processArgs.slice(2))
277277

278278
// Run hooks
279-
await this.runOnProcessHooks(parsed, 'args', this.argsMap)
280-
await this.runOnProcessHooks(parsed, 'opts', this.opts)
279+
await command.runOnProcessHooks(parsed, 'args', this.argsMap)
280+
await command.runOnProcessHooks(parsed, 'opts', this.opts)
281281

282282
// Run validators
283-
await this.runValidators(parsed, 'args', this.argsMap)
284-
await this.runValidators(parsed, 'opts', this.opts)
283+
await command.runValidators(parsed, 'args', this.argsMap)
284+
await command.runValidators(parsed, 'opts', this.opts)
285285

286286
// Run handler
287287
if (command.handler !== undefined) {

src/presentation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ const formatOptions = (opts: OptionDefinition[]): string => {
5050
let optString = optStrings[i]
5151
optString = padToLength(optString, maxOptionLength + padding)
5252

53+
if (opt.required) {
54+
optString += ' (required)'
55+
}
5356
if (opt.description) {
5457
optString += ` ${opt.description}`
5558
}
5659
if (opt.defaultValue !== undefined) {
5760
optString += ` (default: ${JSON.stringify(opt.defaultValue)})`
5861
}
59-
if (opt.required) {
60-
optString += '(required)'
61-
}
6262
optStrings[i] = optString
6363
}
6464

0 commit comments

Comments
 (0)