Skip to content

Commit

Permalink
feat: Node.js 4.4.5+ compatibility
Browse files Browse the repository at this point in the history
Make Caporal compatible with node.js 4.4.5+
  • Loading branch information
mattallty committed Feb 26, 2017
1 parent cf8e4d0 commit fd0fbdc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
10 changes: 4 additions & 6 deletions lib/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class Autocomplete {
while(!cmd && args.length) {
commandArr.push(args.shift());
const cmdStr = commandArr.join(' ');
[cmd] = commands.filter(c => {
cmd = commands.filter(c => {
return (c.name() === cmdStr || c.getAlias() === cmdStr)
});
})[0];
}

if (!cmd && this._program._getDefaultCommand()) {
Expand Down Expand Up @@ -123,8 +123,8 @@ class Autocomplete {
if ((o.getShortName() && o.getShortName() != lastPartial && o.getShortName().startsWith(lastPartial)) ||
(o.getLongName() && o.getLongName() != lastPartial && o.getLongName().startsWith(lastPartial)) ) {
return o.getLongOrShortName() + ':' + o.description();
} else if(!lastPartialIsOption && !optionsAlreadyUsed.includes(o.getShortName()) &&
!optionsAlreadyUsed.includes(o.getLongName())) {
} else if(!lastPartialIsOption && optionsAlreadyUsed.indexOf(o.getShortName()) === -1 &&
optionsAlreadyUsed.indexOf(o.getLongName()) === -1) {
return o.getLongOrShortName() + ':' + o.description();
}
}).filter(o => typeof o != 'undefined') : [];
Expand Down Expand Up @@ -196,8 +196,6 @@ class Autocomplete {
const completions = []
.concat.apply([], results)
.filter(e => typeof e != 'undefined');
console.log("results", results);
console.log("completions", completions);
done(null, completions);
return completions;
})
Expand Down
2 changes: 1 addition & 1 deletion lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class Command extends GetterSetter {
*/
_validateOptions(options) {
return Object.keys(options).reduce((acc, key) => {
if (Command.NATIVE_OPTIONS.includes(key)) {
if (Command.NATIVE_OPTIONS.indexOf(key) !== -1) {
return acc;
}
const value = acc[key];
Expand Down
4 changes: 2 additions & 2 deletions lib/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Program extends GetterSetter {
* @private
*/
help(cmdStr) {
const [cmd] = this._commands.filter(c => (c.name() === cmdStr || c.getAlias() === cmdStr));
const cmd = this._commands.filter(c => (c.name() === cmdStr || c.getAlias() === cmdStr))[0];
this._help.display(cmd);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ class Program extends GetterSetter {
while(!cmd && argsCopy.length) {
commandArr.push(argsCopy.shift());
const cmdStr = commandArr.join(' ');
[cmd] = this._commands.filter(c => (c.name() === cmdStr || c.getAlias() === cmdStr));
cmd = this._commands.filter(c => (c.name() === cmdStr || c.getAlias() === cmdStr))[0];
}

if (options.V || options.version) {
Expand Down
2 changes: 1 addition & 1 deletion lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Validator {
* @private
*/
_validateWithArray(value) {
if (!this._validator.map(String).includes(value)) {
if (this._validator.map(String).indexOf(value) === -1) {
throw new ValidationError(
"Array validation failed",
{validator: this._validator, value},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"postinstall": "(test -f ./node_modules/husky/bin/install.js && node ./node_modules/husky/bin/install.js) || exit 0"
},
"engines": {
"node": ">= 6.0.0"
"node": ">= 4.4.5"
},
"keywords": [
"cli",
Expand Down
5 changes: 4 additions & 1 deletion tests/verbosity-quiet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ describe('Passing --quiet', () => {
it(`should only output warnings & errors`, (done) => {
let output = 0;

const listener = (out, level, txt) => output++;
const listener = function(out, level, txt) {
output++
};

logger.on('logging', listener);

program.parse(makeArgv(['foo', '--quiet']));
Expand Down

0 comments on commit fd0fbdc

Please sign in to comment.