Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tj/commander.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.19.0
Choose a base ref
...
head repository: tj/commander.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.20.0
Choose a head ref
  • 18 commits
  • 13 files changed
  • 9 contributors

Commits on Oct 9, 2018

  1. Add extension to .eslintrc

    ManoelLobo authored and roman-vanesyan committed Oct 9, 2018
    Copy the full SHA
    700130e View commit details

Commits on Oct 21, 2018

  1. Added missing semicolon

    reviewher committed Oct 21, 2018
    Copy the full SHA
    f054510 View commit details
  2. Merge pull request #882 from reviewher/patch-1

    Added missing semicolon
    abetomo authored Oct 21, 2018
    Copy the full SHA
    27aeac1 View commit details

Commits on Nov 22, 2018

  1. Added example of receiving args from options

    Updated file to give example and how to manage arguments using options parsing.
    codyj110 authored and roman-vanesyan committed Nov 22, 2018
    Copy the full SHA
    03f7d38 View commit details
  2. Update Readme.md

    removed <br> not needed
    codyj110 authored and roman-vanesyan committed Nov 22, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d240081 View commit details

Commits on Dec 28, 2018

  1. Copy the full SHA
    cec57f5 View commit details
  2. fix url 🚧

    jamesgeorge007 authored and roman-vanesyan committed Dec 28, 2018
    Copy the full SHA
    82d0d0a View commit details

Commits on Feb 19, 2019

  1. Copy the full SHA
    68545af View commit details

Commits on Mar 2, 2019

  1. Update Readme.md

    remove the white space otherwise run `-m xxx` the  `program.myarg` would be `undefined`
    ForJing authored Mar 2, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    77bb580 View commit details
  2. Merge pull request #924 from ForJing/patch-1

    Update Readme.md
    abetomo authored Mar 2, 2019
    Copy the full SHA
    4542306 View commit details

Commits on Mar 14, 2019

  1. Update index.d.ts

    Add the optional parameter `argsDescription` to description() function
    kira1928 committed Mar 14, 2019
    Copy the full SHA
    e31bb8a View commit details
  2. Copy the full SHA
    a679949 View commit details
  3. some more fix.

    kira1928 committed Mar 14, 2019
    Copy the full SHA
    a469137 View commit details

Commits on Mar 15, 2019

  1. Merge pull request #930 from kira1928/update-index.d.ts

    Update index.d.ts
    abetomo authored Mar 15, 2019
    Copy the full SHA
    291fc04 View commit details

Commits on Mar 22, 2019

  1. fix: resolve symbol links until their are no more symbolic links

    Depending on your npm / yarn set up a global install may have to resolve
    through several symlinks before it correctly arrives the the baseDir
    that actually contains the other subcommands.
    
    The changes the resolution logic to resolve symlinks until their are no
    more to resolve by using realpath which will resolve links all the way
    to the final destination.
    MarshallOfSound committed Mar 22, 2019
    Copy the full SHA
    994d24d View commit details

Commits on Apr 1, 2019

  1. Merge pull request #935 from MarshallOfSound/fix-deep-sym-link-resolu…

    …tion
    
    fix: resolve symbolic links completely when hunting for subcommands
    abetomo authored Apr 1, 2019
    Copy the full SHA
    50922d8 View commit details

Commits on Apr 2, 2019

  1. version bump 2.20.0

    abetomo committed Apr 2, 2019
    Copy the full SHA
    1ffcbef View commit details

Commits on Apr 3, 2019

  1. Merge pull request #946 from abetomo/version_bump_2.20.0

    version bump 2.20.0
    abetomo authored Apr 3, 2019
    Copy the full SHA
    3e8bf54 View commit details
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "standard",
"rules": {
"one-var": "off",
"semi": ["error", "always"],
"space-before-function-paren": ["error", "never"]
}
}
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@

2.20.0 / 2019-04-02
==================

