Skip to content

Upgrading commander 7 to 8

Breaking7.2.0 → 8.3.0Breaking5Platform1Deprecated5New17Changed8Other2

BreakingUpgrade verdict

5 breaking changes and a platform requirement change.

  • TypeScript users can no longer reference an Option method that was never actually implemented.
  • CommanderError code commander.invalidOptionArgument is renamed commander.invalidArgument.
  • TypeScript declaration for .addTextHelp() callback no longer allows undefined, now just string.
  • TypeScript users can no longer import the global command object as a default export; it is still available as the named `program` export.
Top 5 of 11 that need code or config changes

Node.js requirement changed in 8.0.0-0: >= 10 → >= 12.

Breaking5
Removes the TypeScript declaration of the unimplemented Option method argumentRejected.
OptionargumentRejected
CommanderError code commander.invalidOptionArgument is renamed commander.invalidArgument.
CommanderErrorcommander.invalidOptionArgumentcommander.invalidArgument
TypeScript declaration for .addTextHelp() callback no longer allows undefined, now just string.
.addTextHelp()
Removes the TypeScript declaration for the default export of the global Command object.
Commandprogram
Help method .visibleArguments() now returns an array of Argument.
Help.visibleArguments()Argument
Platform1
Commander 8 requires Node.js 12 or higher.
Deprecated5
Deprecates .command('*') in favour of using a default command.
.command('*')
Deprecates on('command:*') in favour of .showSuggestionAfterError().
on('command:*').showSuggestionAfterError()
Deprecates the second parameter of cmd.description(desc, argDescriptions) for adding argument descriptions.
cmd.description()
Suggests using .argument(name, description) instead of the deprecated description second parameter.
.argument()
Deprecates InvalidOptionArgumentError, replaced by InvalidArgumentError.
InvalidOptionArgumentErrorInvalidArgumentError

