Skip to content

Commit

Permalink
Update for Commander 11.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Oct 13, 2023
1 parent 1c29b98 commit 5ba0682
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
18 changes: 14 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ export class CommanderError extends Error {
description: string;
required: boolean;
variadic: boolean;

defaultValue?: any;
defaultValueDescription?: string;
argChoices?: string[];

/**
* Initialize a new command argument with the given name and description.
* The default is that the argument is required, and you can explicitly
Expand Down Expand Up @@ -265,6 +268,8 @@ export class CommanderError extends Error {
negate: boolean;
defaultValue?: any;
defaultValueDescription?: string;
presetArg?: unknown;
envVar?: string;
parseArg?: <T>(value: string, previous: T) => T;
hidden: boolean;
argChoices?: string[];
Expand Down Expand Up @@ -453,7 +458,9 @@ export class CommanderError extends Error {
export class Command<Args extends any[] = [], Opts extends OptionValues = {}> {
args: string[];
processedArgs: Args;
commands: CommandUnknownOpts[];
readonly commands: readonly CommandUnknownOpts[];
// readonly options: readonly Option[];
// readonly registeredArguments: readonly Argument[];
parent: CommandUnknownOpts | null;

constructor(name?: string);
Expand All @@ -467,7 +474,10 @@ export class CommanderError extends Error {
* You can optionally supply the flags and description to override the defaults.
*/
version(str: string, flags?: string, description?: string): this;

/**
* Get the program version.
*/
version(): string | undefined;
/**
* Define a command, implemented using an action handler.
*
Expand Down Expand Up @@ -1015,7 +1025,7 @@ export class CommanderError extends Error {
/**
* Get the executable search directory.
*/
executableDir(): string;
executableDir(): string | null;

/**
* Output help information for this command.
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@commander-js/extra-typings",
"version": "11.0.0",
"version": "11.1.0",
"description": "Infer strong typings for commander options and action handlers",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -45,7 +45,7 @@
]
},
"peerDependencies": {
"commander": "11.0.x"
"commander": "11.1.x"
},
"devDependencies": {
"@types/jest": "^29.2.6",
Expand Down
29 changes: 26 additions & 3 deletions tests/commander.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ expectType<commander.Argument>(commander.createArgument('<foo>'));
expectType<string[]>(program.args);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expectType<[]>(program.processedArgs);
expectType<commander.CommandUnknownOpts[]>(program.commands);
expectType<readonly commander.CommandUnknownOpts[]>(program.commands);
// expectType<readonly commander.Option[]>(program.options);
// expectType<readonly commander.Argument[]>(program.registeredArguments);
expectType<commander.CommandUnknownOpts | null>(program.parent);

// version
expectChainedCommand(program.version('1.2.3'));
expectChainedCommand(program.version('1.2.3', '-r,--revision'));
expectChainedCommand(program.version('1.2.3', '-r,--revision', 'show revision information'));
expectType<string | undefined>(program.version());

// command (and CommandOptions)
expectChainedCommand(program.command('action'));
Expand Down Expand Up @@ -292,7 +295,7 @@ expectChainedCommand(program.nameFromFilename(__filename));

// executableDir
expectChainedCommand(program.executableDir(__dirname));
expectType<string>(program.executableDir());
expectType<string | null>(program.executableDir());

// outputHelp
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
Expand Down Expand Up @@ -414,9 +417,26 @@ expectType<string>(helper.wrap('a b c', 50, 3));

expectType<string>(helper.formatHelp(helperCommand, helper));

// Option methods
// Option properties

const baseOption = new commander.Option('-f,--foo', 'foo description');
expectType<string>(baseOption.flags);
expectType<string>(baseOption.description);
expectType<boolean>(baseOption.required);
expectType<boolean>(baseOption.optional);
expectType<boolean>(baseOption.variadic);
expectType<boolean>(baseOption.mandatory);
expectType<string | undefined>(baseOption.short);
expectType<string | undefined>(baseOption.long);
expectType<boolean>(baseOption.negate);
expectType<any>(baseOption.defaultValue);
expectType<string | undefined>(baseOption.defaultValueDescription);
expectType<unknown>(baseOption.presetArg);
expectType<string | undefined>(baseOption.envVar);
expectType<boolean>(baseOption.hidden);
expectType<string[] | undefined>(baseOption.argChoices);

// Option methods

// default
expectType<commander.Option>(baseOption.default(3));
Expand Down Expand Up @@ -470,6 +490,9 @@ const baseArgument = new commander.Argument('<foo');
expectType<string>(baseArgument.description);
expectType<boolean>(baseArgument.required);
expectType<boolean>(baseArgument.variadic);
expectType<any>(baseArgument.defaultValue);
expectType<string | undefined>(baseArgument.defaultValueDescription);
expectType<string[] | undefined>(baseArgument.argChoices);

// Argument methods

Expand Down

0 comments on commit 5ba0682

Please sign in to comment.