Socket
Socket
Sign inDemoInstall

commander

Package Overview
Dependencies
Maintainers
4
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commander - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

LICENSE

12

History.md

@@ -0,1 +1,13 @@

2.7.0 / 2015-03-07
==================
* Fix git-style bug when installed globally. Close #335 #349 @zhiyelee
* Fix collisions when option and first arg have same name. Close #346 #347 @tonylukasavage
* Add support for camelCase on `opts()`. Close #353 @nkzawa
* Add node.js 0.12 and io.js to travis.yml
* Allow RegEx options. #337 @palanik
* Fixes exit code when sub-command failing. Close #260 #332 @pirelenito
* git-style `bin` files in $PATH make sense. Close #196 #327 @zhiyelee
2.6.0 / 2014-12-30

@@ -2,0 +14,0 @@ ==================

61

index.js

@@ -8,5 +8,7 @@

var spawn = require('child_process').spawn;
var readlink = require('graceful-readlink').readlinkSync;
var path = require('path');
var dirname = path.dirname;
var basename = path.basename;
var fs = require('fs');

@@ -290,4 +292,4 @@ /**

};
this.parent.on(this._name, listener);
if (this._alias) this.parent.on(this._alias, listener);
this.parent.on('action_' + this._name, listener);
if (this._alias) this.parent.on('action_' + this._alias, listener);
return this;

@@ -353,4 +355,13 @@ };

if (typeof fn != 'function') {
defaultValue = fn;
fn = null;
if (fn instanceof RegExp) {
var regex = fn;
fn = function(val, def) {
var m = regex.exec(val);
return m ? m[0] : def;
}
}
else {
defaultValue = fn;
fn = null;
}
}

@@ -463,12 +474,31 @@

// executable
var dir = dirname(argv[1]);
var bin = basename(argv[1], '.js') + '-' + args[0];
var f = argv[1];
var link = readlink(f);
if (link !== f && link.charAt(0) !== '/') {
link = path.join(dirname(f), link)
}
var dir = dirname(link);
var bin = basename(f, '.js') + '-' + args[0];
// check for ./<bin> first
// prefer local `./<bin>` to bin in the $PATH
var local = path.join(dir, bin);
try {
// for versions before node v0.8 when there weren't `fs.existsSync`
if (fs.statSync(local).isFile()) {
bin = local;
}
} catch (e) {}
// run it
args = args.slice(1);
args.unshift(local);
var proc = spawn('node', args, { stdio: 'inherit', customFds: [0, 1, 2] });
var proc;
if (process.platform !== 'win32') {
proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] });
} else {
args.unshift(local);
proc = spawn(process.execPath, args, { stdio: 'inherit'});
}
proc.on('close', process.exit.bind(process));
proc.on('error', function(err) {

@@ -480,2 +510,3 @@ if (err.code == "ENOENT") {

}
process.exit(1);
});

@@ -545,4 +576,4 @@

name = args[0];
if (this.listeners(name).length) {
this.emit(args.shift(), args, unknown);
if (this.listeners('action_' + name).length) {
this.emit('action_' + args.shift(), args, unknown);
} else {

@@ -670,3 +701,3 @@ this.emit('*', args);

for (var i = 0 ; i < len; i++) {
var key = this.options[i].name();
var key = camelcase(this.options[i].name());
result[key] = key === 'version' ? this._version : this[key];

@@ -718,3 +749,3 @@ }

Command.prototype.unknownOption = function(flag) {
if(this._allowUnknownOption) return;
if (this._allowUnknownOption) return;
console.error();

@@ -823,3 +854,3 @@ console.error(" error: unknown option `%s'", flag);

Command.prototype.name = function(name) {
Command.prototype.name = function() {
return this._name;

@@ -919,3 +950,3 @@ };

var cmdName = this._name;
if(this._alias) {
if (this._alias) {
cmdName = cmdName + '|' + this._alias;

@@ -922,0 +953,0 @@ }

{
"name": "commander"
, "version": "2.6.0"
, "description": "the complete solution for node.js command-line programs"
, "keywords": ["command", "option", "parser", "prompt"]
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
, "license": "MIT"
, "repository": { "type": "git", "url": "https://github.com/tj/commander.js.git" }
, "devDependencies": { "should": ">= 0.0.1" }
, "scripts": { "test": "make test" }
, "main": "index"
, "engines": { "node": ">= 0.6.x" }
, "files": ["index.js"]
"name": "commander",
"version": "2.7.0",
"description": "the complete solution for node.js command-line programs",
"keywords": [
"command",
"option",
"parser"
],
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/tj/commander.js.git"
},
"devDependencies": {
"should": ">= 0.0.1"
},
"scripts": {
"test": "make test"
},
"main": "index",
"engines": {
"node": ">= 0.6.x"
},
"files": [
"index.js"
],
"dependencies": {
"graceful-readlink": ">= 1.0.0"
}
}
# Commander.js
[![Build Status](https://api.travis-ci.org/tj/commander.js.svg)](http://travis-ci.org/tj/commander.js)
[![Build Status](https://api.travis-ci.org/tj/commander.js.svg)](http://travis-ci.org/tj/commander.js)
[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![Join the chat at https://gitter.im/tj/commander.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

@@ -89,2 +91,14 @@ The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/tj/commander).

## Regular Expression
```js
program
.version('0.0.1')
.option('-s --size <size>', 'Pizza size', /^(large|medium|small)$/i, 'medium')
.option('-d --drink [drink]', 'Drink', /^(coke|pepsi|izze)$/i)
.parse(process.argv);
console.log(' size: %j', program.size);
console.log(' drink: %j', program.drink);
```
## Variadic arguments

@@ -137,4 +151,6 @@

When `.command()` is invoked with a description argument, no `.action(callback)` should be called to handle sub-commands, otherwise there will be an error. This tells commander that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools.
The commander will try to find the executable script in __current directory__ with the name `scriptBasename-subcommand`, like `pm-install`, `pm-search`.
The commander will try to search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-command`, like `pm-install`, `pm-search`.
If the program is designed to installed globally, make sure the executables have proper modes, like `755`.
## Automated --help

@@ -226,4 +242,19 @@

Output help information without exiting.
Output help information without exiting.
If you want to display help by default (e.g. if no command was provided), you can use something like:
```js
var program = require('commander');
program
.version('0.0.1')
.command('getstream [url]', 'get stream URL')
.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp();
}
```
## .help()

@@ -278,27 +309,7 @@

You can see more Demos in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
More Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
## License
(The MIT License)
MIT
Copyright (c) 2011 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc