Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
35 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file should not be read. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |