package/package.json000644 000765 000024 0000001611 13073161176013021 0ustar00000000 000000 { "name": "help-me", "version": "1.1.0", "description": "Help command for node, partner of minimist and commist", "main": "help-me.js", "scripts": { "test": "standard && node test.js | faucet" }, "repository": { "type": "git", "url": "https://github.com/mcollina/help-me.git" }, "keywords": [ "help", "command", "minimist", "commist" ], "author": "Matteo Collina ", "license": "MIT", "bugs": { "url": "https://github.com/mcollina/help-me/issues" }, "homepage": "https://github.com/mcollina/help-me", "devDependencies": { "commist": "^1.0.0", "concat-stream": "^1.4.7", "faucet": "0.0.1", "pre-commit": "^1.1.3", "standard": "^9.0.0", "tape": "^4.6.0" }, "dependencies": { "callback-stream": "^1.0.2", "glob-stream": "^6.1.0", "through2": "^2.0.1", "xtend": "^4.0.0" } } package/.npmignore000644 000765 000024 0000001113 12740646612012532 0ustar00000000 000000 # Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript package/README.md000644 000765 000024 0000001544 13001652145012007 0ustar00000000 000000 help-me ======= Help command for node, to use with [minimist](http://npm.im/minimist) and [commist](http://npm.im/commist). Example ------- ```js 'use strict' var helpMe = require('help-me') var help = helpMe({ // the default dir: path.join(path.dirname(require.main.filename), 'doc'), // the default ext: '.txt' }) help .createStream(['hello']) // can support also strings .pipe(process.stdout) // little helper to do the same help.toStdout(['hello'] ``` Usage with commist ------------------ [Commist](http://npm.im/commist) provide a command system for node. ```js var commist = require('commist')() var help = require('help-me')() commist.register('help', help.toStdout) commist.parse(process.argv.splice(2)) ``` Acknowledgements ---------------- This project was kindly sponsored by [nearForm](http://nearform.com). License ------- MIT package/LICENSE000644 000765 000024 0000002072 12740646612011545 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2014 Matteo Collina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/test.js000644 000765 000024 0000011126 13073160076012050 0ustar00000000 000000 'use strict' var test = require('tape') var concat = require('concat-stream') var fs = require('fs') var helpMe = require('./') test('show the doc/help.txt from the require.main folder if no options are passed', function (t) { t.plan(2) helpMe() .createStream() .pipe(concat(function (data) { fs.readFile('./doc/help.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) test('show a generic help.txt from a folder to a stream', function (t) { t.plan(2) helpMe({ dir: 'fixture/basic' }).createStream() .pipe(concat(function (data) { fs.readFile('fixture/basic/help.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) test('custom help command with an array', function (t) { t.plan(2) helpMe({ dir: 'fixture/basic' }).createStream(['hello']) .pipe(concat(function (data) { fs.readFile('fixture/basic/hello.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) test('custom help command without an ext', function (t) { t.plan(2) helpMe({ dir: 'fixture/no-ext', ext: '' }).createStream(['hello']) .pipe(concat(function (data) { fs.readFile('fixture/no-ext/hello', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) test('custom help command with a string', function (t) { t.plan(2) helpMe({ dir: 'fixture/basic' }).createStream('hello') .pipe(concat(function (data) { fs.readFile('fixture/basic/hello.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) test('missing help file', function (t) { t.plan(1) helpMe({ dir: 'fixture/basic' }).createStream('abcde') .on('error', function (err) { t.equal(err.message, 'no such help file') }) .resume() }) test('custom help command with an array', function (t) { var helper = helpMe({ dir: 'fixture/shortnames' }) t.test('abbreviates two words in one', function (t) { t.plan(2) helper .createStream(['world']) .pipe(concat(function (data) { fs.readFile('fixture/shortnames/hello world.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) t.test('abbreviates three words in two', function (t) { t.plan(2) helper .createStream(['abcde', 'fghi']) .pipe(concat(function (data) { fs.readFile('fixture/shortnames/abcde fghi lmno.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) t.test('abbreviates a word', function (t) { t.plan(2) helper .createStream(['abc', 'fg']) .pipe(concat(function (data) { fs.readFile('fixture/shortnames/abcde fghi lmno.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) t.test('abbreviates a word using strings', function (t) { t.plan(2) helper .createStream('abc fg') .pipe(concat(function (data) { fs.readFile('fixture/shortnames/abcde fghi lmno.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) t.test('print a disambiguation', function (t) { t.plan(1) var expected = '' + 'There are 2 help pages that matches the given request, please disambiguate:\n' + ' * abcde fghi lmno\n' + ' * abcde hello\n' helper .createStream(['abc']) .pipe(concat({ encoding: 'string' }, function (data) { t.equal(data, expected) })) }) }) test('support for help files organized in folders', function (t) { var helper = helpMe({ dir: 'fixture/dir' }) t.test('passing an array', function (t) { t.plan(2) helper .createStream(['a', 'b']) .pipe(concat(function (data) { fs.readFile('fixture/dir/a/b.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) t.test('passing a string', function (t) { t.plan(2) helper .createStream('a b') .pipe(concat(function (data) { fs.readFile('fixture/dir/a/b.txt', function (err, expected) { t.error(err) t.equal(data.toString(), expected.toString()) }) })) }) }) package/help-me.js000644 000765 000024 0000004030 13073160530012407 0ustar00000000 000000 'use strict' var fs = require('fs') var path = require('path') var through = require('through2') var globStream = require('glob-stream') var concat = require('callback-stream') var xtend = require('xtend') var defaults = { dir: path.join(path.dirname(require.main.filename), 'doc'), ext: '.txt', help: 'help' } function helpMe (opts) { opts = xtend(defaults, opts) if (!opts.dir) { throw new Error('missing directory') } return { createStream: createStream, toStdout: toStdout } function createStream (args) { if (typeof args === 'string') { args = args.split(' ') } else if (!args || args.length === 0) { args = [opts.help] } var out = through() var gs = globStream([opts.dir + '/**/*' + opts.ext]) var re = new RegExp(args.map(function (arg) { return arg + '[a-zA-Z0-9]*' }).join('[ /]+')) gs.pipe(concat({ objectMode: true }, function (err, files) { if (err) return out.emit('error', err) files = files.map(function (file) { file.relative = file.path.replace(file.base, '').replace(/^\//, '') return file }).filter(function (file) { return file.relative.match(re) }) if (files.length === 0) { return out.emit('error', new Error('no such help file')) } else if (files.length > 1) { out.write('There are ' + files.length + ' help pages ') out.write('that matches the given request, please disambiguate:\n') files.forEach(function (file) { out.write(' * ') out.write(file.relative.replace(opts.ext, '')) out.write('\n') }) out.end() return } fs.createReadStream(files[0].path) .on('error', function (err) { out.emit('error', err) }) .pipe(out) })) return out } function toStdout (args) { createStream(args) .on('error', function () { console.log('no such help file\n') toStdout() }) .pipe(process.stdout) } } module.exports = helpMe package/example.js000644 000765 000024 0000000234 12740650022012515 0ustar00000000 000000 'use strict' var commist = require('commist')() var help = require('./')() commist.register('help', help.toStdout) commist.parse(process.argv.splice(2)) package/fixture/basic/hello.txt000644 000765 000024 0000000014 12740646612015145 0ustar00000000 000000 ahdsadhdash package/fixture/basic/help.txt000644 000765 000024 0000000014 12740646612014772 0ustar00000000 000000 hello world package/fixture/dir/a/b.txt000644 000765 000024 0000000000 12740646612014173 0ustar00000000 000000 package/fixture/no-ext/hello000644 000765 000024 0000000011 12740646612014455 0ustar00000000 000000 ghghghhg package/fixture/shortnames/abcde fghi lmno.txt000644 000765 000024 0000000017 12740646612020031 0ustar00000000 000000 ewweqjewqjewqj package/fixture/shortnames/abcde hello.txt000644 000765 000024 0000000006 12740646612017267 0ustar00000000 000000 45678 package/fixture/shortnames/hello world.txt000644 000765 000024 0000000006 12740646612017360 0ustar00000000 000000 12345 package/doc/hello.txt000644 000765 000024 0000000024 12740646612013144 0ustar00000000 000000 this is hello world package/doc/help.txt000644 000765 000024 0000000006 12740646612012771 0ustar00000000 000000 aaaaa package/.travis.yml000644 000765 000024 0000000146 13073160623012642 0ustar00000000 000000 language: node_js sudo: false node_js: - '0.10' - '0.12' - '4' - '5' - '6' - '7' script: - npm test