Socket
Socket
Sign inDemoInstall

@rushstack/ts-command-line

Package Overview
Dependencies
Maintainers
3
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rushstack/ts-command-line - npm Package Compare versions

Comparing version 4.14.0 to 4.15.0

9

dist/ts-command-line.d.ts

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

export declare abstract class CommandLineParameter {
private _shortNameValue;
/* Excluded from this release type: _parserKey */

@@ -234,4 +235,2 @@ /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */

readonly scopedLongName: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
readonly shortName: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */

@@ -250,3 +249,6 @@ readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;

/* Excluded from this release type: __constructor */
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
get shortName(): string | undefined;
/* Excluded from this release type: _setValue */
/* Excluded from this release type: _disableShortName */
/* Excluded from this release type: _getSupplementaryNotes */

@@ -309,3 +311,5 @@ /**

private readonly _parametersByLongName;
private readonly _parametersByShortName;
private readonly _parameterGroupsByName;
private readonly _ambiguousParameterNamesByParserKey;
private _parametersRegistered;

@@ -490,2 +494,3 @@ private _parametersProcessed;

/* Excluded from this release type: _registerParameter */
private _registerAmbiguousParameter;
private _generateKey;

@@ -492,0 +497,0 @@ private _getParameter;

@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.

"packageName": "@microsoft/api-extractor",
"packageVersion": "7.35.1"
"packageVersion": "7.35.2"
}
]
}

@@ -28,2 +28,3 @@ import type { SCOPING_PARAMETER_GROUP } from '../Constants';

