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 program to exports #1195

Merged
merged 1 commit into from Feb 15, 2020
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
2 changes: 1 addition & 1 deletion Readme.md
Expand Up @@ -56,7 +56,7 @@ Commander exports a global object which is convenient for quick programs.
This is used in the examples in this README for brevity.

```js
const program = require('commander');
const program = require('commander').program;
program.version('0.0.1');
```

Expand Down
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -1523,6 +1523,7 @@ class Command extends EventEmitter {
*/

exports = module.exports = new Command();
exports.program = exports; // More explicit access to global command.

/**
* Expose classes
Expand Down
20 changes: 20 additions & 0 deletions tests/program.test.js
@@ -0,0 +1,20 @@
const commander = require('../');

// Do some testing of the default export(s).

test('when require commander then is a Command (default export of global)', () => {
// Legacy global command
const program = commander;
expect(program.constructor.name).toBe('Command');
});

test('when require commander then has program (named export of global)', () => {
// program added in v5
const program = commander.program;
expect(program.constructor.name).toBe('Command');
});

test('when require commander then has newable Command', () => {
const cmd = new commander.Command();
expect(cmd.constructor.name).toBe('Command');
});