Comparing version 5.1.0 to 6.0.0
@@ -10,2 +10,3 @@ 'use strict' | ||
const repeat = require('repeat-string') | ||
const output = require('./output.js') | ||
@@ -39,2 +40,4 @@ module.exports = class { | ||
run (callback) { | ||
callback = callback || function () {} | ||
let context_first = this.context.length > 1 ? this.context[0] : false | ||
@@ -91,3 +94,11 @@ let options = last(this.context) | ||
asyncDone(action, callback) | ||
asyncDone(action, function (err) { | ||
if (err) { | ||
output.error(chalk.red(err)) | ||
callback(err) | ||
} else { | ||
callback() | ||
} | ||
}) | ||
} else { | ||
@@ -97,2 +108,4 @@ throw new Error('run with --help to get a list of commands') | ||
} catch (error) { | ||
output.error(chalk.red(error)) | ||
callback(error) | ||
@@ -104,3 +117,2 @@ } | ||
let context_first = this.context.length > 1 ? this.context[0] : false | ||
let results = [] | ||
let cols = [] | ||
@@ -113,6 +125,6 @@ let longest = 0 | ||
results.push(chalk.magenta('Description:') + ' ' + command.settings.description) | ||
results.push(chalk.magenta('Usage:') + ' [options] ' + context_first + ' ' + usage) | ||
output.log(chalk.magenta('Description:') + ' ' + command.settings.description) | ||
output.log(chalk.magenta('Usage:') + ' [options] ' + context_first + ' ' + usage) | ||
if (Object.keys(command.settings.options).length) { | ||
results.push(chalk.magenta('Options:')) | ||
output.log(chalk.magenta('Options:')) | ||
} | ||
@@ -131,3 +143,3 @@ | ||
cols.forEach(function (v) { | ||
results.push(' ' + chalk.cyan(v[0]) + repeat(' ', longest - v[0].length) + v[1]) | ||
output.log(' ' + chalk.cyan(v[0]) + repeat(' ', longest - v[0].length) + v[1]) | ||
}) | ||
@@ -139,3 +151,3 @@ | ||
if (Object.keys(command.settings.aliases).length) { | ||
results.push(chalk.magenta('Aliases:')) | ||
output.log(chalk.magenta('Aliases:')) | ||
} | ||
@@ -164,8 +176,8 @@ | ||
cols.forEach(function (v) { | ||
results.push(' ' + chalk.cyan(v[0]) + repeat(' ', longest - v[0].length) + v[1]) | ||
output.log(' ' + chalk.cyan(v[0]) + repeat(' ', longest - v[0].length) + v[1]) | ||
}) | ||
} else { | ||
results.push(chalk.magenta('Description:') + ' ' + this.settings.description) | ||
output.log(chalk.magenta('Description:') + ' ' + this.settings.description) | ||
if (Object.keys(this.commands).length) { | ||
results.push(chalk.magenta('Commands:')) | ||
output.log(chalk.magenta('Commands:')) | ||
} | ||
@@ -186,8 +198,8 @@ | ||
cols.forEach(function (v) { | ||
results.push(' ' + chalk.cyan(v[0]) + repeat(' ', longest - v[0].length) + v[1]) | ||
output.log(' ' + chalk.cyan(v[0]) + repeat(' ', longest - v[0].length) + v[1]) | ||
}) | ||
} | ||
callback(null, results.join('\n')) | ||
callback() | ||
} | ||
} |
@@ -5,2 +5,3 @@ 'use strict' | ||
const parse = require('./parse.js') | ||
const output = require('./output.js') | ||
const defaultArgv = process.argv.slice(2) | ||
@@ -16,2 +17,10 @@ | ||
sergeant.series = require('./series.js') | ||
sergeant.parallel = require('./parallel.js') | ||
sergeant.log = output.log | ||
sergeant.error = output.error | ||
module.exports = sergeant |
{ | ||
"name": "sergeant", | ||
"version": "5.1.0", | ||
"version": "6.0.0", | ||
"description": "", | ||
@@ -32,4 +32,5 @@ "main": "code/main.js", | ||
"object-assign": "^3.0.0", | ||
"pretty-hrtime": "^1.0.0", | ||
"repeat-string": "^1.5.2" | ||
} | ||
} |
var assert = require('assert') | ||
var describe = require('mocha').describe | ||
var it = require('mocha').it | ||
var beforeEach = require('mocha').beforeEach | ||
var Application = require('../code/application.js') | ||
var output = require('../code/output.js') | ||
var chalk = require('chalk') | ||
var log | ||
var errorLog | ||
output.log = function (str) { | ||
log.push(str) | ||
} | ||
output.error = function (str) { | ||
errorLog.push(str) | ||
} | ||
beforeEach(function () { | ||
log = [] | ||
errorLog = [] | ||
}) | ||
describe('application', function () { | ||
@@ -12,10 +29,8 @@ it('should run commands', function (done) { | ||
app.command('test', function (options, d) { | ||
d(null, 'ran test') | ||
d() | ||
}) | ||
app.run(function (err, result) { | ||
app.run(function (err) { | ||
assert.ifError(err) | ||
assert.equal(result, 'ran test') | ||
done() | ||
@@ -29,10 +44,8 @@ }) | ||
app.command('test', function (d) { | ||
d(null, 'ran test') | ||
d() | ||
}) | ||
app.run(function (err, result) { | ||
app.run(function (err) { | ||
assert.ifError(err) | ||
assert.equal(result, 'ran test') | ||
done() | ||
@@ -129,6 +142,6 @@ }) | ||
app.run(function (err, result) { | ||
app.run(function (err) { | ||
assert.ifError(err) | ||
assert.deepEqual(result, [ | ||
assert.deepEqual(log, [ | ||
chalk.magenta('Description:') + ' a test app', | ||
@@ -138,3 +151,3 @@ chalk.magenta('Commands:'), | ||
' ' + chalk.cyan('[options] test <arg>') + ' test command' | ||
].join('\n')) | ||
]) | ||
@@ -158,6 +171,6 @@ done() | ||
app.run(function (err, result) { | ||
app.run(function (err) { | ||
assert.ifError(err) | ||
assert.deepEqual(result, [ | ||
assert.deepEqual(log, [ | ||
chalk.magenta('Description:') + ' a test app', | ||
@@ -167,3 +180,3 @@ chalk.magenta('Commands:'), | ||
' ' + chalk.cyan('[options] test <arg>') + ' test command' | ||
].join('\n')) | ||
]) | ||
@@ -177,8 +190,8 @@ done() | ||
app.run(function (err, result) { | ||
app.run(function (err) { | ||
assert.ifError(err) | ||
assert.deepEqual(result, [ | ||
assert.deepEqual(log, [ | ||
chalk.magenta('Description:') + ' a test app' | ||
].join('\n')) | ||
]) | ||
@@ -208,6 +221,6 @@ done() | ||
app.run(function (err, result) { | ||
app.run(function (err) { | ||
assert.ifError(err) | ||
assert.deepEqual(result, [ | ||
assert.deepEqual(log, [ | ||
chalk.magenta('Description:') + ' test command', | ||
@@ -221,3 +234,3 @@ chalk.magenta('Usage:') + ' [options] test <arg>', | ||
' ' + chalk.cyan('b') + ' --option' | ||
].join('\n')) | ||
]) | ||
@@ -238,6 +251,6 @@ done() | ||
assert.deepEqual(result, [ | ||
assert.deepEqual(log, [ | ||
chalk.magenta('Description:') + ' test command', | ||
chalk.magenta('Usage:') + ' [options] test <arg>' | ||
].join('\n')) | ||
]) | ||
@@ -244,0 +257,0 @@ done() |
23041
17
682
8
+ Addedpretty-hrtime@^1.0.0
+ Addedpretty-hrtime@1.0.3(transitive)