
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
commander-completion
Advanced tools
Shell completion for Commander.js
This was built as part of foundry, a CLI utility for making releases painless.
$ npm pub|
$ npm publish |
Install the module with: npm install commander-completion
var program = require('commander-completion')(require('commander'));
program.name = 'git';
program
.command('checkout')
.completion(function (info, cb) {
// For `git checkout dev/|`
// info.words.value = ['git', 'checkout', 'dev/']
// info.word.partialLeft = 'dev/'
getGitBranches(function (err, allBranches) {
if (err) {
return cb(err);
}
var branches = allBranches.filter(function (branch) {
// 'chec' === 'chec' (from 'checkout')
return partialLeftWord === branch.substr(0, partialLeftWord.length);
});
cb(null, branches);
});
})
.action(function () {
// Checkout a git branch
});
program
.command('completion')
.action(function () {
program.completion({
line: process.env.COMP_LINE,
cursor: process.env.COMP_POINT
});
});
// Parse in arguments (e.g. `COMP_LINE="git che" COMP_POINT=7 git completion`)
// Logs: ['checkout']
program.parse(process.argv);
commander-completion exposes a mixin function, mixinCommanderCompletion, as its module.exports. After we mixin to Commander.js, we add more methods onto command() objects.
Currently, you are required to specify the name property of your program.
mixinCommanderCompletion(commander)Add new completion methods to Commander.js' Command objects
Object - Instance of Commander.jsCommand.completion(completionFn)New method available on Commander.js Commands (e.g. program.command('remote').completion(completionFn))
Save completion function to call when completing the current command
Function - Error-first callback that will callback with matches
-completion should have a signature of function (info, cb)
Object - Collection of distilled information about original input
Function - Error-first callback function to run with matches
cb has a signature of function (err, results)Command.complete(params, cb)New method available on Commander.js Commands (e.g. program.command('remote').complete(params, cb))
Get completion results for current command
Object - Information similar to that passed in by bash's tab completion
String - Input to complete against (similar to COMP_LINE)Number - Index within line of the cursor (similar to COMP_POINT)Function - Optional error-first callback function that receives matches
cb should have a signature of function (err, results)cb is not provided, err will be thrown and results will be printed to stdout via console.logAn full example of git would be
var program = require('commander-completion')(require('commander'));
program.name = 'git';
program
// `git checkout master`
.command('checkout')
.option('-b', 'Checkout new branch') // `git checkout -b dev/hai`
.completion(function (info, cb) {
// Get git branches and find matches
})
.action(function () {
// Checkout a `git` branch
});
var remote = program.command('remote');
remote
// `git remote add origin git@github.com:...`
// No possible tab completion here
.command('add')
.action(function () {
// Add a `git` remote
});
remote
// `git remote rm origin`
.command('rm')
.completion(function (info, cb) {
// Get git branches and find matches
})
.action(function () {
// Remove a `git` remote
});
program.complete({
// `git remo|add`
line: 'git remoadd',
cursor: 8
}, function (err, results) {
results; // ['remote']
});
program.complete({
// `git remote |`
line: 'git remote ',
cursor: 11
}, function (err, results) {
results; // ['add', 'rm']
});
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via npm run lint and test via npm test.
Support this project and others by twolfson via donations.
http://twolfson.com/support-me
As of Dec 16 2013, Todd Wolfson has released this repository and its contents to the public domain.
It has been released under the UNLICENSE.
FAQs
Shell completion for commander.js
The npm package commander-completion receives a total of 474 weekly downloads. As such, commander-completion popularity was classified as not popular.
We found that commander-completion demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.