From f34c7d9fa00d86e0d4d2743d64474837653790d7 Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 20:56:28 +0200 Subject: [PATCH 1/8] implement header, body and footer help emiters --- index.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 987b79f0d..fa04c6f5e 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const EventEmitter = require('events').EventEmitter; const spawn = require('child_process').spawn; const path = require('path'); const fs = require('fs'); +const globalEventEmitter = new EventEmitter(); // @ts-check @@ -128,6 +129,9 @@ class Command extends EventEmitter { this._helpCommandName = 'help'; this._helpCommandnameAndArgs = 'help [command]'; this._helpCommandDescription = 'display help for command'; + this._helpHeader = 'help:header'; + this._helpBody = 'help:body'; + this._helpFooter = 'help:footer'; } /** @@ -1530,12 +1534,23 @@ class Command extends EventEmitter { return passthru; }; } + globalEventEmitter.emit(this._helpHeader, this); + this.emit(this._helpHeader, this); const cbOutput = cb(this.helpInformation()); if (typeof cbOutput !== 'string' && !Buffer.isBuffer(cbOutput)) { throw new Error('outputHelp callback must return a string or a Buffer'); } - process.stdout.write(cbOutput); - this.emit(this._helpLongFlag); + const globalBodyListeners = globalEventEmitter.listeners(this._helpBody); + const bodyListeners = this.listeners(this._helpBody); + if (bodyListeners.length === 0 || globalBodyListeners.length === 0) { + process.stdout.write(cbOutput); + } else { + globalEventEmitter.emit(this._helpBody, this); + this.emit(this._helpBody, this); + } + this.emit(this._helpLongFlag); // Leave .on('--help') in for compatibility + this.emit(this._helpFooter, this); + globalEventEmitter.emit(this._helpFooter, this); }; /** @@ -1604,6 +1619,12 @@ exports.Command = Command; exports.Option = Option; exports.CommanderError = CommanderError; +/** + * Expose Global Emiter + */ + +exports.commanderGlobalEmitter = globalEventEmitter; + /** * Camel-case the given `flag` * From 4a32a730d0b4b2f55aaec90219f5e74f18c1b234 Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 20:56:58 +0200 Subject: [PATCH 2/8] add examples --- examples/help-global-listeners | 35 ++++++++++++++++++++++++++++++++++ examples/help-listeners | 21 ++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 examples/help-global-listeners create mode 100644 examples/help-listeners diff --git a/examples/help-global-listeners b/examples/help-global-listeners new file mode 100644 index 000000000..805869d97 --- /dev/null +++ b/examples/help-global-listeners @@ -0,0 +1,35 @@ +#!/usr/bin/env node + +// const program = require('commander'); // (normal include) +const program = require('../'); // include commander in git clone of commander repo +const { commanderGlobalEmitter } = require('../') + +commanderGlobalEmitter + .on('help:header', () => { + console.log('Global Header\n'); + }) + .on('help:body', (instace) => { + console.log('++++++++++++'); + console.log(instace.helpInformation().replace(/\n$/, '\n++++++++++++\n')); + }) + .on('help:footer', () => { + console.log(`The End.`); + }) + + +program + .version('0.0.1') + .option('-b, --bar', 'enable some bar') + .on('help:header', () => { + console.log('Custom Header\n'); + }) + .on('help:body', (instace) => { + console.log('------------'); + console.log(instace.helpInformation().replace(/\n$/, '\n------------\n')); + }) + .on('help:footer', () => { + console.log(`Commander - ${new Date().getFullYear()}`); + }) + .parse(process.argv); + +if (!program.args.length) program.help(); \ No newline at end of file diff --git a/examples/help-listeners b/examples/help-listeners new file mode 100644 index 000000000..6d423e0f7 --- /dev/null +++ b/examples/help-listeners @@ -0,0 +1,21 @@ +#!/usr/bin/env node + +// const program = require('commander'); // (normal include) +const program = require('../'); // include commander in git clone of commander repo + +program + .version('0.0.1') + .option('-b, --bar', 'enable some bar') + .on('help:header', () => { + console.log('Custom Header\n'); + }) + .on('help:body', (instace) => { + console.log('------------'); + console.log(instace.helpInformation().replace(/\n$/, '\n------------\n')); + }) + .on('help:footer', () => { + console.log(`Commander - ${new Date().getFullYear()}`); + }) + .parse(process.argv); + + if (!program.args.length) program.help(); \ No newline at end of file From 5e09664f9ec1522d73f134f624ce8db826fad255 Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 21:16:31 +0200 Subject: [PATCH 3/8] fix example and code --- examples/help-global-listeners | 26 +++++++++++++++++++++----- index.js | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/examples/help-global-listeners b/examples/help-global-listeners index 805869d97..34f51dcda 100644 --- a/examples/help-global-listeners +++ b/examples/help-global-listeners @@ -9,8 +9,8 @@ commanderGlobalEmitter console.log('Global Header\n'); }) .on('help:body', (instace) => { - console.log('++++++++++++'); - console.log(instace.helpInformation().replace(/\n$/, '\n++++++++++++\n')); + console.log('++++++global++++++'); + console.log(instace.helpInformation().replace(/\n$/, '\n++++++global++++++\n')); }) .on('help:footer', () => { console.log(`The End.`); @@ -20,16 +20,32 @@ commanderGlobalEmitter program .version('0.0.1') .option('-b, --bar', 'enable some bar') + +program .on('help:header', () => { console.log('Custom Header\n'); }) .on('help:body', (instace) => { - console.log('------------'); - console.log(instace.helpInformation().replace(/\n$/, '\n------------\n')); + console.log('------local------'); + console.log(instace.helpInformation().replace(/\n$/, '\n------local------\n')); }) .on('help:footer', () => { console.log(`Commander - ${new Date().getFullYear()}`); }) + .command('foo') + .action(() => {}) + +program .parse(process.argv); -if (!program.args.length) program.help(); \ No newline at end of file +/** + * examples/help-global-listeners -h + * + * Should display both global and "local" emiter messages + */ + +/** + * examples/help-global-listeners foo -h + * + * Should display only global emiter messages + */ \ No newline at end of file diff --git a/index.js b/index.js index fa04c6f5e..64d44d8f2 100644 --- a/index.js +++ b/index.js @@ -1542,7 +1542,7 @@ class Command extends EventEmitter { } const globalBodyListeners = globalEventEmitter.listeners(this._helpBody); const bodyListeners = this.listeners(this._helpBody); - if (bodyListeners.length === 0 || globalBodyListeners.length === 0) { + if (bodyListeners.length === 0 && globalBodyListeners.length === 0) { process.stdout.write(cbOutput); } else { globalEventEmitter.emit(this._helpBody, this); From 0f579322d54fe9ae1602da5ff413e72618bd2221 Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 21:43:58 +0200 Subject: [PATCH 4/8] add typings --- typings/commander-tests.ts | 5 +++++ typings/index.d.ts | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/typings/commander-tests.ts b/typings/commander-tests.ts index 57392c667..cf1254211 100644 --- a/typings/commander-tests.ts +++ b/typings/commander-tests.ts @@ -220,3 +220,8 @@ const myProgram = new MyCommand(); myProgram.myFunction(); const mySub = myProgram.command('sub'); mySub.myFunction(); + +// globalEventEmitter +const onGlobal: commander.GlobalEventEmitter = commander.globalEventEmitter.on('help:body', () => { + // do nothing. +}); \ No newline at end of file diff --git a/typings/index.d.ts b/typings/index.d.ts index 6f41bf3cf..f2124de82 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -27,6 +27,15 @@ declare namespace commander { from: 'node' | 'electron' | 'user'; } + // (string & {}) is sort of a hack so we able to show the string types autocompletion + // as well as allow any string to be used + export type Event = + | 'help:header' + | 'help:body' + | 'help:footer' + | (string & {}) + | symbol + interface Command { [key: string]: any; // options as properties @@ -353,7 +362,7 @@ declare namespace commander { * console.log('See web site for more information.'); * }); */ - on(event: string | symbol, listener: (...args: any[]) => void): this; + on(event: Event, listener: (...args: any[]) => void): this; } type CommandConstructor = new (name?: string) => Command; @@ -371,13 +380,26 @@ declare namespace commander { unknown: string[]; } + interface GlobalEventEmitter { + /** + * Add a listener (callback) for when events occur. (Implemented using EventEmitter.) + * + * @example + * program + * .on('help:body', () -> { + * console.log('See web site for more information.'); + * }); + */ + on(event: Event, listener: (...args: any[]) => void): this; + } + interface CommanderStatic extends Command { program: Command; + globalEventEmitter: GlobalEventEmitter; Command: CommandConstructor; Option: OptionConstructor; CommanderError: CommanderErrorConstructor; } - } // Declaring namespace AND global From 69cdff6bfd6fd2b29d97f739023e6a780db30ed5 Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 22:57:23 +0200 Subject: [PATCH 5/8] add tests and fix typings --- tests/command.helpGlobalListener.test.js | 125 +++++++++++++++++++++++ tests/command.helpListener.test.js | 78 ++++++++++++++ typings/commander-tests.ts | 2 +- typings/index.d.ts | 4 +- 4 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 tests/command.helpGlobalListener.test.js create mode 100644 tests/command.helpListener.test.js diff --git a/tests/command.helpGlobalListener.test.js b/tests/command.helpGlobalListener.test.js new file mode 100644 index 000000000..b0524a172 --- /dev/null +++ b/tests/command.helpGlobalListener.test.js @@ -0,0 +1,125 @@ +const commander = require('../'); +const { commanderGlobalEmitter } = require('../'); + +jest.spyOn(global.console, 'log').mockImplementation() + +// Testing help listeners, both "local" and global + +// Avoid doing many full format tests as will be broken by any layout changes! +test('when listening for the global help:body the default help command should be overriden', () => { + const program = new commander.Command(); + + commanderGlobalEmitter + .on('help:body', (instance) => { + console.log(`------------ +${instance.helpInformation().replace(/\n$/, '\n------------\n')}`); + }) + + program + .command('my-command '); + const expectedHelpInformation = +`------------ +Usage: test [options] [command] + +Options: + -h, --help display help for command + +Commands: + my-command + help [command] display help for command +------------ +`; + + program.name('test'); + program.outputHelp(); + expect(global.console.log).toHaveBeenCalledWith(expectedHelpInformation); +}); + +test('when listening for the global help:header the listener should be called correctly', () => { + const program = new commander.Command(); + const listenerCall = jest.fn() + + commanderGlobalEmitter + .on('help:header', listenerCall) + + program + .command('my-command '); + + program.outputHelp(); + expect(listenerCall).toHaveBeenCalledTimes(1); +}); + +test('when listening for the global help:footer the listener should be called correctly', () => { + const program = new commander.Command(); + const listenerCall = jest.fn() + + commanderGlobalEmitter + .on('help:footer', listenerCall) + + program + .command('my-command '); + + program.outputHelp(); + expect(listenerCall).toHaveBeenCalledTimes(1); +}); + +test('when listening for global help:header, help:body and help:footer they should be called in the correct order', () => { + const program = new commander.Command(); + const callOrder = [] + + commanderGlobalEmitter + .on('help:footer', () => { + callOrder.push('help:footer') + }) + .on('help:header', () => { + callOrder.push('help:header') + }) + .on('help:body', () => { + callOrder.push('help:body') + }) + + program + .command('my-command '); + + program.outputHelp(); + expect(callOrder[0]).toBe('help:header') + expect(callOrder[1]).toBe('help:body') + expect(callOrder[2]).toBe('help:footer') +}); + + +test('when listening for local and global help:header, help:body and help:footer they should be called in the correct order', () => { + const program = new commander.Command(); + const callOrder = [] + + commanderGlobalEmitter + .on('help:footer', () => { + callOrder.push('global:help:footer') + }) + .on('help:header', () => { + callOrder.push('global:help:header') + }) + .on('help:body', () => { + callOrder.push('global:help:body') + }) + + program + .on('help:footer', () => { + callOrder.push('help:footer') + }) + .on('help:header', () => { + callOrder.push('help:header') + }) + .on('help:body', () => { + callOrder.push('help:body') + }) + .command('my-command '); + + program.outputHelp(); + expect(callOrder[0]).toBe('global:help:header') + expect(callOrder[1]).toBe('help:header') + expect(callOrder[2]).toBe('global:help:body') + expect(callOrder[3]).toBe('help:body') + expect(callOrder[4]).toBe('help:footer') + expect(callOrder[5]).toBe('global:help:footer') +}); diff --git a/tests/command.helpListener.test.js b/tests/command.helpListener.test.js new file mode 100644 index 000000000..8385daec9 --- /dev/null +++ b/tests/command.helpListener.test.js @@ -0,0 +1,78 @@ +const commander = require('../'); + +jest.spyOn(global.console, 'log').mockImplementation() + +// Testing help listeners, both "local" and global + +// Avoid doing many full format tests as will be broken by any layout changes! +test('when listening for the help:body the default help command should be overriden', () => { + const program = new commander.Command(); + program + .on('help:body', (instance) => { + console.log(`------------ +${instance.helpInformation().replace(/\n$/, '\n------------\n')}`); + }) + .command('my-command '); + const expectedHelpInformation = +`------------ +Usage: test [options] [command] + +Options: + -h, --help display help for command + +Commands: + my-command + help [command] display help for command +------------ +`; + + program.name('test'); + program.outputHelp(); + expect(global.console.log).toHaveBeenCalledWith(expectedHelpInformation); +}); + +test('when listening for the help:header the listener should be called correctly', () => { + const program = new commander.Command(); + const listenerCall = jest.fn() + program + .on('help:header', listenerCall) + .on('help:body', () => {}) // to prevent printing to console + .command('my-command '); + + program.outputHelp(); + expect(listenerCall).toHaveBeenCalledTimes(1); +}); + +test('when listening for the help:footer the listener should be called correctly', () => { + const program = new commander.Command(); + const listenerCall = jest.fn() + program + .on('help:footer', listenerCall) + .on('help:body', () => {}) // to prevent printing to console + .command('my-command '); + + program.outputHelp(); + expect(listenerCall).toHaveBeenCalledTimes(1); +}); + +test('when listening for help:header, help:body and help:footer they should be called in the correct order', () => { + const program = new commander.Command(); + const callOrder = [] + program + .on('help:footer', () => { + callOrder.push('help:footer') + }) + .on('help:header', () => { + callOrder.push('help:header') + }) + .on('help:body', () => { + callOrder.push('help:body') + }) + .command('my-command '); + + program.outputHelp(); + expect(callOrder[0]).toBe('help:header') + expect(callOrder[1]).toBe('help:body') + expect(callOrder[2]).toBe('help:footer') +}); + diff --git a/typings/commander-tests.ts b/typings/commander-tests.ts index cf1254211..51660d63f 100644 --- a/typings/commander-tests.ts +++ b/typings/commander-tests.ts @@ -222,6 +222,6 @@ const mySub = myProgram.command('sub'); mySub.myFunction(); // globalEventEmitter -const onGlobal: commander.GlobalEventEmitter = commander.globalEventEmitter.on('help:body', () => { +const onGlobal: commander.CommanderGlobalEmitter = commander.commanderGlobalEmitter.on('help:body', () => { // do nothing. }); \ No newline at end of file diff --git a/typings/index.d.ts b/typings/index.d.ts index f2124de82..47d22139c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -380,7 +380,7 @@ declare namespace commander { unknown: string[]; } - interface GlobalEventEmitter { + interface CommanderGlobalEmitter { /** * Add a listener (callback) for when events occur. (Implemented using EventEmitter.) * @@ -395,7 +395,7 @@ declare namespace commander { interface CommanderStatic extends Command { program: Command; - globalEventEmitter: GlobalEventEmitter; + commanderGlobalEmitter: CommanderGlobalEmitter; Command: CommandConstructor; Option: OptionConstructor; CommanderError: CommanderErrorConstructor; From e69b077b88c3b316418f1de4704314701445791c Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 23:00:39 +0200 Subject: [PATCH 6/8] fix linting issues --- tests/command.helpGlobalListener.test.js | 61 ++++++++++++------------ tests/command.helpListener.test.js | 21 ++++---- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/tests/command.helpGlobalListener.test.js b/tests/command.helpGlobalListener.test.js index b0524a172..2645a8fff 100644 --- a/tests/command.helpGlobalListener.test.js +++ b/tests/command.helpGlobalListener.test.js @@ -1,19 +1,19 @@ const commander = require('../'); const { commanderGlobalEmitter } = require('../'); -jest.spyOn(global.console, 'log').mockImplementation() +jest.spyOn(global.console, 'log').mockImplementation(); // Testing help listeners, both "local" and global // Avoid doing many full format tests as will be broken by any layout changes! test('when listening for the global help:body the default help command should be overriden', () => { const program = new commander.Command(); - + commanderGlobalEmitter - .on('help:body', (instance) => { + .on('help:body', (instance) => { console.log(`------------ ${instance.helpInformation().replace(/\n$/, '\n------------\n')}`); - }) + }); program .command('my-command '); @@ -37,10 +37,10 @@ Commands: test('when listening for the global help:header the listener should be called correctly', () => { const program = new commander.Command(); - const listenerCall = jest.fn() + const listenerCall = jest.fn(); commanderGlobalEmitter - .on('help:header', listenerCall) + .on('help:header', listenerCall); program .command('my-command '); @@ -51,10 +51,10 @@ test('when listening for the global help:header the listener should be called co test('when listening for the global help:footer the listener should be called correctly', () => { const program = new commander.Command(); - const listenerCall = jest.fn() + const listenerCall = jest.fn(); commanderGlobalEmitter - .on('help:footer', listenerCall) + .on('help:footer', listenerCall); program .command('my-command '); @@ -65,61 +65,60 @@ test('when listening for the global help:footer the listener should be called co test('when listening for global help:header, help:body and help:footer they should be called in the correct order', () => { const program = new commander.Command(); - const callOrder = [] + const callOrder = []; commanderGlobalEmitter .on('help:footer', () => { - callOrder.push('help:footer') + callOrder.push('help:footer'); }) .on('help:header', () => { - callOrder.push('help:header') + callOrder.push('help:header'); }) .on('help:body', () => { - callOrder.push('help:body') - }) + callOrder.push('help:body'); + }); program .command('my-command '); program.outputHelp(); - expect(callOrder[0]).toBe('help:header') - expect(callOrder[1]).toBe('help:body') - expect(callOrder[2]).toBe('help:footer') + expect(callOrder[0]).toBe('help:header'); + expect(callOrder[1]).toBe('help:body'); + expect(callOrder[2]).toBe('help:footer'); }); - test('when listening for local and global help:header, help:body and help:footer they should be called in the correct order', () => { const program = new commander.Command(); - const callOrder = [] + const callOrder = []; commanderGlobalEmitter .on('help:footer', () => { - callOrder.push('global:help:footer') + callOrder.push('global:help:footer'); }) .on('help:header', () => { - callOrder.push('global:help:header') + callOrder.push('global:help:header'); }) .on('help:body', () => { - callOrder.push('global:help:body') - }) + callOrder.push('global:help:body'); + }); program .on('help:footer', () => { - callOrder.push('help:footer') + callOrder.push('help:footer'); }) .on('help:header', () => { - callOrder.push('help:header') + callOrder.push('help:header'); }) .on('help:body', () => { - callOrder.push('help:body') + callOrder.push('help:body'); }) .command('my-command '); program.outputHelp(); - expect(callOrder[0]).toBe('global:help:header') - expect(callOrder[1]).toBe('help:header') - expect(callOrder[2]).toBe('global:help:body') - expect(callOrder[3]).toBe('help:body') - expect(callOrder[4]).toBe('help:footer') - expect(callOrder[5]).toBe('global:help:footer') + expect(callOrder[0]).toBe('global:help:header'); + expect(callOrder[1]).toBe('help:header'); + expect(callOrder[2]).toBe('global:help:body'); + expect(callOrder[3]).toBe('help:body'); + expect(callOrder[4]).toBe('help:footer'); + expect(callOrder[5]).toBe('global:help:footer'); }); diff --git a/tests/command.helpListener.test.js b/tests/command.helpListener.test.js index 8385daec9..393455d36 100644 --- a/tests/command.helpListener.test.js +++ b/tests/command.helpListener.test.js @@ -1,6 +1,6 @@ const commander = require('../'); -jest.spyOn(global.console, 'log').mockImplementation() +jest.spyOn(global.console, 'log').mockImplementation(); // Testing help listeners, both "local" and global @@ -33,7 +33,7 @@ Commands: test('when listening for the help:header the listener should be called correctly', () => { const program = new commander.Command(); - const listenerCall = jest.fn() + const listenerCall = jest.fn(); program .on('help:header', listenerCall) .on('help:body', () => {}) // to prevent printing to console @@ -45,7 +45,7 @@ test('when listening for the help:header the listener should be called correctly test('when listening for the help:footer the listener should be called correctly', () => { const program = new commander.Command(); - const listenerCall = jest.fn() + const listenerCall = jest.fn(); program .on('help:footer', listenerCall) .on('help:body', () => {}) // to prevent printing to console @@ -57,22 +57,21 @@ test('when listening for the help:footer the listener should be called correctly test('when listening for help:header, help:body and help:footer they should be called in the correct order', () => { const program = new commander.Command(); - const callOrder = [] + const callOrder = []; program .on('help:footer', () => { - callOrder.push('help:footer') + callOrder.push('help:footer'); }) .on('help:header', () => { - callOrder.push('help:header') + callOrder.push('help:header'); }) .on('help:body', () => { - callOrder.push('help:body') + callOrder.push('help:body'); }) .command('my-command '); program.outputHelp(); - expect(callOrder[0]).toBe('help:header') - expect(callOrder[1]).toBe('help:body') - expect(callOrder[2]).toBe('help:footer') + expect(callOrder[0]).toBe('help:header'); + expect(callOrder[1]).toBe('help:body'); + expect(callOrder[2]).toBe('help:footer'); }); - From a3bf3d2109f20499ac535ffe4179c129a89f6503 Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 23:36:27 +0200 Subject: [PATCH 7/8] fix ts linting --- typings/commander-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/commander-tests.ts b/typings/commander-tests.ts index 51660d63f..61262ea25 100644 --- a/typings/commander-tests.ts +++ b/typings/commander-tests.ts @@ -224,4 +224,4 @@ mySub.myFunction(); // globalEventEmitter const onGlobal: commander.CommanderGlobalEmitter = commander.commanderGlobalEmitter.on('help:body', () => { // do nothing. -}); \ No newline at end of file +}); From 51dbcabc03044544bf412650d740baa9594f6f88 Mon Sep 17 00:00:00 2001 From: JCQuintas Date: Wed, 27 May 2020 23:46:07 +0200 Subject: [PATCH 8/8] fix typos --- examples/help-global-listeners | 12 ++++++------ examples/help-listeners | 4 ++-- tests/command.helpGlobalListener.test.js | 2 +- tests/command.helpListener.test.js | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/help-global-listeners b/examples/help-global-listeners index 34f51dcda..c5bb72b38 100644 --- a/examples/help-global-listeners +++ b/examples/help-global-listeners @@ -8,9 +8,9 @@ commanderGlobalEmitter .on('help:header', () => { console.log('Global Header\n'); }) - .on('help:body', (instace) => { + .on('help:body', (instance) => { console.log('++++++global++++++'); - console.log(instace.helpInformation().replace(/\n$/, '\n++++++global++++++\n')); + console.log(instance.helpInformation().replace(/\n$/, '\n++++++global++++++\n')); }) .on('help:footer', () => { console.log(`The End.`); @@ -25,9 +25,9 @@ program .on('help:header', () => { console.log('Custom Header\n'); }) - .on('help:body', (instace) => { + .on('help:body', (instance) => { console.log('------local------'); - console.log(instace.helpInformation().replace(/\n$/, '\n------local------\n')); + console.log(instance.helpInformation().replace(/\n$/, '\n------local------\n')); }) .on('help:footer', () => { console.log(`Commander - ${new Date().getFullYear()}`); @@ -41,11 +41,11 @@ program /** * examples/help-global-listeners -h * - * Should display both global and "local" emiter messages + * Should display both global and "local" emitter messages */ /** * examples/help-global-listeners foo -h * - * Should display only global emiter messages + * Should display only global emitter messages */ \ No newline at end of file diff --git a/examples/help-listeners b/examples/help-listeners index 6d423e0f7..f52d8bf0c 100644 --- a/examples/help-listeners +++ b/examples/help-listeners @@ -9,9 +9,9 @@ program .on('help:header', () => { console.log('Custom Header\n'); }) - .on('help:body', (instace) => { + .on('help:body', (instance) => { console.log('------------'); - console.log(instace.helpInformation().replace(/\n$/, '\n------------\n')); + console.log(instance.helpInformation().replace(/\n$/, '\n------------\n')); }) .on('help:footer', () => { console.log(`Commander - ${new Date().getFullYear()}`); diff --git a/tests/command.helpGlobalListener.test.js b/tests/command.helpGlobalListener.test.js index 2645a8fff..4a1bad178 100644 --- a/tests/command.helpGlobalListener.test.js +++ b/tests/command.helpGlobalListener.test.js @@ -6,7 +6,7 @@ jest.spyOn(global.console, 'log').mockImplementation(); // Testing help listeners, both "local" and global // Avoid doing many full format tests as will be broken by any layout changes! -test('when listening for the global help:body the default help command should be overriden', () => { +test('when listening for the global help:body the default help command should be overridden', () => { const program = new commander.Command(); commanderGlobalEmitter diff --git a/tests/command.helpListener.test.js b/tests/command.helpListener.test.js index 393455d36..b049636cd 100644 --- a/tests/command.helpListener.test.js +++ b/tests/command.helpListener.test.js @@ -5,7 +5,7 @@ jest.spyOn(global.console, 'log').mockImplementation(); // Testing help listeners, both "local" and global // Avoid doing many full format tests as will be broken by any layout changes! -test('when listening for the help:body the default help command should be overriden', () => { +test('when listening for the help:body the default help command should be overridden', () => { const program = new commander.Command(); program .on('help:body', (instance) => {