Skip to content

Commit

Permalink
Add option for Help Configuration (#1150)
Browse files Browse the repository at this point in the history
Add option for Help Configuration using the `.configureHelp()` function
in commander js


https://github.com/tj/commander.js/tree/v11.1.0?tab=readme-ov-file#more-configuration-2
  • Loading branch information
jmcdo29 authored Jul 1, 2024
2 parents 0c60cd1 + 1cdac14 commit 07723b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/twelve-rabbits-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'nest-commander': minor
---

feat: Add option for Help Configuration using the .configureHelp() function in
commander js
3 changes: 2 additions & 1 deletion packages/nest-commander/src/command-factory.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoggerService, LogLevel } from '@nestjs/common';
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
import { OutputConfiguration } from 'commander';
import { Help, OutputConfiguration } from 'commander';
import type { CompletionFactoryOptions } from './completion.factory.interface';

export type ErrorHandler = (err: Error) => void;
Expand All @@ -22,6 +22,7 @@ export interface CommandFactoryRunOptions
enablePositionalOptions?: boolean;
enablePassThroughOptions?: boolean;
outputConfiguration?: OutputConfiguration;
helpConfiguration?: Help;
version?: string;

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/nest-commander/src/command-runner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ ${cliPluginError(
this.options.pluginsAvailable,
)}`);
}
if (this.options.helpConfiguration) {
this.commander.configureHelp(this.options.helpConfiguration);
}
if (this.options.errorHandler) {
this.commander.exitOverride(this.options.errorHandler);
}
Expand Down Expand Up @@ -134,6 +137,9 @@ ${cliPluginError(
if (this.options.outputConfiguration) {
newCommand.configureOutput(this.options.outputConfiguration);
}
if (this.options.helpConfiguration) {
newCommand.configureHelp(this.options.helpConfiguration);
}
if (command.command.arguments) {
this.mapArgumentDescriptions(
newCommand,
Expand Down
1 change: 1 addition & 0 deletions packages/nest-commander/src/command.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class CommandFactory {
options.enablePassThroughOptions || false;
options.outputConfiguration = options.outputConfiguration || undefined;
options.completion = options.completion || false;
options.helpConfiguration = options.helpConfiguration || undefined;

return options as DefinedCommandFactoryRunOptions;
}
Expand Down

0 comments on commit 07723b6

Please sign in to comment.