Skip to content

Commit

Permalink
Test help
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Dec 5, 2013
1 parent 871ecd4 commit 90f3bcd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
22 changes: 12 additions & 10 deletions lib/help/index.js
@@ -1,21 +1,23 @@
var fs = require('fs'),
path = require('path'),
utils = require('../utils');
path = require('path');

module.exports = help;

function help(item) {
if (!item) {
item = 'help';
} else if (item === true) { // if used with -h or --help and no args
item = 'help'
item = 'help';
}

fs.readFile(path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt'), 'utf8', function (err, body) {
if (err) {
return utils.log.error(item + ' help can\'t be found');
}
console.log(body);
process.exit(0);
});
// cleanse the filename to only contain letters
// aka: /\W/g but figured this was eaiser to read
item = item.replace(/[^a-z]/gi, '');

try {
var body = fs.readFileSync(path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt'), 'utf8');
return body;
} catch (e) {
return '"' + item + '" help can\'t be found';
}
}
3 changes: 2 additions & 1 deletion lib/nodemon.js
Expand Up @@ -32,7 +32,8 @@ function nodemon(settings) {
}

if (settings.help) {
return help(settings.help);
console.log(help(settings.help));
process.exit(0);
}

if (settings.version) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/help.txt
@@ -0,0 +1 @@
This file should not be read.
20 changes: 20 additions & 0 deletions test/help/help.test.js
@@ -0,0 +1,20 @@
/*global describe:true, it: true */
var help = require('../../lib/help'),
assert = require('assert');

describe('help', function () {
it('should load index by default', function () {
var page = help();
assert(page.indexOf('Usage: nodemon') !== -1, 'shows default help page');
});

it('should load specific help topic', function () {
var page = help('authors');
assert(page.indexOf('Remy Sharp') !== -1, 'shows specific topic');
});

it('should not expose files', function () {
var page = help('../../test/fixtures/help');
assert(page.indexOf('" help can\'t be found') !== -1, 'shows help cannot be found');
});
});

0 comments on commit 90f3bcd

Please sign in to comment.