Generated by DepDelta from published .d.ts files. Not mixed with prose notes.

  • removed: const commander: commander.CommanderStatic
  • removed: export = commander
  • removed: index commander.OptionValues[key: string]: any
  • removed: interface commander.AddHelpTextContext
  • removed: interface commander.Command
  • removed: interface commander.CommandOptions
  • removed: interface commander.CommanderError extends Error
  • removed: interface commander.CommanderStatic extends Command
  • removed: interface commander.ExecutableCommandOptions extends CommandOptions
  • removed: interface commander.Help
  • removed: interface commander.HelpContext
  • removed: interface commander.InvalidOptionArgumentError extends CommanderError
  • removed: interface commander.Option
  • removed: interface commander.OptionValues
  • removed: interface commander.OutputConfiguration
  • removed: interface commander.ParseOptions
  • removed: interface commander.ParseOptionsResult
  • removed: method commander.Command.action(fn: (...args: any[]) => void | Promise<void>): this
  • removed: method commander.Command.addCommand(cmd: Command, opts?: CommandOptions): this
  • removed: method commander.Command.addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this
  • removed: method commander.Command.addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string | undefined): this
  • removed: method commander.Command.addHelpText(position: AddHelpTextPosition, text: string): this
  • removed: method commander.Command.addOption(option: Option): this
  • removed: method commander.Command.alias(): string
  • removed: method commander.Command.alias(alias: string): this
  • removed: method commander.Command.aliases(): string[]
  • removed: method commander.Command.aliases(aliases: string[]): this
  • removed: method commander.Command.allowExcessArguments(allowExcess?: boolean): this
  • removed: method commander.Command.allowUnknownOption(allowUnknown?: boolean): this
  • removed: method commander.Command.arguments(desc: string): this
  • removed: method commander.Command.combineFlagAndOptionalValue(combine?: boolean): this
  • removed: method commander.Command.command(nameAndArgs: string, description: string, opts?: commander.ExecutableCommandOptions): this
  • removed: method commander.Command.command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>
  • removed: method commander.Command.configureHelp(): HelpConfiguration
  • removed: method commander.Command.configureHelp(configuration: HelpConfiguration): this
  • removed: method commander.Command.configureOutput(): OutputConfiguration
  • removed: method commander.Command.configureOutput(configuration: OutputConfiguration): this
  • removed: method commander.Command.createCommand(name?: string): Command
  • removed: method commander.Command.createHelp(): Help
  • removed: method commander.Command.createOption(flags: string, description?: string): Option
  • removed: method commander.Command.description(): string
  • removed: method commander.Command.description(str: string, argsDescription?: { [argName: string]: string }): this
  • removed: method commander.Command.enablePositionalOptions(positional?: boolean): this
  • removed: method commander.Command.exitOverride(callback?: (err: CommanderError) => never|void): this
  • removed: method commander.Command.help(cb?: (str: string) => string): never
  • removed: method commander.Command.help(context?: HelpContext): never
  • removed: method commander.Command.helpInformation(context?: HelpContext): string
  • removed: method commander.Command.helpOption(flags?: string | boolean, description?: string): this
  • removed: method commander.Command.name(): string
  • removed: method commander.Command.name(str: string): this
  • removed: method commander.Command.on(event: string | symbol, listener: (...args: any[]) => void): this
  • removed: method commander.Command.option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this
  • removed: method commander.Command.option(flags: string, description?: string, defaultValue?: string | boolean): this
  • removed: method commander.Command.option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this
  • removed: method commander.Command.opts(): OptionValues
  • removed: method commander.Command.outputHelp(cb?: (str: string) => string): void
  • removed: method commander.Command.outputHelp(context?: HelpContext): void
  • removed: method commander.Command.parse(argv?: string[], options?: ParseOptions): this
  • removed: method commander.Command.parseAsync(argv?: string[], options?: ParseOptions): Promise<this>
  • removed: method commander.Command.parseOptions(argv: string[]): commander.ParseOptionsResult
  • removed: method commander.Command.passThroughOptions(passThrough?: boolean): this
  • removed: method commander.Command.requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this
  • removed: method commander.Command.requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this
  • removed: method commander.Command.requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this
  • removed: method commander.Command.storeOptionsAsProperties(): this & OptionValues
  • removed: method commander.Command.storeOptionsAsProperties(storeAsProperties: true): this & OptionValues
  • removed: method commander.Command.storeOptionsAsProperties(storeAsProperties?: boolean): this
  • removed: method commander.Command.usage(): string
  • removed: method commander.Command.usage(str: string): this
  • removed: method commander.Command.version(str: string, flags?: string, description?: string): this
  • removed: method commander.Help.commandDescription(cmd: Command): string
  • removed: method commander.Help.commandUsage(cmd: Command): string
  • removed: method commander.Help.formatHelp(cmd: Command, helper: Help): string
  • removed: method commander.Help.longestArgumentTermLength(cmd: Command, helper: Help): number
  • removed: method commander.Help.longestOptionTermLength(cmd: Command, helper: Help): number
  • removed: method commander.Help.longestSubcommandTermLength(cmd: Command, helper: Help): number
  • removed: method commander.Help.optionDescription(option: Option): string
  • removed: method commander.Help.optionTerm(option: Option): string
  • removed: method commander.Help.padWidth(cmd: Command, helper: Help): number
  • removed: method commander.Help.subcommandDescription(cmd: Command): string
  • removed: method commander.Help.subcommandTerm(cmd: Command): string
  • removed: method commander.Help.visibleArguments(cmd: Command): Array<{ term: string; description: string }>
  • removed: method commander.Help.visibleCommands(cmd: Command): Command[]
  • removed: method commander.Help.visibleOptions(cmd: Command): Option[]
  • removed: method commander.Help.wrap(str: string, width: number, indent: number, minColumnWidth?: number): string
  • removed: method commander.Option.argParser<T>(fn: (value: string, previous: T) => T): this
  • removed: method commander.Option.argumentRejected(messsage: string): never
  • removed: method commander.Option.attributeName(): string
  • removed: method commander.Option.choices(values: string[]): this
  • removed: method commander.Option.default(value: any, description?: string): this
  • removed: method commander.Option.fullDescription(): string
  • removed: method commander.Option.hideHelp(hide?: boolean): this
  • removed: method commander.Option.makeOptionMandatory(mandatory?: boolean): this
  • removed: method commander.Option.name(): string
  • removed: method commander.OutputConfiguration.getErrHelpWidth?(): number
  • removed: method commander.OutputConfiguration.getOutHelpWidth?(): number
  • removed: method commander.OutputConfiguration.outputError?(str: string, write: (str: string) => void): void
  • removed: method commander.OutputConfiguration.writeErr?(str: string): void
  • removed: method commander.OutputConfiguration.writeOut?(str: string): void
  • removed: namespace commander
  • removed: property commander.AddHelpTextContext.command: Command
  • removed: property commander.AddHelpTextContext.error: boolean
  • removed: property commander.Command.args: string[]
  • removed: property commander.Command.commands: Command[]
  • removed: property commander.Command.parent: Command | null
  • removed: property commander.CommandOptions.hidden?: boolean
  • removed: property commander.CommandOptions.isDefault?: boolean
  • removed: property commander.CommandOptions.noHelp?: boolean
  • removed: property commander.CommanderError.code: string
  • removed: property commander.CommanderError.exitCode: number
  • removed: property commander.CommanderError.message: string
  • removed: property commander.CommanderError.nestedError?: string
  • removed: property commander.CommanderStatic.Command: CommandConstructor
  • removed: property commander.CommanderStatic.CommanderError: CommanderErrorConstructor
  • removed: property commander.CommanderStatic.Help: HelpConstructor
  • removed: property commander.CommanderStatic.InvalidOptionArgumentError: InvalidOptionArgumentErrorConstructor
  • removed: property commander.CommanderStatic.Option: OptionConstructor
  • removed: property commander.CommanderStatic.program: Command
  • removed: property commander.ExecutableCommandOptions.executableFile?: string
  • removed: property commander.Help.helpWidth?: number
  • removed: property commander.Help.sortOptions: boolean
  • removed: property commander.Help.sortSubcommands: boolean
  • removed: property commander.HelpContext.error: boolean
  • removed: property commander.Option.argChoices?: string[]
  • removed: property commander.Option.defaultValue?: any
  • removed: property commander.Option.defaultValueDescription?: string
  • removed: property commander.Option.description: string
  • removed: property commander.Option.flags: string
  • removed: property commander.Option.hidden: boolean
  • removed: property commander.Option.long?: string
  • removed: property commander.Option.mandatory: boolean
  • removed: property commander.Option.negate: boolean
  • removed: property commander.Option.optionFlags: string
  • removed: property commander.Option.optional: boolean
  • removed: property commander.Option.parseArg?: <T>(value: string, previous: T) => T
  • removed: property commander.Option.required: boolean
  • removed: property commander.Option.short?: string
  • removed: property commander.Option.variadic: boolean
  • removed: property commander.ParseOptions.from: 'node' | 'electron' | 'user'
  • removed: property commander.ParseOptionsResult.operands: string[]
  • removed: property commander.ParseOptionsResult.unknown: string[]
  • removed: type commander.AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll'
  • removed: type commander.CommandConstructor = new (name?: string) => Command
  • removed: type commander.CommanderErrorConstructor = new (exitCode: number, code: string, message: string) => CommanderError
  • removed: type commander.HelpConfiguration = Partial<Help>
  • removed: type commander.HelpConstructor = new () => Help
  • removed: type commander.InvalidOptionArgumentErrorConstructor = new (message: string) => InvalidOptionArgumentError
  • removed: type commander.OptionConstructor = new (flags: string, description?: string) => Option
  • added: class Argument
  • added: class Command
  • added: class CommanderError extends Error
  • added: class Help
  • added: class InvalidArgumentError extends CommanderError
  • added: class InvalidOptionArgumentError extends CommanderError
  • added: class Option
  • added: const program: Command
  • added: constructor Argument(arg: string, description?: string)
  • added: constructor Command(name?: string)
  • added: constructor CommanderError(exitCode: number, code: string, message: string)
  • added: constructor Help()
  • added: constructor InvalidArgumentError(message: string)
  • added: constructor InvalidOptionArgumentError(message: string)
  • added: constructor Option(flags: string, description?: string)
  • added: function createArgument(name: string, description?: string): Argument
  • added: function createCommand(name?: string): Command
  • added: function createOption(flags: string, description?: string): Option
  • added: index OptionValues[key: string]: any
  • added: interface AddHelpTextContext
  • added: interface CommandOptions
  • added: interface ExecutableCommandOptions extends CommandOptions
  • added: interface HelpContext
  • added: interface OptionValues
  • added: interface OutputConfiguration
  • added: interface ParseOptions
  • added: interface ParseOptionsResult
  • added: method Argument.argOptional(): this
  • added: method Argument.argParser<T>(fn: (value: string, previous: T) => T): this
  • added: method Argument.argRequired(): this
  • added: method Argument.choices(values: string[]): this
  • added: method Argument.default(value: unknown, description?: string): this
  • added: method Argument.name(): string
  • added: method Command.action(fn: (...args: any[]) => void | Promise<void>): this
  • added: method Command.addArgument(arg: Argument): this
  • added: method Command.addCommand(cmd: Command, opts?: CommandOptions): this
  • added: method Command.addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this
  • added: method Command.addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string): this
  • added: method Command.addHelpText(position: AddHelpTextPosition, text: string): this
  • added: method Command.addOption(option: Option): this
  • added: method Command.alias(): string
  • added: method Command.alias(alias: string): this
  • added: method Command.aliases(): string[]
  • added: method Command.aliases(aliases: string[]): this
  • added: method Command.allowExcessArguments(allowExcess?: boolean): this
  • added: method Command.allowUnknownOption(allowUnknown?: boolean): this
  • added: method Command.argument(name: string, description?: string, defaultValue?: unknown): this
  • added: method Command.argument<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this
  • added: method Command.arguments(names: string): this
  • added: method Command.combineFlagAndOptionalValue(combine?: boolean): this
  • added: method Command.command(nameAndArgs: string, description: string, opts?: ExecutableCommandOptions): this
  • added: method Command.command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>
  • added: method Command.configureHelp(): HelpConfiguration
  • added: method Command.configureHelp(configuration: HelpConfiguration): this
  • added: method Command.configureOutput(): OutputConfiguration
  • added: method Command.configureOutput(configuration: OutputConfiguration): this
  • added: method Command.copyInheritedSettings(sourceCommand: Command): this
  • added: method Command.createArgument(name: string, description?: string): Argument
  • added: method Command.createCommand(name?: string): Command
  • added: method Command.createHelp(): Help
  • added: method Command.createOption(flags: string, description?: string): Option
  • added: method Command.description(): string
  • added: method Command.description(str: string): this
  • added: method Command.description(str: string, argsDescription: { [argName: string]: string }): this
  • added: method Command.enablePositionalOptions(positional?: boolean): this
  • added: method Command.exitOverride(callback?: (err: CommanderError) => never|void): this
  • added: method Command.getOptionValue(key: string): any
  • added: method Command.getOptionValueSource(key: string): OptionValueSource
  • added: method Command.help(cb?: (str: string) => string): never
  • added: method Command.help(context?: HelpContext): never
  • added: method Command.helpInformation(context?: HelpContext): string
  • added: method Command.helpOption(flags?: string | boolean, description?: string): this
  • added: method Command.hook(event: HookEvent, listener: (thisCommand: Command, actionCommand: Command) => void | Promise<void>): this
  • added: method Command.name(): string
  • added: method Command.name(str: string): this
  • added: method Command.on(event: string | symbol, listener: (...args: any[]) => void): this
  • added: method Command.option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this
  • added: method Command.option(flags: string, description?: string, defaultValue?: string | boolean): this
  • added: method Command.option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this
  • added: method Command.opts<T extends OptionValues>(): T
  • added: method Command.outputHelp(cb?: (str: string) => string): void
  • added: method Command.outputHelp(context?: HelpContext): void
  • added: method Command.parse(argv?: string[], options?: ParseOptions): this
  • added: method Command.parseAsync(argv?: string[], options?: ParseOptions): Promise<this>
  • added: method Command.parseOptions(argv: string[]): ParseOptionsResult
  • added: method Command.passThroughOptions(passThrough?: boolean): this
  • added: method Command.requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this
  • added: method Command.requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this
  • added: method Command.requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this
  • added: method Command.setOptionValue(key: string, value: unknown): this
  • added: method Command.setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this
  • added: method Command.showHelpAfterError(displayHelp?: boolean | string): this
  • added: method Command.showSuggestionAfterError(displaySuggestion?: boolean): this
  • added: method Command.storeOptionsAsProperties(storeAsProperties?: boolean): this
  • added: method Command.storeOptionsAsProperties<T extends OptionValues>(): this & T
  • added: method Command.storeOptionsAsProperties<T extends OptionValues>(storeAsProperties: true): this & T
  • added: method Command.usage(): string
  • added: method Command.usage(str: string): this
  • added: method Command.version(str: string, flags?: string, description?: string): this
  • added: method Help.argumentDescription(argument: Argument): string
  • added: method Help.argumentTerm(argument: Argument): string
  • added: method Help.commandDescription(cmd: Command): string
  • added: method Help.commandUsage(cmd: Command): string
  • added: method Help.formatHelp(cmd: Command, helper: Help): string
  • added: method Help.longestArgumentTermLength(cmd: Command, helper: Help): number
  • added: method Help.longestOptionTermLength(cmd: Command, helper: Help): number
  • added: method Help.longestSubcommandTermLength(cmd: Command, helper: Help): number
  • added: method Help.optionDescription(option: Option): string
  • added: method Help.optionTerm(option: Option): string
  • added: method Help.padWidth(cmd: Command, helper: Help): number
  • added: method Help.subcommandDescription(cmd: Command): string
  • added: method Help.subcommandTerm(cmd: Command): string
  • added: method Help.visibleArguments(cmd: Command): Argument[]
  • added: method Help.visibleCommands(cmd: Command): Command[]
  • added: method Help.visibleOptions(cmd: Command): Option[]
  • added: method Help.wrap(str: string, width: number, indent: number, minColumnWidth?: number): string
  • added: method Option.argParser<T>(fn: (value: string, previous: T) => T): this
  • added: method Option.attributeName(): string
  • added: method Option.choices(values: string[]): this
  • added: method Option.default(value: unknown, description?: string): this
  • added: method Option.env(name: string): this
  • added: method Option.fullDescription(): string
  • added: method Option.hideHelp(hide?: boolean): this
  • added: method Option.makeOptionMandatory(mandatory?: boolean): this
  • added: method Option.name(): string
  • added: method OutputConfiguration.getErrHelpWidth?(): number
  • added: method OutputConfiguration.getOutHelpWidth?(): number
  • added: method OutputConfiguration.outputError?(str: string, write: (str: string) => void): void
  • added: method OutputConfiguration.writeErr?(str: string): void
  • added: method OutputConfiguration.writeOut?(str: string): void
  • added: property AddHelpTextContext.command: Command
  • added: property AddHelpTextContext.error: boolean
  • added: property Argument.description: string
  • added: property Argument.required: boolean
  • added: property Argument.variadic: boolean
  • added: property Command.args: string[]
  • added: property Command.commands: Command[]
  • added: property Command.parent: Command | null
  • added: property Command.processedArgs: any[]
  • added: property CommandOptions.hidden?: boolean
  • added: property CommandOptions.isDefault?: boolean
  • added: property CommandOptions.noHelp?: boolean
  • added: property CommanderError.code: string
  • added: property CommanderError.exitCode: number
  • added: property CommanderError.message: string
  • added: property CommanderError.nestedError?: string
  • added: property ExecutableCommandOptions.executableFile?: string
  • added: property Help.helpWidth?: number
  • added: property Help.sortOptions: boolean
  • added: property Help.sortSubcommands: boolean
  • added: property HelpContext.error: boolean
  • added: property Option.argChoices?: string[]
  • added: property Option.defaultValue?: any
  • added: property Option.defaultValueDescription?: string
  • added: property Option.description: string
  • added: property Option.flags: string
  • added: property Option.hidden: boolean
  • added: property Option.long?: string
  • added: property Option.mandatory: boolean
  • added: property Option.negate: boolean
  • added: property Option.optionFlags: string
  • added: property Option.optional: boolean
  • added: property Option.parseArg?: <T>(value: string, previous: T) => T
  • added: property Option.required: boolean
  • added: property Option.short?: string
  • added: property Option.variadic: boolean
  • added: property ParseOptions.from: 'node' | 'electron' | 'user'
  • added: property ParseOptionsResult.operands: string[]
  • added: property ParseOptionsResult.unknown: string[]
  • added: type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll'
  • added: type HelpConfiguration = Partial<Help>
  • added: type HookEvent = 'preAction' | 'postAction'
  • added: type OptionValueSource = 'default' | 'env' | 'config' | 'cli'