export declare abstract class CommandLineParameter {
private _shortNameValue;
/**

@@ -41,4 +42,2 @@ * A unique internal key used to retrieve the value from the parser's dictionary.

readonly scopedLongName: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
readonly shortName: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */

@@ -58,2 +57,4 @@ readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;

constructor(definition: IBaseCommandLineDefinition);
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
get shortName(): string | undefined;
/**

@@ -65,2 +66,7 @@ * Called internally by CommandLineParameterProvider._processParsedData()

/**
* Called internally by CommandLineParameterProvider._registerDefinedParameters()
* @internal
*/
_disableShortName(): void;
/**
* Returns additional text used by the help formatter.

@@ -67,0 +73,0 @@ * @internal

@@ -57,3 +57,3 @@ "use strict";

this.longName = definition.parameterLongName;
this.shortName = definition.parameterShortName;
this._shortNameValue = definition.parameterShortName;
this.parameterGroup = definition.parameterGroup;

@@ -109,3 +109,14 @@ this.parameterScope = definition.parameterScope;

}
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
get shortName() {
return this._shortNameValue;
}
/**
* Called internally by CommandLineParameterProvider._registerDefinedParameters()
* @internal
*/
_disableShortName() {
this._shortNameValue = undefined;
}
/**
* Returns additional text used by the help formatter.

@@ -112,0 +123,0 @@ * @internal

@@ -50,3 +50,5 @@ import * as argparse from 'argparse';

private readonly _parametersByLongName;
private readonly _parametersByShortName;
private readonly _parameterGroupsByName;
private readonly _ambiguousParameterNamesByParserKey;
private _parametersRegistered;

@@ -240,2 +242,3 @@ private _parametersProcessed;

protected _registerParameter(parameter: CommandLineParameter, useScopedLongName: boolean): void;
private _registerAmbiguousParameter;
private _generateKey;

@@ -242,0 +245,0 @@ private _getParameter;

@@ -55,3 +55,5 @@ "use strict";

this._parametersByLongName = new Map();
this._parametersByShortName = new Map();
this._parameterGroupsByName = new Map();
this._ambiguousParameterNamesByParserKey = new Map();
this._parametersRegistered = false;

@@ -322,8 +324,26 @@ this._parametersProcessed = false;

this._parametersRegistered = true;
const ambiguousParameterNames = new Set();
// First, loop through all parameters with short names. If there are any duplicates, disable the short names
// since we can't prefix scopes to short names in order to deduplicate them. The duplicate short names will
// be reported as errors if the user attempts to use them.
for (const [shortName, shortNameParameters] of this._parametersByShortName.entries()) {
if (shortNameParameters.length > 1) {
for (const parameter of shortNameParameters) {
ambiguousParameterNames.add(shortName);
parameter._disableShortName();
}
}
}
// Then, loop through all parameters and register them. If there are any duplicates, ensure that they have
// provided a scope and register them with the scope. The duplicate long names will be reported as an error
// if the user attempts to use them.
for (const longNameParameters of this._parametersByLongName.values()) {
const useScopedLongName = longNameParameters.length > 1;
for (const parameter of longNameParameters) {
if (useScopedLongName && !parameter.parameterScope) {
throw new Error(`The parameter "${parameter.longName}" is defined multiple times with the same long name. ` +
'Parameters with the same long name must define a scope.');
if (useScopedLongName) {
if (!parameter.parameterScope) {
throw new Error(`The parameter "${parameter.longName}" is defined multiple times with the same long name. ` +
'Parameters with the same long name must define a scope.');
}
ambiguousParameterNames.add(parameter.longName);
}

@@ -333,2 +353,7 @@ this._registerParameter(parameter, useScopedLongName);

}
// Register silent parameters for the ambiguous short names and long names to ensure that users are made
// aware that the provided argument is ambiguous.
for (const ambiguousParameterName of ambiguousParameterNames) {
this._registerAmbiguousParameter(ambiguousParameterName);
}
// Need to add the remainder parameter last

@@ -352,2 +377,59 @@ if (this._remainder) {

}
// Search for any ambiguous parameters and throw an error if any are found
for (const [parserKey, parameterName] of this._ambiguousParameterNamesByParserKey) {
if (data[parserKey]) {
// Determine if the ambiguous parameter is a short name or a long name, since the process of finding
// the non-ambiguous name is different for each.
const duplicateShortNameParameters = this._parametersByShortName.get(parameterName);
if (duplicateShortNameParameters) {
// We also need to make sure we get the non-ambiguous long name for the parameter, since it is
// possible for that the long name is ambiguous as well.
const nonAmbiguousLongNames = [];
for (const parameter of duplicateShortNameParameters) {
const matchingLongNameParameters = this._parametersByLongName.get(parameter.longName);
if (!(matchingLongNameParameters === null || matchingLongNameParameters === void 0 ? void 0 : matchingLongNameParameters.length)) {
// This should never happen
throw new Error(`Unable to find long name parameters for ambiguous short name parameter "${parameterName}".`);
}
// If there is more than one matching long name parameter, then we know that we need to use the
// scoped long name for the parameter. The scoped long name should always be provided.
if (matchingLongNameParameters.length > 1) {
if (!parameter.scopedLongName) {
// This should never happen
throw new Error(`Unable to find scoped long name for ambiguous short name parameter "${parameterName}".`);
}
nonAmbiguousLongNames.push(parameter.scopedLongName);
}
else {
nonAmbiguousLongNames.push(parameter.longName);
}
}
// Throw an error including the non-ambiguous long names for the parameters that have the ambiguous
// short name, ex.
// Error: The short parameter name "-p" is ambiguous. It could refer to any of the following
// parameters: "--param1", "--param2"
throw new Error(`The short parameter name "${parameterName}" is ambiguous. It could refer to any of ` +
`the following parameters: "${nonAmbiguousLongNames.join('", "')}"`);
}
const duplicateLongNameParameters = this._parametersByLongName.get(parameterName);
if (duplicateLongNameParameters) {
const nonAmbiguousLongNames = duplicateLongNameParameters.map((p) => {
// The scoped long name should always be provided
if (!p.scopedLongName) {
// This should never happen
throw new Error(`Unable to find scoped long name for ambiguous long name parameter "${parameterName}".`);
}
return p.scopedLongName;
});
// Throw an error including the non-ambiguous scoped long names for the parameters that have the
// ambiguous long name, ex.
// Error: The parameter name "--param" is ambiguous. It could refer to any of the following
// parameters: "--scope1:param", "--scope2:param"
throw new Error(`The parameter name "${parameterName}" is ambiguous. It could refer to any of ` +
`the following parameters: "${nonAmbiguousLongNames.join('", "')}"`);
}
// This shouldn't happen, but we also shouldn't allow the user to use the ambiguous parameter
throw new Error(`The parameter name "${parameterName}" is ambiguous.`);
}
}
// Fill in the values for the parameters

@@ -378,5 +460,15 @@ for (const parameter of this._parameters) {

longNameParameters.push(parameter);
// Collect all parameters with the same short name. We will perform conflict resolution at registration.
if (parameter.shortName) {
let shortNameParameters = this._parametersByShortName.get(parameter.shortName);
if (!shortNameParameters) {
shortNameParameters = [];
this._parametersByShortName.set(parameter.shortName, shortNameParameters);
}
shortNameParameters.push(parameter);
}
}
/** @internal */
_registerParameter(parameter, useScopedLongName) {
var _a;
const names = [];

@@ -465,6 +557,18 @@ if (parameter.shortName) {

argumentGroup.addArgument(names, Object.assign({}, argparseOptions));
if (parameter.undocumentedSynonyms && parameter.undocumentedSynonyms.length > 0) {
if ((_a = parameter.undocumentedSynonyms) === null || _a === void 0 ? void 0 : _a.length) {
argumentGroup.addArgument(parameter.undocumentedSynonyms, Object.assign(Object.assign({}, argparseOptions), { help: argparse.Const.SUPPRESS }));
}
}
_registerAmbiguousParameter(name) {
const parserKey = this._generateKey();
this._ambiguousParameterNamesByParserKey.set(parserKey, name);
this._getArgumentParser().addArgument(name, {
dest: parserKey,
// We don't know if this argument takes parameters or not, so we need to accept any number of args
nargs: '*',
// Ensure that the argument is not shown in the help text, since these parameters are only included
// to inform the user that ambiguous parameters are present
help: argparse.Const.SUPPRESS
});
}
_generateKey() {

@@ -482,5 +586,11 @@ return 'key_' + (CommandLineParameterProvider._keyCounter++).toString();

}
const parameter = parameters.find((p) => p.parameterScope === parameterScope);
let parameter = parameters.find((p) => p.parameterScope === parameterScope);
if (!parameter) {
throw new Error(`The parameter "${parameterLongName}" with scope "${parameterScope}" is not defined.`);
if (parameterScope !== undefined) {
throw new Error(`The parameter "${parameterLongName}" with scope "${parameterScope}" is not defined.`);
}
if (parameters.length !== 1) {
throw new Error(`The parameter "${parameterLongName}" is ambiguous. You must specify a scope.`);
}
parameter = parameters[0];
}

@@ -487,0 +597,0 @@ if (parameter.kind !== expectedKind) {

@@ -126,3 +126,5 @@ "use strict";

}
scopedArgs.push(...this.remainder.values.slice(1));
for (const scopedArg of this.remainder.values.slice(1)) {
scopedArgs.push(scopedArg);
}
}

@@ -129,0 +131,0 @@ // Call the scoped parser using only the scoped args to handle parsing

{
"name": "@rushstack/ts-command-line",
"version": "4.14.0",
"version": "4.15.0",
"description": "An object-oriented command-line parser for TypeScript",

@@ -20,4 +20,4 @@ "repository": {

"devDependencies": {
"@rushstack/heft": "0.51.0",
"@rushstack/heft-node-rig": "2.0.1",
"@rushstack/heft": "0.53.1",
"@rushstack/heft-node-rig": "2.2.5",
"@types/heft-jest": "1.0.1",

@@ -24,0 +24,0 @@ "@types/node": "14.18.36",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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