-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating codebase to use @feross' standard, for easier contributions.…
… see #144
- Loading branch information
Benjamin Coe
committed
Apr 14, 2015
1 parent
1f2bf91
commit 679fbbf
Showing
15 changed files
with
3,905 additions
and
3,942 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,71 +1,71 @@ | ||
var fs = require('fs'), | ||
path = require('path'); | ||
path = require('path') | ||
|
||
// add bash completions to your | ||
// yargs-powered applications. | ||
module.exports = function (yargs, usage) { | ||
var self = { | ||
completionKey: 'get-yargs-completions' | ||
}; | ||
} | ||
|
||
// get a list of completion commands. | ||
self.getCompletion = function (done) { | ||
var completions = [], | ||
current = process.argv[process.argv.length - 1], | ||
previous = process.argv.slice(process.argv.indexOf('--' + self.completionKey) + 1), | ||
argv = yargs.parse(previous); | ||
current = process.argv[process.argv.length - 1], | ||
previous = process.argv.slice(process.argv.indexOf('--' + self.completionKey) + 1), | ||
argv = yargs.parse(previous) | ||
|
||
// a custom completion function can be provided | ||
// to completion(). | ||
if (completionFunction) { | ||
if (completionFunction.length < 3) { | ||
// synchronous completion function. | ||
return done(completionFunction(current, argv)); | ||
return done(completionFunction(current, argv)) | ||
} else { | ||
// asynchronous completion function | ||
return completionFunction(current, argv, function(completions) { | ||
done(completions); | ||
}); | ||
return completionFunction(current, argv, function (completions) { | ||
done(completions) | ||
}) | ||
} | ||
} | ||
|
||
if (!current.match(/^-/)) { | ||
usage.getCommands().forEach(function(command) { | ||
completions.push(command[0]); | ||
}); | ||
usage.getCommands().forEach(function (command) { | ||
completions.push(command[0]) | ||
}) | ||
} | ||
|
||
if (current.match(/^-/)) { | ||
Object.keys(yargs.getOptions().key).forEach(function(key) { | ||
completions.push('--' + key); | ||
}); | ||
Object.keys(yargs.getOptions().key).forEach(function (key) { | ||
completions.push('--' + key) | ||
}) | ||
} | ||
|
||
done(completions); | ||
}; | ||
done(completions) | ||
} | ||
|
||
// generate the completion script to add to your .bashrc. | ||
self.generateCompletionScript = function ($0) { | ||
var script = fs.readFileSync( | ||
path.resolve(__dirname, '../completion.sh.hbs'), | ||
'utf-8' | ||
), | ||
name = path.basename($0); | ||
path.resolve(__dirname, '../completion.sh.hbs'), | ||
'utf-8' | ||
), | ||
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); | ||
return script.replace(/{{app_path}}/g, $0); | ||
}; | ||
script = script.replace(/{{app_name}}/g, name) | ||
return script.replace(/{{app_path}}/g, $0) | ||
} | ||
|
||
// register a function to perform your own custom | ||
// completions., this function can be either | ||
// synchrnous or asynchronous. | ||
var completionFunction = null; | ||
var completionFunction = null | ||
self.registerFunction = function (fn) { | ||
completionFunction = fn; | ||
completionFunction = fn | ||
} | ||
|
||
return self; | ||
}; | ||
return self | ||
} |
Oops, something went wrong.