Upgrading commander 6 to 7
Breaking6.2.1 → 7.2.0Breaking7Deprecated2New20Changed3Fixed9Other4
BreakingUpgrade verdict
7 breaking changes.
In plain terms
- Option values are no longer set as properties on the command object; read them with .opts().
- The .passCommandToAction() method is gone because action handlers now receive the command directly.
- The extra-arguments parameter is gone; set .allowExcessArguments(false) to get an error for excess arguments.
- Several newly added help-related names were changed, so code using the old names must be updated.
Must act Top 5 of 9 that need code or config changes
Node.js requirement changed in 7.0.0-2: >= 6 → >= 10.
What you must change
Breaking7
Stores options safely by default, not as properties on the command; use program.opts() to access them.
program.opts().storeOptionsAsProperties()Removes .passCommandToAction(), no longer needed as action handler is passed options and command.
.passCommandToAction()Removes the "extra arguments" parameter to action handler; use .allowExcessArguments(false) to detect excess arguments.
.allowExcessArguments()Renames the new columns properties: Help.columns to helpWidth, getOutColumns() to getOutHelpWidth(), getErrColumns() to getErrHelpWidth().
Help.columnshelpWidthgetOutColumns()getOutHelpWidth()getErrColumns()getErrHelpWidth()Action handlers are passed options and command separately.
Errors are now displayed using process.stderr.write() instead of console.error().
process.stderr.write()console.error()Reworks the new Help.wrap() for a simpler usage pattern.
Help.wrap()Deprecations to plan for
Deprecated2
Deprecates the callback parameter to .help() and .outputHelp() (removed from README).
.help().outputHelp()Deprecates .on('--help') (removed from README).
.on('--help')API changes
Generated by DepDelta from published .d.ts files. Not mixed with prose notes.
- removed:
index commander.Command[key: string]: any - removed:
method commander.Command.passCommandToAction(value?: boolean): this - removed:
property commander.Option.bool: boolean - changed:
method commander.Command.allowUnknownOption(arg?: boolean): this → method commander.Command.allowUnknownOption(allowUnknown?: boolean): this - changed:
method commander.Command.combineFlagAndOptionalValue(arg?: boolean): this → method commander.Command.combineFlagAndOptionalValue(combine?: boolean): this - changed:
method commander.Command.helpInformation(): string → method commander.Command.helpInformation(context?: HelpContext): string - changed:
method commander.Command.opts(): { [key: string]: any } → method commander.Command.opts(): OptionValues - changed:
method commander.Command.storeOptionsAsProperties(value?: boolean): this → method commander.Command.storeOptionsAsProperties(): this & OptionValues - changed:
property commander.Option.long: string → property commander.Option.long?: string - added:
index commander.OptionValues[key: string]: any - added:
interface commander.AddHelpTextContext - added:
interface commander.Help - added:
interface commander.HelpContext - added:
interface commander.InvalidOptionArgumentError extends CommanderError - added:
interface commander.OptionValues - added:
interface commander.OutputConfiguration - added:
method commander.Command.addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string | undefined): this - added:
method commander.Command.addHelpText(position: AddHelpTextPosition, text: string): this - added:
method commander.Command.addOption(option: Option): this - added:
method commander.Command.allowExcessArguments(allowExcess?: boolean): this - added:
method commander.Command.configureHelp(): HelpConfiguration - added:
method commander.Command.configureHelp(configuration: HelpConfiguration): this - added:
method commander.Command.configureOutput(): OutputConfiguration - added:
method commander.Command.configureOutput(configuration: OutputConfiguration): this - added:
method commander.Command.createHelp(): Help - added:
method commander.Command.createOption(flags: string, description?: string): Option - added:
method commander.Command.enablePositionalOptions(positional?: boolean): this - added:
method commander.Command.help(context?: HelpContext): never - added:
method commander.Command.outputHelp(context?: HelpContext): void - added:
method commander.Command.passThroughOptions(passThrough?: boolean): this - added:
method commander.Command.storeOptionsAsProperties(storeAsProperties: true): this & OptionValues - added:
method commander.Command.storeOptionsAsProperties(storeAsProperties?: boolean): this - added:
method commander.Help.commandDescription(cmd: Command): string - added:
method commander.Help.commandUsage(cmd: Command): string - added:
method commander.Help.formatHelp(cmd: Command, helper: Help): string - added:
method commander.Help.longestArgumentTermLength(cmd: Command, helper: Help): number - added:
method commander.Help.longestOptionTermLength(cmd: Command, helper: Help): number - added:
method commander.Help.longestSubcommandTermLength(cmd: Command, helper: Help): number - added:
method commander.Help.optionDescription(option: Option): string - added:
method commander.Help.optionTerm(option: Option): string - added:
method commander.Help.padWidth(cmd: Command, helper: Help): number - added:
method commander.Help.subcommandDescription(cmd: Command): string - added:
method commander.Help.subcommandTerm(cmd: Command): string - added:
method commander.Help.visibleArguments(cmd: Command): Array<{ term: string; description: string }> - added:
method commander.Help.visibleCommands(cmd: Command): Command[] - added:
method commander.Help.visibleOptions(cmd: Command): Option[] - added:
method commander.Help.wrap(str: string, width: number, indent: number, minColumnWidth?: number): string - added:
method commander.Option.argParser<T>(fn: (value: string, previous: T) => T): this - added:
method commander.Option.argumentRejected(messsage: string): never - added:
method commander.Option.attributeName(): string - added:
method commander.Option.choices(values: string[]): this - added:
method commander.Option.default(value: any, description?: string): this - added:
method commander.Option.fullDescription(): string - added:
method commander.Option.hideHelp(hide?: boolean): this - added:
method commander.Option.makeOptionMandatory(mandatory?: boolean): this - added:
method commander.Option.name(): string - added:
method commander.OutputConfiguration.getErrHelpWidth?(): number - added:
method commander.OutputConfiguration.getOutHelpWidth?(): number - added:
method commander.OutputConfiguration.outputError?(str: string, write: (str: string) => void): void - added:
method commander.OutputConfiguration.writeErr?(str: string): void - added:
method commander.OutputConfiguration.writeOut?(str: string): void - added:
property commander.AddHelpTextContext.command: Command - added:
property commander.AddHelpTextContext.error: boolean - added:
property commander.Command.parent: Command | null - added:
property commander.CommanderStatic.Help: HelpConstructor - added:
property commander.CommanderStatic.InvalidOptionArgumentError: InvalidOptionArgumentErrorConstructor - added:
property commander.Help.helpWidth?: number - added:
property commander.Help.sortOptions: boolean - added:
property commander.Help.sortSubcommands: boolean - added:
property commander.HelpContext.error: boolean - added:
property commander.Option.argChoices?: string[] - added:
property commander.Option.defaultValue?: any - added:
property commander.Option.defaultValueDescription?: string - added:
property commander.Option.hidden: boolean - added:
property commander.Option.negate: boolean - added:
property commander.Option.optionFlags: string - added:
property commander.Option.parseArg?: <T>(value: string, previous: T) => T - added:
property commander.Option.variadic: boolean - added:
type commander.AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll' - added:
type commander.HelpConfiguration = Partial<Help> - added:
type commander.HelpConstructor = new () => Help - added:
type commander.InvalidOptionArgumentErrorConstructor = new (message: string) => InvalidOptionArgumentError