package/fixture/no-ext/hello000664 0000000011 3560116604 013200 0ustar00000000 000000 ghghghhg package/LICENSE000664 0000002072 3560116604 010270 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/example.js000664 0000000240 3560116604 011247 0ustar00000000 000000 'use strict' const commist = require('commist')() const help = require('./')() commist.register('help', help.toStdout) commist.parse(process.argv.splice(2)) package/help-me.js000664 0000004062 3560116604 011151 0ustar00000000 000000 'use strict' const fs = require('fs') const path = require('path') const { PassThrough, pipeline } = require('readable-stream') const glob = require('glob') const defaults = { dir: path.join(path.dirname(require.main.filename), 'doc'), ext: '.txt', help: 'help' } function helpMe (opts) { opts = Object.assign({}, 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] } const out = new PassThrough() const re = new RegExp(args.map(function (arg) { return arg + '[a-zA-Z0-9]*' }).join('[ /]+')) glob(opts.dir + '/**/*' + opts.ext, function (err, files) { if (err) return out.emit('error', err) files = files.map(function (path) { const relative = path.replace(opts.dir, '').replace(/^\//, '') return { path, relative } }).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) { const exactMatch = files.find((file) => file.relative === `${args[0]}${opts.ext}`) if (!exactMatch) { 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 } files = [exactMatch] } pipeline(fs.createReadStream(files[0].path), 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/test.js000664 0000011546 3560116604 010606 0ustar00000000 000000 'use strict' const test = require('tape') const concat = require('concat-stream') const fs = require('fs') const 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) { const 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) const 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) })) }) t.test('choose exact match over partial', function (t) { t.plan(1) helpMe({ dir: 'fixture/sameprefix' }).createStream(['hello']) .pipe(concat({ encoding: 'string' }, function (data) { t.equal(data, 'hello') })) }) }) test('support for help files organized in folders', function (t) { const 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/package.json000664 0000001527 3560116604 011555 0ustar00000000 000000 { "name": "help-me", "version": "2.0.0", "description": "Help command for node, partner of minimist and commist", "main": "help-me.js", "scripts": { "test": "standard && node test.js | tap-spec" }, "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": "^2.0.0", "pre-commit": "^1.1.3", "standard": "^16.0.0", "tap-spec": "^5.0.0", "tape": "^5.0.0" }, "dependencies": { "glob": "^7.1.6", "readable-stream": "^3.6.0" } } package/README.md000664 0000001544 3560116604 010545 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/fixture/shortnames/abcde fghi lmno.txt000664 0000000017 3560116604 016554 0ustar00000000 000000 ewweqjewqjewqj package/fixture/shortnames/abcde hello.txt000664 0000000006 3560116604 016012 0ustar00000000 000000 45678 package/fixture/dir/a/b.txt000664 0000000000 3560116604 012716 0ustar00000000 000000 package/fixture/sameprefix/hello world.txt000664 0000000013 3560116604 016061 0ustar00000000 000000 hello worldpackage/fixture/shortnames/hello world.txt000664 0000000006 3560116604 016103 0ustar00000000 000000 12345 package/doc/hello.txt000664 0000000024 3560116604 011667 0ustar00000000 000000 this is hello world package/fixture/basic/hello.txt000664 0000000014 3560116604 013670 0ustar00000000 000000 ahdsadhdash package/fixture/sameprefix/hello.txt000664 0000000005 3560116604 014752 0ustar00000000 000000 hellopackage/doc/help.txt000664 0000000006 3560116604 011514 0ustar00000000 000000 aaaaa package/fixture/basic/help.txt000664 0000000014 3560116604 013515 0ustar00000000 000000 hello world package/.travis.yml000664 0000000130 3560116604 011365 0ustar00000000 000000 language: node_js sudo: false node_js: - '10' - '12' - '14' - '15' script: - npm test