-
Notifications
You must be signed in to change notification settings - Fork 38
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
5 changed files
with
158 additions
and
53 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
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
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,12 +1,36 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const util = require('util'); | ||
const util = require('util'); | ||
const dbg = require('debug'); | ||
|
||
let out = fs.createWriteStream(process.env.TABTAB_DEBUG || '/tmp/tabtab.log', { | ||
flags: 'a' | ||
}); | ||
process.env.TABTAB_DEBUG = process.env.TABTAB_DEBUG || '/tmp/tabtab.log'; | ||
|
||
module.exports = function debug() { | ||
// console.log('write', util.format.apply(util, arguments)); | ||
out.write(util.format.apply(util, arguments) + '\n'); | ||
let out = process.env.TABTAB_DEBUG ? | ||
fs.createWriteStream(process.env.TABTAB_DEBUG, { flags: 'a' }) : | ||
null; | ||
|
||
module.exports = log; | ||
|
||
// Internal: Facade to debug module, which provides the exact same interface. | ||
// | ||
// The added benefit is with the TABTAB_DEBUG environment variable, which when | ||
// defined, will write debug output to the specified filename. | ||
// | ||
// Usefull when debugging tab completion, as logs on stdout / stderr are either | ||
// shallowed or used as tab completion results. | ||
// | ||
// namespace - The String namespace to use when TABTAB_DEBUG is not defined, | ||
// delegates to debug module. | ||
// | ||
// Examples | ||
// | ||
// // Use with following command to redirect output to file | ||
// // TABTAB_DEBUG="debug.log" tabtab ... | ||
// debug('Foo'); | ||
function debug(namespace) { | ||
var log = dbg(namespace); | ||
return () => { | ||
out && out.write(util.format.apply(util, arguments) + '\n'); | ||
out || log.apply(null, arguments); | ||
} | ||
} |
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,5 +1,25 @@ | ||
const Complete = require('./complete'); | ||
|
||
module.exports = (options) => { | ||
module.exports = tabtab; | ||
complete.Commands = require('./commands'); | ||
complete.Complete = Complete; | ||
|
||
// Public: Tabtab entry point. | ||
// | ||
// It provides the main API to the completion and plumbing system, in the form | ||
// of an EventEmitter with the following events. | ||
// | ||
// options - The options hash as parsed by minimist (default: {}) | ||
// | ||
// Examples | ||
// | ||
// // The binary name being completed. | ||
// complete.on('name', function(data, done) {}); | ||
// | ||
// // The very last word being completed, preceding the cursor tab position | ||
// complete.on('list', function(data, done) {}); | ||
// | ||
// Returns an instance of Complete. | ||
function tabtab(options) { | ||
return new Complete(options); | ||
}; | ||
} |