Skip to content

program.opts() can be overridden by an option #584

@rijnhard

Description

@rijnhard
import program from 'commander';

program.getOptions = program.opts;
console.log('program.opts before', program.opts); // prints body of opts() function

program.option('--opts <path>', 'specify opts path', 'test/mocha.opts');
program.parse(process.argv);

console.log('program.opts after', program.opts); // prints test/mocha.opts
console.log('program.opts()', program.opts()); // errors, is not a function
console.log('program.opts().opts', program.getOptions().opts); // this is the workaround that works.

Shouldnt the function be protected from being overridden?
it's easy enough to use program.opts().opts to get any properties that would override default functions.

But in cases (like in the mocha code) where they are using the overridden property program.opts it will introduce errors.

Thus it is a breaking change. but none the less the workaround introduce more problems with reuse then anything else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions