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 11.0.0 to 11.1.0

11

index.js

@@ -7,4 +7,2 @@ const { Argument } = require('./lib/argument.js');

// @ts-check
/**

@@ -16,3 +14,3 @@ * Expose the root command.

exports.program = exports; // More explicit access to global command.
// Implicit export of createArgument, createCommand, and createOption.
// createArgument, createCommand, and createOption are implicitly available as they are methods on program.

@@ -23,8 +21,9 @@ /**

exports.Command = Command;
exports.Option = Option;
exports.Argument = Argument;
exports.Command = Command;
exports.Help = Help;
exports.CommanderError = CommanderError;
exports.Help = Help;
exports.InvalidArgumentError = InvalidArgumentError;
exports.InvalidOptionArgumentError = InvalidArgumentError; // Deprecated
exports.Option = Option;
const { InvalidArgumentError } = require('./error.js');
// @ts-check
class Argument {

@@ -69,3 +67,3 @@ /**

*
* @param {any} value
* @param {*} value
* @param {string} [description]

@@ -72,0 +70,0 @@ * @return {Argument}

@@ -1,3 +0,1 @@

// @ts-check
/**

@@ -4,0 +2,0 @@ * CommanderError class

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

// @ts-check
// Although this is a class, methods are static in style to allow override using subclass or just functions.

@@ -105,4 +103,4 @@ class Help {

const globalOptions = [];
for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {
const visibleOptions = parentCmd.options.filter((option) => !option.hidden);
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
globalOptions.push(...visibleOptions);

@@ -126,3 +124,3 @@ }

if (cmd._argsDescription) {
cmd._args.forEach(argument => {
cmd.registeredArguments.forEach(argument => {
argument.description = argument.description || cmd._argsDescription[argument.name()] || '';

@@ -133,4 +131,4 @@ });

// If there are any arguments with a description then return all the arguments.
if (cmd._args.find(argument => argument.description)) {
return cmd._args;
if (cmd.registeredArguments.find(argument => argument.description)) {
return cmd.registeredArguments;
}

@@ -149,3 +147,3 @@ return [];

// Legacy. Ignores custom usage string, and nested commands.
const args = cmd._args.map(arg => humanReadableArgName(arg)).join(' ');
const args = cmd.registeredArguments.map(arg => humanReadableArgName(arg)).join(' ');
return cmd._name +

@@ -248,7 +246,7 @@ (cmd._aliases[0] ? '|' + cmd._aliases[0] : '') +

}
let parentCmdNames = '';
for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {
parentCmdNames = parentCmd.name() + ' ' + parentCmdNames;
let ancestorCmdNames = '';
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
ancestorCmdNames = ancestorCmd.name() + ' ' + ancestorCmdNames;
}
return parentCmdNames + cmdName + ' ' + cmd.usage();
return ancestorCmdNames + cmdName + ' ' + cmd.usage();
}

@@ -255,0 +253,0 @@

const { InvalidArgumentError } = require('./error.js');
// @ts-check
class Option {

@@ -43,3 +41,3 @@ /**

*
* @param {any} value
* @param {*} value
* @param {string} [description]

@@ -63,3 +61,3 @@ * @return {Option}

*
* @param {any} arg
* @param {*} arg
* @return {Option}

@@ -280,3 +278,3 @@ */

*
* @param {any} value
* @param {*} value
* @param {Option} option

@@ -283,0 +281,0 @@ * @returns {boolean}

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

@@ -25,7 +25,7 @@ "keywords": [

"lint:typescript": "eslint typings/*.ts tests/*.ts",
"test": "jest && npm run test-typings",
"test": "jest && npm run typecheck-ts",
"test-esm": "node ./tests/esm-imports-test.mjs",
"test-typings": "tsd",
"typescript-checkJS": "tsc --allowJS --checkJS index.js lib/*.js --noEmit",
"test-all": "npm run test && npm run lint && npm run typescript-checkJS && npm run test-esm"
"typecheck-ts": "tsd && tsc -p tsconfig.ts.json",
"typecheck-js": "tsc -p tsconfig.js.json",
"test-all": "npm run test && npm run lint && npm run typecheck-js && npm run test-esm"
},

@@ -77,12 +77,2 @@ "files": [

"types": "typings/index.d.ts",
"jest": {
"testEnvironment": "node",
"collectCoverage": true,
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testPathIgnorePatterns": [
"/node_modules/"
]
},
"engines": {

@@ -89,0 +79,0 @@ "node": ">=16"

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

By default options on the command line are not positional, and can be specified before or after other arguments.
By default, options on the command line are not positional, and can be specified before or after other arguments.

@@ -238,3 +238,3 @@ There are additional related routines for when `.opts()` is not enough:

Multiple boolean short options may be combined together following the dash, and may be followed by a single short option taking a value.
Multiple boolean short options may be combined following the dash, and may be followed by a single short option taking a value.
For example `-d -s -p cheese` may be written as `-ds -p cheese` or even `-dsp cheese`.

@@ -332,3 +332,3 @@

For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-in-depth.md).

@@ -385,3 +385,3 @@ ### Required option

For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-in-depth.md).

@@ -553,2 +553,4 @@ ### Version option

`.command()` automatically copies the inherited settings from the parent command to the newly created subcommand. This is only done during creation, any later setting changes to the parent are not inherited.
For safety, `.addCommand()` does not automatically copy the inherited settings from the parent command. There is a helper routine `.copyInheritedSettings()` for copying the settings when they are wanted.

@@ -684,3 +686,3 @@

A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments will be reported as an error. You can suppress the unknown option checks with `.allowUnknownOption()`. By default it is not an error to
A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments will be reported as an error. You can suppress the unknown option checks with `.allowUnknownOption()`. By default, it is not an error to
pass more arguments than declared, but you can make this an error with `.allowExcessArguments(false)`.

@@ -773,3 +775,3 @@

Long descriptions are wrapped to fit the available width. (However, a description that includes a line-break followed by whitespace is assumed to be pre-formatted and not wrapped.)
Long descriptions are wrapped to fit the available width. (However, a description that includes a line-break followed by whitespace is assumed to be pre-formatted and not wrapped.)

@@ -862,4 +864,4 @@ ### Custom help

You may specify the program name using `.name()` or in the Command constructor. For the program, Commander will
fallback to using the script name from the full arguments passed into `.parse()`. However, the script name varies
depending on how your program is launched so you may wish to specify it explicitly.
fall back to using the script name from the full arguments passed into `.parse()`. However, the script name varies
depending on how your program is launched, so you may wish to specify it explicitly.

@@ -906,3 +908,3 @@ ```js

By default every command has a help option. You may change the default help flags and description. Pass false to disable the built-in help option.
By default, every command has a help option. You may change the default help flags and description. Pass false to disable the built-in help option.

@@ -981,3 +983,3 @@ ```js

By default program options are recognised before and after subcommands. To only look for program options before subcommands, use `.enablePositionalOptions()`. This lets you use
By default, program options are recognised before and after subcommands. To only look for program options before subcommands, use `.enablePositionalOptions()`. This lets you use
an option for a different purpose in subcommands.

@@ -994,4 +996,4 @@

By default options are recognised before and after command-arguments. To only process options that come
before the command-arguments, use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program
By default, options are recognised before and after command-arguments. To only process options that come
before the command-arguments, use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program
without needing to use `--` to end the option processing.

@@ -1009,5 +1011,5 @@ To use pass through options in a subcommand, the program needs to enable positional options.

By default the option processing shows an error for an unknown option. To have an unknown option treated as an ordinary command-argument and continue looking for options, use `.allowUnknownOption()`. This lets you mix known and unknown options.
By default, the option processing shows an error for an unknown option. To have an unknown option treated as an ordinary command-argument and continue looking for options, use `.allowUnknownOption()`. This lets you mix known and unknown options.
By default the argument processing does not display an error for more command-arguments than expected.
By default, the argument processing does not display an error for more command-arguments than expected.
To display an error for excess arguments, use`.allowExcessArguments(false)`.

@@ -1018,3 +1020,3 @@

Before Commander 7, the option values were stored as properties on the command.
This was convenient to code but the downside was possible clashes with
This was convenient to code, but the downside was possible clashes with
existing properties of `Command`. You can revert to the old behaviour to run unmodified legacy code by using `.storeOptionsAsProperties()`.

@@ -1043,3 +1045,3 @@

ts-node: If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g.
ts-node: If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g.

@@ -1074,3 +1076,3 @@ ```sh

If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al,
If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al.,
the inspector port is incremented by 1 for the spawned subcommand.

@@ -1082,3 +1084,3 @@

By default when you call your program using run-script, `npm` will parse any options on the command-line and they will not reach your program. Use
By default, when you call your program using run-script, `npm` will parse any options on the command-line and they will not reach your program. Use
`--` to stop the npm option parsing and pass through all the arguments.

@@ -1106,3 +1108,3 @@

By default Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
By default, Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
this behaviour and optionally supply a callback. The default override throws a `CommanderError`.

@@ -1123,3 +1125,3 @@

By default Commander is configured for a command-line application and writes to stdout and stderr.
By default, Commander is configured for a command-line application and writes to stdout and stderr.
You can modify this behaviour for custom applications. In addition, you can modify the display of error messages.

@@ -1150,3 +1152,3 @@

- [deprecated](./docs/deprecated.md) features still supported for backwards compatibility
- [options taking varying arguments](./docs/options-taking-varying-arguments.md)
- [options taking varying arguments](./docs/options-in-depth.md)
- [parsing life cycle and hooks](./docs/parsing-and-hooks.md)

@@ -1153,0 +1155,0 @@

@@ -8,2 +8,10 @@ // Type definitions for commander

// This is a trick to encourage editor to suggest the known literals while still
// allowing any BaseType value.
// References:
// - https://github.com/microsoft/TypeScript/issues/29729
// - https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
// - https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts
type LiteralUnion<LiteralType, BaseType extends string | number> = LiteralType | (BaseType & Record<never, never>);
export class CommanderError extends Error {

@@ -46,2 +54,5 @@ code: string;

variadic: boolean;
defaultValue?: any;
defaultValueDescription?: string;
argChoices?: string[];

@@ -99,2 +110,4 @@ /**

defaultValueDescription?: string;
presetArg?: unknown;
envVar?: string;
parseArg?: <T>(value: string, previous: T) => T;

@@ -278,3 +291,4 @@ hidden: boolean;

export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';
export type OptionValueSource = 'default' | 'config' | 'env' | 'cli' | 'implied';
// The source is a string so author can define their own too.
export type OptionValueSource = LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string> | undefined;

@@ -288,2 +302,3 @@ export type OptionValues = Record<string, any>;

readonly options: readonly Option[];
readonly registeredArguments: readonly Argument[];
parent: Command | null;

@@ -302,2 +317,6 @@

version(str: string, flags?: string, description?: string): this;
/**
* Get the program version.
*/
version(): string | undefined;

@@ -506,41 +525,17 @@ /**

/**
* Define option with `flags`, `description` and optional
* coercion `fn`.
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
*
* The `flags` string contains the short and/or long flags,
* separated by comma, a pipe or space. The following are all valid
* all will output this way when `--help` is used.
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
*
* "-p, --pepper"
* "-p|--pepper"
* "-p --pepper"
* See the README for more details, and see also addOption() and requiredOption().
*
* @example
* ```
* // simple boolean defaulting to false
* program.option('-p, --pepper', 'add pepper');
*
* --pepper
* program.pepper
* // => Boolean
*
* // simple boolean defaulting to true
* program.option('-C, --no-cheese', 'remove cheese');
*
* program.cheese
* // => true
*
* --no-cheese
* program.cheese
* // => false
*
* // required argument
* program.option('-C, --chdir <path>', 'change the working directory');
*
* --chdir /tmp
* program.chdir
* // => "/tmp"
*
* // optional argument
* program.option('-c, --cheese [type]', 'add cheese [marble]');
* ```js
* program
* .option('-p, --pepper', 'add pepper')
* .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
* ```

@@ -551,3 +546,3 @@ *

option(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
option<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
/** @deprecated since v7, instead use choices or a custom function */

@@ -563,3 +558,3 @@ option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;

requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
requiredOption<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
/** @deprecated since v7, instead use choices or a custom function */

@@ -831,3 +826,3 @@ requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;

*/
executableDir(): string;
executableDir(): string | null;

@@ -834,0 +829,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