Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for showing global options in Help #19

Merged
merged 1 commit into from Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.d.ts
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
Expand Up @@ -385,6 +385,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 @@ -397,10 +398,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