diff options
Diffstat (limited to 'deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js')
-rw-r--r-- | deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js index ad6969a2d9..5cd9a18a03 100644 --- a/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js +++ b/deps/npm/node_modules/libnpx/node_modules/yargs/lib/completion.js @@ -1,17 +1,16 @@ -'use strict' const fs = require('fs') const path = require('path') // add bash completions to your // yargs-powered applications. -module.exports = function completion (yargs, usage, command) { +module.exports = function (yargs, usage, command) { const self = { completionKey: 'get-yargs-completions' } // get a list of completion commands. // 'args' is the array of strings from the line to be completed - self.getCompletion = function getCompletion (args, done) { + self.getCompletion = function (args, done) { const completions = [] const current = args.length ? args[args.length - 1] : '' const argv = yargs.parse(args, true) @@ -21,14 +20,14 @@ module.exports = function completion (yargs, usage, command) { // to completion(). if (completionFunction) { if (completionFunction.length < 3) { - const result = completionFunction(current, argv) + var result = completionFunction(current, argv) // promise based completion function. if (typeof result.then === 'function') { - return result.then((list) => { - process.nextTick(() => { done(list) }) - }).catch((err) => { - process.nextTick(() => { throw err }) + return result.then(function (list) { + process.nextTick(function () { done(list) }) + }).catch(function (err) { + process.nextTick(function () { throw err }) }) } @@ -36,14 +35,14 @@ module.exports = function completion (yargs, usage, command) { return done(result) } else { // asynchronous completion function - return completionFunction(current, argv, (completions) => { + return completionFunction(current, argv, function (completions) { done(completions) }) } } - const handlers = command.getCommandHandlers() - for (let i = 0, ii = args.length; i < ii; ++i) { + var handlers = command.getCommandHandlers() + for (var i = 0, ii = args.length; i < ii; ++i) { if (handlers[args[i]] && handlers[args[i]].builder) { const builder = handlers[args[i]].builder if (typeof builder === 'function') { @@ -55,21 +54,22 @@ module.exports = function completion (yargs, usage, command) { } if (!current.match(/^-/)) { - usage.getCommands().forEach((usageCommand) => { - const commandName = command.parseCommand(usageCommand[0]).cmd - if (args.indexOf(commandName) === -1) { - completions.push(commandName) + usage.getCommands().forEach(function (command) { + if (args.indexOf(command[0]) === -1) { + completions.push(command[0]) } }) } if (current.match(/^-/)) { - Object.keys(yargs.getOptions().key).forEach((key) => { + Object.keys(yargs.getOptions().key).forEach(function (key) { // If the key and its aliases aren't in 'args', add the key to 'completions' - const keyAndAliases = [key].concat(aliases[key] || []) - const notInArgs = keyAndAliases.every(val => args.indexOf(`--${val}`) === -1) + var keyAndAliases = [key].concat(aliases[key] || []) + var notInArgs = keyAndAliases.every(function (val) { + return args.indexOf('--' + val) === -1 + }) if (notInArgs) { - completions.push(`--${key}`) + completions.push('--' + key) } }) } @@ -78,26 +78,25 @@ module.exports = function completion (yargs, usage, command) { } // generate the completion script to add to your .bashrc. - self.generateCompletionScript = function generateCompletionScript ($0, cmd) { - let script = fs.readFileSync( + self.generateCompletionScript = function ($0) { + var script = fs.readFileSync( path.resolve(__dirname, '../completion.sh.hbs'), 'utf-8' ) - const name = path.basename($0) + var name = path.basename($0) // add ./to applications not yet installed as bin. - if ($0.match(/\.js$/)) $0 = `./${$0}` + if ($0.match(/\.js$/)) $0 = './' + $0 script = script.replace(/{{app_name}}/g, name) - script = script.replace(/{{completion_command}}/g, cmd) return script.replace(/{{app_path}}/g, $0) } // register a function to perform your own custom // completions., this function can be either // synchrnous or asynchronous. - let completionFunction = null - self.registerFunction = (fn) => { + var completionFunction = null + self.registerFunction = function (fn) { completionFunction = fn } |