Skip to content

Commit

Permalink
Add support for showing global options in Help (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn authored Dec 19, 2022
1 parent 536ef60 commit 5ee0817
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ export class CommanderError extends Error {
helpWidth?: number;
sortSubcommands: boolean;
sortOptions: boolean;

showGlobalOptions: boolean;

constructor();

/** Get the command term to show in the list of subcommands. */
Expand All @@ -383,13 +384,17 @@ export class CommanderError extends Error {
visibleCommands(cmd: CommandUnknownOpts): CommandUnknownOpts[];
/** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */
visibleOptions(cmd: CommandUnknownOpts): Option[];
/** Get an array of the visible global options. (Not including help.) */
visibleGlobalOptions(cmd: CommandUnknownOpts): Option[];
/** Get an array of the arguments which have descriptions. */
visibleArguments(cmd: CommandUnknownOpts): Argument[];

/** Get the longest command term length. */
longestSubcommandTermLength(cmd: CommandUnknownOpts, helper: Help): number;
/** Get the longest option term length. */
longestOptionTermLength(cmd: CommandUnknownOpts, helper: Help): number;
/** Get the longest global option term length. */
longestGlobalOptionTermLength(cmd: CommandUnknownOpts, helper: Help): number;
/** Get the longest argument term length. */
longestArgumentTermLength(cmd: CommandUnknownOpts, helper: Help): number;
/** Calculate the pad width from the maximum term length. */
Expand Down
3 changes: 3 additions & 0 deletions tests/commander.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ const helperArgument = new commander.Argument('<file>');
expectType<number | undefined>(helper.helpWidth);
expectType<boolean>(helper.sortSubcommands);
expectType<boolean>(helper.sortOptions);
expectType<boolean>(helper.showGlobalOptions);

expectType<string>(helper.subcommandTerm(helperCommand));
expectType<string>(helper.commandUsage(helperCommand));
Expand All @@ -400,10 +401,12 @@ expectType<string>(helper.argumentDescription(helperArgument));

expectType<commander.CommandUnknownOpts[]>(helper.visibleCommands(helperCommand));
expectType<commander.Option[]>(helper.visibleOptions(helperCommand));
expectType<commander.Option[]>(helper.visibleGlobalOptions(helperCommand));
expectType<commander.Argument[]>(helper.visibleArguments(helperCommand));

expectType<number>(helper.longestSubcommandTermLength(helperCommand, helper));
expectType<number>(helper.longestOptionTermLength(helperCommand, helper));
expectType<number>(helper.longestGlobalOptionTermLength(helperCommand, helper));
expectType<number>(helper.longestArgumentTermLength(helperCommand, helper));
expectType<number>(helper.padWidth(helperCommand, helper));

Expand Down

0 comments on commit 5ee0817

Please sign in to comment.