Socket
Socket
Sign inDemoInstall

commander

Package Overview
Dependencies
0
Maintainers
4
Versions
114
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 12.0.0-0 to 12.0.0-1

33

lib/help.js

@@ -29,9 +29,4 @@ const { humanReadableArgName } = require('./argument.js');

const visibleCommands = cmd.commands.filter(cmd => !cmd._hidden);
if (cmd._hasImplicitHelpCommand()) {
// Create a command matching the implicit help command.
const [, helpName, helpArgs] = cmd._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/);
const helpCommand = cmd.createCommand(helpName)
.helpOption(false);
helpCommand.description(cmd._helpCommandDescription);
if (helpArgs) helpCommand.arguments(helpArgs);
const helpCommand = cmd._getHelpCommand();
if (helpCommand && !helpCommand._hidden) {
visibleCommands.push(helpCommand);

@@ -72,15 +67,15 @@ }

const visibleOptions = cmd.options.filter((option) => !option.hidden);
// Implicit help
const showShortHelpFlag = cmd._hasHelpOption && cmd._helpShortFlag && !cmd._findOption(cmd._helpShortFlag);
const showLongHelpFlag = cmd._hasHelpOption && !cmd._findOption(cmd._helpLongFlag);
if (showShortHelpFlag || showLongHelpFlag) {
let helpOption;
if (!showShortHelpFlag) {
helpOption = cmd.createOption(cmd._helpLongFlag, cmd._helpDescription);
} else if (!showLongHelpFlag) {
helpOption = cmd.createOption(cmd._helpShortFlag, cmd._helpDescription);
} else {
helpOption = cmd.createOption(cmd._helpFlags, cmd._helpDescription);
// Built-in help option.
const helpOption = cmd._getHelpOption();
if (helpOption && !helpOption.hidden) {
// Automatically hide conflicting flags. Bit dubious but a historical behaviour that is convenient for single-command programs.
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
if (!removeShort && !removeLong) {
visibleOptions.push(helpOption); // no changes needed
} else if (helpOption.long && !removeLong) {
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
} else if (helpOption.short && !removeShort) {
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
}
visibleOptions.push(helpOption);
}

@@ -87,0 +82,0 @@ if (this.sortOptions) {

@@ -77,3 +77,3 @@ const { InvalidArgumentError } = require('./error.js');

*
* @param {string | string[]} names
* @param {(string | string[])} names
* @return {Option}

@@ -328,3 +328,2 @@ */

exports.Option = Option;
exports.splitOptionFlags = splitOptionFlags;
exports.DualOptions = DualOptions;
{
"name": "commander",
"version": "12.0.0-0",
"version": "12.0.0-1",
"description": "the complete solution for node.js command-line programs",

@@ -19,3 +19,3 @@ "keywords": [

"type": "git",
"url": "https://github.com/tj/commander.js.git"
"url": "git+https://github.com/tj/commander.js.git"
},

@@ -66,3 +66,3 @@ "scripts": {

"eslint-config-standard": "^17.0.0",
"eslint-config-standard-with-typescript": "^39.1.1",
"eslint-config-standard-with-typescript": "^40.0.0",
"eslint-plugin-import": "^2.26.0",

@@ -69,0 +69,0 @@ "eslint-plugin-jest": "^27.1.7",

@@ -40,3 +40,3 @@ # Commander.js

- [.helpOption(flags, description)](#helpoptionflags-description)
- [.addHelpCommand()](#addhelpcommand)
- [.helpCommand()](#helpcommand)
- [More configuration](#more-configuration-2)

@@ -908,12 +908,16 @@ - [Custom event listeners](#custom-event-listeners)

### .addHelpCommand()
(Or use `.addHelpOption()` to add an option you construct yourself.)
A help command is added by default if your command has subcommands. You can explicitly turn on or off the implicit help command with `.addHelpCommand()` and `.addHelpCommand(false)`.
### .helpCommand()
A help command is added by default if your command has subcommands. You can explicitly turn on or off the implicit help command with `.helpCommand(true)` and `.helpCommand(false)`.
You can both turn on and customise the help command by supplying the name and description:
```js
program.addHelpCommand('assist [command]', 'show assistance');
program.helpCommand('assist [command]', 'show assistance');
```
(Or use `.addHelpCommand()` to add a command you construct yourself.)
### More configuration

@@ -920,0 +924,0 @@

@@ -422,16 +422,25 @@ // Type definitions for commander

/**
* Override default decision whether to add implicit help command.
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
*
* @example
* ```ts
* program.helpCommand('help [cmd]');
* program.helpCommand('help [cmd]', 'show help');
* program.helpCommand(false); // suppress default help command
* program.helpCommand(true); // add help command even if no subcommands
* ```
* addHelpCommand() // force on
* addHelpCommand(false); // force off
* addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
* ```
*
* @returns `this` command for chaining
*/
addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;
helpCommand(nameAndArgs: string, description?: string): this;
helpCommand(enable: boolean): this;
/**
* Add prepared custom help command.
*/
addHelpCommand(cmd: Command): this;
/** @deprecated since v12, instead use helpCommand */
addHelpCommand(nameAndArgs: string, description?: string): this;
/** @deprecated since v12, instead use helpCommand */
addHelpCommand(enable?: boolean): this;
/**
* Add hook for life cycle event.

@@ -843,2 +852,8 @@ */

/**
* Supply your own option to use for the built-in help option.
* This is an alternative to using helpOption() to customise the flags and description etc.
*/
addHelpOption(option: Option): this;
/**
* Output help information and exit.

@@ -845,0 +860,0 @@ *

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc