Skip to content

Commit

Permalink
lib: linting
Browse files Browse the repository at this point in the history
no functional changes
  • Loading branch information
esatterwhite committed Sep 26, 2017
1 parent 1c4d010 commit 310c4c3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ language: node_js
node_js:
- "6"
- "7"
- "8"
17 changes: 8 additions & 9 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Command extends events.EventEmitter {
this.options = Object.create(null);
this.reset();
this.setOptions( defaults, ...options );
debug('strict mode: %s', this.options.strict)
debug('strict mode: %s', this.options.strict);
}

/**
Expand Down Expand Up @@ -228,21 +228,21 @@ class Command extends events.EventEmitter {
}

this.parsed = nopt( this.conf, this.shorthands, this.options.args || process.argv );
const keys = new Set(Object.keys(this.options.flags).concat(Object.keys(this.parsed)))
const keys = new Set(Object.keys(this.options.flags).concat(Object.keys(this.parsed)));

for (const key of keys) {
if (key === ARGV) continue
if (key === ARGV) continue;
const flag = this.options.flags[ key ];

if (!flag) {
if (this.options.strict) {
const error = new exceptions.UnknownFlagException(key)
tty.isatty() && console.log(this.usage)
this.emit('error', error)
const error = new exceptions.UnknownFlagException(key);
tty.isatty() && console.log(this.usage);
this.emit('error', error);

return this.parsed
return this.parsed;
}
continue
continue;
}

this.parsed[ key ] = hasOwn(this.parsed, key) ? this.parsed[key] : flag.default;
Expand Down Expand Up @@ -438,7 +438,6 @@ class Command extends events.EventEmitter {
callback && callback( err, content );
}.bind( this );

const a = this.argv
command = this.argv.argv.remain[0];
directive = this.argv.argv.remain[1];
cmd = cmd ? cmd : directive || null;
Expand Down
2 changes: 1 addition & 1 deletion lib/domain.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';

module.exports = require('domain').create()
module.exports = require('domain').create();
18 changes: 9 additions & 9 deletions lib/exceptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*jshint laxcomma: true, smarttabs: true, node: true*/
/*jshint laxcomma: true, smarttabs: true, node: true, esnext: true*/
'use strict';
/**
* Default exception types for seeli
Expand All @@ -23,23 +23,23 @@ class RequiredFieldException extends Error {
* @name name
* @property {String} name=RequiredFieldException Exception name
**/
this.name = 'RequiredFieldException'
this.name = 'RequiredFieldException';
/**
* @readonly
* @instance
* @memberof module:seeli/lib/exceptions.RequiredFieldException
* @name message
* @property {String} message Message to include in error output
**/
this.message = `${field} is a required option`
this.message = `${field} is a required option`;
/**
* @readonly
* @instance
* @memberof module:seeli/lib/exceptions.RequiredFieldException
* @name code
* @property {String} message A Unique error code identifier
**/
this.code = 'EREQUIRED'
this.code = 'EREQUIRED';
}

}
Expand Down Expand Up @@ -78,7 +78,7 @@ class InvalidFieldException extends RequiredFieldException {
* @name code
* @property {String} message A Unique error code identifier
**/
this.code = 'EINVALIDFIELD'
this.code = 'EINVALIDFIELD';
}
}

Expand All @@ -98,28 +98,28 @@ class UnknownFlagException extends Error {
* @name name
* @property {String} name=RequiredFieldException Exception name
**/
this.name = 'UnknownFlagException'
this.name = 'UnknownFlagException';
/**
* @readonly
* @instance
* @memberof module:seeli/lib/exceptions.UnknownFlagException
* @name message
* @property {String} message Message to include in error output
**/
this.message = `unknow field: ${field}.`
this.message = `unknow field: ${field}.`;
/**
* @readonly
* @instance
* @memberof module:seeli/lib/exceptions.UnkownFlagException
* @name code
* @property {String} message A Unique error code identifier
**/
this.code = 'ENOFLAG'
this.code = 'ENOFLAG';
}
}

module.exports = {
RequiredFieldException: RequiredFieldException
, InvalidFieldException: InvalidFieldException
, UnknownFlagException: UnknownFlagException
}
};
2 changes: 1 addition & 1 deletion lib/helpers/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exports.usage = {
, style; // color style to apply

return_value = [''];
style = !!plain ? function(input){ return input } : chalk[conf.get('color')] || chalk.green;
style = !!plain ? function(input){ return input; } : chalk[conf.get('color')] || chalk.green;

for( let flag in flags ){
let config = flags[ flag ]
Expand Down
17 changes: 11 additions & 6 deletions test/command.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* jshint laxcomma: true, smarttabs: true, node: true */
'use strict';
const assert = require("assert");
const cli = require("../")
const Command = require("../lib/command");
const chalk = require("chalk");
const assert = require('assert');
const cli = require('../')
const Command = require('../lib/command');
const chalk = require('chalk');
const strip = require('strip-ansi');
const os = require("os");
const os = require('os');
const domain = require('../lib/domain')
const test = require('tap').test

Expand Down Expand Up @@ -377,6 +377,7 @@ test('command', function(t){
ttt.throws(function(){
// should throw because it is expecting test
// sending fake should make its way to the run function
const stream = new stream.Passthrough()
DirectiveCommand.run('fake');
});

Expand All @@ -386,6 +387,11 @@ test('command', function(t){
});
t.test('strict mode', (tt) => {
tt.plan(1)
const log = console.log
console.log = () => {}
tt.on('end', () => {
console.log = log
})
var DirectiveCommand = new Command({
strict: true
, flags: {
Expand All @@ -402,7 +408,6 @@ test('command', function(t){
DirectiveCommand.setOptions({
args:['--fake=1']
});

DirectiveCommand.once('error', (err) => {
tt.equal(err.code, 'ENOFLAG', 'should return an error')
})
Expand Down

0 comments on commit 310c4c3

Please sign in to comment.