Socket
Socket
Sign inDemoInstall

commander

Package Overview
Dependencies
Maintainers
6
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 6.0.0 to 6.1.0

30

CHANGELOG.md

@@ -11,2 +11,19 @@ # Changelog

## [6.1.0] (2020-08-28)
### Added
- include URL to relevant section of README for error for potential conflict between Command properties and option values ([#1306])
- `.combineFlagAndOptionalValue(false)` to ease upgrade path from older versions of Commander ([#1326])
- allow disabling the built-in help option using `.helpOption(false)` ([#1325])
- allow just some arguments in `argumentDescription` to `.description()` ([#1323])
### Changed
- tidy async test and remove lint override ([#1312])
### Fixed
- executable subcommand launching when script path not known ([#1322])
## [6.0.0] (2020-07-21)

@@ -18,3 +35,4 @@

- allow options to be added with just a short flag ([#1256])
- throw an error if there might be a clash between option name and a Command property, with advice on how to resolve ([#1275])
- *Breaking* the option property has same case as flag. e.g. flag `-n` accessed as `opts().n` (previously uppercase)
- *Breaking* throw an error if there might be a clash between option name and a Command property, with advice on how to resolve ([#1275])

@@ -118,2 +136,5 @@ ### Fixed

If you want to continue combining short options with optional values as though they were boolean flags, set `combineFlagAndOptionalValue(false)`
to expand `-fb` to `-f -b` rather than `-f b`.
## [5.0.0-4] (2020-03-03)

@@ -287,4 +308,11 @@

[#1301]: https://github.com/tj/commander.js/issues/1301
[#1306]: https://github.com/tj/commander.js/pull/1306
[#1312]: https://github.com/tj/commander.js/pull/1312
[#1322]: https://github.com/tj/commander.js/pull/1322
[#1323]: https://github.com/tj/commander.js/pull/1323
[#1325]: https://github.com/tj/commander.js/pull/1325
[#1326]: https://github.com/tj/commander.js/pull/1326
[Unreleased]: https://github.com/tj/commander.js/compare/master...develop
[6.1.0]: https://github.com/tj/commander.js/compare/v6.0.0..v6.1.0
[6.0.0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0

@@ -291,0 +319,0 @@ [6.0.0-0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0-0

74

index.js

@@ -130,4 +130,6 @@ /**

this._aliases = [];
this._combineFlagAndOptionalValue = true;
this._hidden = false;
this._hasHelpOption = true;
this._helpFlags = '-h, --help';

@@ -188,2 +190,3 @@ this._helpDescription = 'display help for command';

cmd._hidden = !!(opts.noHelp || opts.hidden);
cmd._hasHelpOption = this._hasHelpOption;
cmd._helpFlags = this._helpFlags;

@@ -199,2 +202,3 @@ cmd._helpDescription = this._helpDescription;

cmd._passCommandToAction = this._passCommandToAction;
cmd._combineFlagAndOptionalValue = this._combineFlagAndOptionalValue;

@@ -474,3 +478,5 @@ cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor

- or call storeOptionsAsProperties(true) to suppress this check,
- or change option name`);
- or change option name
Read more on https://git.io/JJc0W`);
}

@@ -642,2 +648,19 @@ };

/**
* Alter parsing of short flags with optional values.
*
* Examples:
*
* // for `.option('-f,--flag [value]'):
* .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
* .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
*
* @param {Boolean} [arg] - if `true` or omitted, an optional value can be specified directly after the flag.
* @api public
*/
combineFlagAndOptionalValue(arg) {
this._combineFlagAndOptionalValue = (arg === undefined) || arg;
return this;
};
/**
* Allow unknown options on the command line.

@@ -829,3 +852,7 @@ *

// Want the entry script as the reference for command name and directory for searching for other files.
const scriptPath = this._scriptPath;
let scriptPath = this._scriptPath;
// Fallback in case not set, due to how Command created or called.
if (!scriptPath && process.mainModule) {
scriptPath = process.mainModule.filename;
}

@@ -1112,3 +1139,3 @@ let baseDir;

if (option) {
if (option.required || option.optional) {
if (option.required || (option.optional && this._combineFlagAndOptionalValue)) {
// option with value following in same argument

@@ -1240,3 +1267,4 @@ this.emit(`option:${option.name()}`, arg.slice(2));

const fullCommand = partCommands.join(' ');
const message = `error: unknown command '${this.args[0]}'. See '${fullCommand} ${this._helpLongFlag}'.`;
const message = `error: unknown command '${this.args[0]}'.` +
(this._hasHelpOption ? ` See '${fullCommand} ${this._helpLongFlag}'.` : '');
console.error(message);

@@ -1350,5 +1378,7 @@ this._exit(1, 'commander.unknownCommand', message);

});
return '[options]' +
(this.commands.length ? ' [command]' : '') +
(this._args.length ? ' ' + args.join(' ') : '');
return [].concat(
(this.options.length || this._hasHelpOption ? '[options]' : []),
(this.commands.length ? '[command]' : []),
(this._args.length ? args : [])
).join(' ');
}

@@ -1496,4 +1526,4 @@

// Implicit help
const showShortHelpFlag = this._helpShortFlag && !this._findOption(this._helpShortFlag);
const showLongHelpFlag = !this._findOption(this._helpLongFlag);
const showShortHelpFlag = this._hasHelpOption && this._helpShortFlag && !this._findOption(this._helpShortFlag);
const showLongHelpFlag = this._hasHelpOption && !this._findOption(this._helpLongFlag);
if (showShortHelpFlag || showLongHelpFlag) {

@@ -1561,3 +1591,3 @@ let helpFlags = this._helpFlags;

this._args.forEach((arg) => {
desc.push(' ' + pad(arg.name, width) + ' ' + wrap(argsDescription[arg.name], descriptionWidth, width + 4));
desc.push(' ' + pad(arg.name, width) + ' ' + wrap(argsDescription[arg.name] || '', descriptionWidth, width + 4));
});

@@ -1585,7 +1615,10 @@ desc.push('');

const options = [
'Options:',
'' + this.optionHelp().replace(/^/gm, ' '),
''
];
let options = [];
if (this._hasHelpOption || this.options.length > 0) {
options = [
'Options:',
'' + this.optionHelp().replace(/^/gm, ' '),
''
];
}

@@ -1624,5 +1657,6 @@ return usage

* You can pass in flags and a description to override the help
* flags and help description for your command.
* flags and help description for your command. Pass in false to
* disable the built-in help option.
*
* @param {string} [flags]
* @param {string | boolean} [flags]
* @param {string} [description]

@@ -1634,2 +1668,6 @@ * @return {Command} `this` command for chaining

helpOption(flags, description) {
if (typeof flags === 'boolean') {
this._hasHelpOption = flags;
return this;
}
this._helpFlags = flags || this._helpFlags;

@@ -1767,3 +1805,3 @@ this._helpDescription = description || this._helpDescription;

function outputHelpIfRequested(cmd, args) {
const helpOption = args.find(arg => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
const helpOption = cmd._hasHelpOption && args.find(arg => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
if (helpOption) {

@@ -1770,0 +1808,0 @@ cmd.outputHelp();

{
"name": "commander",
"version": "6.0.0",
"version": "6.1.0",
"description": "the complete solution for node.js command-line programs",

@@ -5,0 +5,0 @@ "keywords": [

@@ -379,14 +379,7 @@ # Commander.js

.action(function (cmd, env) {
cmdValue = cmd;
envValue = env;
console.log('command:', cmdValue);
console.log('environment:', envValue || 'no environment given');
});
program.parse(process.argv);
if (typeof cmdValue === 'undefined') {
console.error('no command given!');
process.exit(1);
}
console.log('command:', cmdValue);
console.log('environment:', envValue || "no environment given");
```

@@ -570,3 +563,3 @@

Override the default help flags and description.
Override the default help flags and description. Pass false to disable the built-in help option.

@@ -573,0 +566,0 @@ ```js

@@ -205,2 +205,14 @@ // Type definitions for commander

/**
* Alter parsing of short flags with optional values.
*
* @example
* // for `.option('-f,--flag [value]'):
* .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
* .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
*
* @returns `this` command for chaining
*/
combineFlagAndOptionalValue(arg?: boolean): this;
/**
* Allow unknown options on the command line.

@@ -339,5 +351,6 @@ *

* You can pass in flags and a description to override the help
* flags and help description for your command.
* flags and help description for your command. Pass in false
* to disable the built-in help option.
*/
helpOption(flags?: string, description?: string): this;
helpOption(flags?: string | boolean, description?: string): this;

@@ -344,0 +357,0 @@ /**

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