* fix: resolve symbolic links completely when hunting for subcommands (#935)
* Update index.d.ts (#930)
* Update Readme.md (#924)
* Remove --save option as it isn't required anymore (#918)
* Add link to the license file (#900)
* Added example of receiving args from options (#858)
* Added missing semicolon (#882)
* Add extension to .eslintrc (#876)

2.19.0 / 2018-10-02
==================

15 changes: 13 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@

## Installation

$ npm install commander --save
$ npm install commander

## Option parsing

@@ -65,6 +65,17 @@ if (program.sauce) console.log(' with sauce');
else console.log(' without sauce');
```

To get string arguments from options you will need to use angle brackets <> for required inputs or square brackets [] for optional inputs.

e.g. ```.option('-m --myarg [myVar]', 'my super cool description')```

Then to access the input if it was passed in.

e.g. ```var myInput = program.myarg```

**NOTE**: If you pass a argument without using brackets the example above will return true and not the value passed in.


## Version option

Calling the `version` implicitly adds the `-V` and `--version` options to the command.
@@ -414,4 +425,4 @@ More Demos can be found in the [examples](https://github.com/tj/commander.js/tre

## License

MIT
[MIT](https://github.com/tj/commander.js/blob/master/LICENSE)
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -527,14 +527,11 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {

// In case of globally installed, get the base dir where executable
// subcommand file should be located at
var baseDir,
link = fs.lstatSync(f).isSymbolicLink() ? fs.readlinkSync(f) : f;
var baseDir;

// when symbolink is relative path
if (link !== f && link.charAt(0) !== '/') {
link = path.join(dirname(f), link);
}
baseDir = dirname(link);
var resolvedLink = fs.realpathSync(f);

baseDir = dirname(resolvedLink);

// prefer local `./<bin>` to bin in the $PATH
var localBin = path.join(baseDir, bin);
@@ -664,7 +661,7 @@ Command.prototype.parseArgs = function(args, unknown) {
this.unknownOption(unknown[0]);
}
if (this.commands.length === 0 &&
this._args.filter(function(a) { return a.required }).length === 0) {
this._args.filter(function(a) { return a.required; }).length === 0) {
this.emit('command:*');
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commander",
"version": "2.19.0",
"version": "2.20.0",
"description": "the complete solution for node.js command-line programs",
"keywords": [
"commander",
1 change: 1 addition & 0 deletions test/fixtures/another-dir/pm
1 change: 1 addition & 0 deletions test/fixtures/other-dir/pm
7 changes: 7 additions & 0 deletions test/test.command.executableSubcommand.js
Original file line number Diff line number Diff line change
@@ -34,3 +34,10 @@ var bin = path.join(__dirname, './fixtures/pmlink')
exec(bin + ' install', function (error, stdout, stderr) {
stdout.should.equal('install\n');
});

// when `bin` is a symbol link pointing at a symbolic for mocking global install
var bin = path.join(__dirname, './fixtures/another-dir/pm')
// success case
exec(bin + ' install', function (error, stdout, stderr) {
stdout.should.equal('install\n');
});
7 changes: 7 additions & 0 deletions test/test.command.executableSubcommandAlias.js
Original file line number Diff line number Diff line change
@@ -26,3 +26,10 @@ var bin = path.join(__dirname, './fixtures/pmlink')
exec(bin + ' i', function (error, stdout, stderr) {
stdout.should.equal('install\n');
});

// when `bin` is a symbol link pointing at a symbolic for mocking global install
var bin = path.join(__dirname, './fixtures/another-dir/pm')
// success case
exec(bin + ' install', function (error, stdout, stderr) {
stdout.should.equal('install\n');
});
7 changes: 7 additions & 0 deletions test/test.command.executableSubcommandDefault.js
Original file line number Diff line number Diff line change
@@ -44,3 +44,10 @@ var bin = path.join(__dirname, './fixtures/pmlink')
exec(bin + ' install', function (error, stdout, stderr) {
stdout.should.equal('install\n');
});

// when `bin` is a symbol link pointing at a symbolic for mocking global install
var bin = path.join(__dirname, './fixtures/another-dir/pm')
// success case
exec(bin + ' install', function (error, stdout, stderr) {
stdout.should.equal('install\n');
});
3 changes: 2 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -226,9 +226,10 @@ declare namespace local {
* Set the description to `str`.
*
* @param {string} str
* @param {{[argName: string]: string}} argsDescription
* @return {(Command | string)}
*/
description(str: string): Command;
description(str: string, argsDescription?: {[argName: string]: string}): Command;
description(): string;

/**