This commit is contained in:
2024-02-07 01:33:07 -05:00
commit c1af19d441
4088 changed files with 1260170 additions and 0 deletions

View File

@ -0,0 +1,108 @@
import type { SCOPING_PARAMETER_GROUP } from '../Constants';
import type { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument } from './CommandLineDefinition';
/**
* Identifies the kind of a CommandLineParameter.
* @public
*/
export declare enum CommandLineParameterKind {
/** Indicates a CommandLineChoiceParameter */
Choice = 0,
/** Indicates a CommandLineFlagParameter */
Flag = 1,
/** Indicates a CommandLineIntegerParameter */
Integer = 2,
/** Indicates a CommandLineStringParameter */
String = 3,
/** Indicates a CommandLineStringListParameter */
StringList = 4,
/** Indicates a CommandLineChoiceListParameter */
ChoiceList = 5,
/** Indicates a CommandLineIntegerListParameter */
IntegerList = 6
}
/**
* The base class for the various command-line parameter types.
* @public
*/
export declare abstract class CommandLineParameter {
private _shortNameValue;
/**
* A unique internal key used to retrieve the value from the parser's dictionary.
* @internal
*/
_parserKey: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */
readonly longName: string;
/**
* If a parameterScope is provided, returns the scope-prefixed long name of the flag,
* including double dashes, eg. "--scope:do-something". Otherwise undefined.
*/
readonly scopedLongName: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */
readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */
readonly parameterScope: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.description} */
readonly description: string;
/** {@inheritDoc IBaseCommandLineDefinition.required} */
readonly required: boolean;
/** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */
readonly environmentVariable: string | undefined;
/** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */
readonly undocumentedSynonyms: string[] | undefined;
/** @internal */
constructor(definition: IBaseCommandLineDefinition);
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
get shortName(): string | undefined;
/**
* Called internally by CommandLineParameterProvider._processParsedData()
* @internal
*/
abstract _setValue(data: any): void;
/**
* Returns additional text used by the help formatter.
* @internal
*/
_getSupplementaryNotes(supplementaryNotes: string[]): void;
/**
* Indicates the type of parameter.
*/
abstract get kind(): CommandLineParameterKind;
/**
* Append the parsed values to the provided string array.
* @remarks
* Sometimes a command line parameter is not used directly, but instead gets passed through to another
* tool that will use it. For example if our parameter comes in as "--max-count 3", then we might want to
* call `child_process.spawn()` and append ["--max-count", "3"] to the args array for that tool.
* appendToArgList() appends zero or more strings to the provided array, based on the input command-line
* that we parsed.
*
* If the parameter was omitted from our command-line and has no default value, then
* nothing will be appended. If the short name was used, the long name will be appended instead.
* @param argList - the parsed strings will be appended to this string array
*/
abstract appendToArgList(argList: string[]): void;
/**
* Internal usage only. Used to report unexpected output from the argparse library.
*/
protected reportInvalidData(data: any): never;
protected validateDefaultValue(hasDefaultValue: boolean): void;
}
/**
* The common base class for parameters types that receive an argument.
*
* @remarks
* An argument is an accompanying command-line token, such as "123" in the
* example "--max-count 123".
* @public
*/
export declare abstract class CommandLineParameterWithArgument extends CommandLineParameter {
private static _invalidArgumentNameRegExp;
/** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */
readonly argumentName: string;
/** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */
readonly completions: (() => Promise<string[]>) | undefined;
/** @internal */
constructor(definition: IBaseCommandLineDefinitionWithArgument);
}
//# sourceMappingURL=BaseClasses.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"BaseClasses.d.ts","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EACV,0BAA0B,EAC1B,sCAAsC,EACvC,MAAM,yBAAyB,CAAC;AAEjC;;;GAGG;AACH,oBAAY,wBAAwB;IAClC,6CAA6C;IAC7C,MAAM,IAAA;IACN,2CAA2C;IAC3C,IAAI,IAAA;IACJ,8CAA8C;IAC9C,OAAO,IAAA;IACP,6CAA6C;IAC7C,MAAM,IAAA;IACN,iDAAiD;IACjD,UAAU,IAAA;IACV,iDAAiD;IACjD,UAAU,IAAA;IACV,kDAAkD;IAClD,WAAW,IAAA;CACZ;AA4BD;;;GAGG;AACH,8BAAsB,oBAAoB;IACxC,OAAO,CAAC,eAAe,CAAqB;IAE5C;;;OAGG;IACI,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAEtC,iEAAiE;IACjE,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAEjC;;;OAGG;IACH,SAAgB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnD,8DAA8D;IAC9D,SAAgB,cAAc,EAAE,MAAM,GAAG,OAAO,uBAAuB,GAAG,SAAS,CAAC;IAEpF,8DAA8D;IAC9D,SAAgB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnD,2DAA2D;IAC3D,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC,wDAAwD;IACxD,SAAgB,QAAQ,EAAE,OAAO,CAAC;IAElC,mEAAmE;IACnE,SAAgB,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IAExD,qEAAqE;IACrE,SAAgB,oBAAoB,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAE3D,gBAAgB;gBACG,UAAU,EAAE,0BAA0B;IAyEzD,kEAAkE;IAClE,IAAW,SAAS,IAAI,MAAM,GAAG,SAAS,CAEzC;IAED;;;OAGG;aACa,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAE1C;;;OAGG;IACI,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,IAAI;IAWjE;;OAEG;IACH,aAAoB,IAAI,IAAI,wBAAwB,CAAC;IAErD;;;;;;;;;;;;OAYG;aACa,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAExD;;OAEG;IAEH,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,KAAK;IAI7C,SAAS,CAAC,oBAAoB,CAAC,eAAe,EAAE,OAAO,GAAG,IAAI;CAY/D;AAED;;;;;;;GAOG;AACH,8BAAsB,gCAAiC,SAAQ,oBAAoB;IAEjF,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAwB;IAEjE,wEAAwE;IACxE,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC,uEAAuE;IACvE,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEnE,gBAAgB;gBACG,UAAU,EAAE,sCAAsC;CAyBtE"}

View File

@ -0,0 +1,173 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineParameterWithArgument = exports.CommandLineParameter = exports.CommandLineParameterKind = void 0;
/**
* Identifies the kind of a CommandLineParameter.
* @public
*/
var CommandLineParameterKind;
(function (CommandLineParameterKind) {
/** Indicates a CommandLineChoiceParameter */
CommandLineParameterKind[CommandLineParameterKind["Choice"] = 0] = "Choice";
/** Indicates a CommandLineFlagParameter */
CommandLineParameterKind[CommandLineParameterKind["Flag"] = 1] = "Flag";
/** Indicates a CommandLineIntegerParameter */
CommandLineParameterKind[CommandLineParameterKind["Integer"] = 2] = "Integer";
/** Indicates a CommandLineStringParameter */
CommandLineParameterKind[CommandLineParameterKind["String"] = 3] = "String";
/** Indicates a CommandLineStringListParameter */
CommandLineParameterKind[CommandLineParameterKind["StringList"] = 4] = "StringList";
/** Indicates a CommandLineChoiceListParameter */
CommandLineParameterKind[CommandLineParameterKind["ChoiceList"] = 5] = "ChoiceList";
/** Indicates a CommandLineIntegerListParameter */
CommandLineParameterKind[CommandLineParameterKind["IntegerList"] = 6] = "IntegerList";
})(CommandLineParameterKind = exports.CommandLineParameterKind || (exports.CommandLineParameterKind = {}));
/**
* Matches kebab-case formatted strings prefixed with double dashes.
* Example: "--do-something"
*/
const LONG_NAME_REGEXP = /^-(-[a-z0-9]+)+$/;
/**
* Matches a single upper-case or lower-case letter prefixed with a dash.
* Example: "-d"
*/
const SHORT_NAME_REGEXP = /^-[a-zA-Z]$/;
/**
* Matches kebab-case formatted strings
* Example: "my-scope"
*/
const SCOPE_REGEXP = /^[a-z0-9]+(-[a-z0-9]+)*$/;
/**
* "Environment variable names used by the utilities in the Shell and Utilities volume of
* IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)
* from the characters defined in Portable Character Set and do not begin with a digit."
* Example: "THE_SETTING"
*/
const ENVIRONMENT_VARIABLE_NAME_REGEXP = /^[A-Z_][A-Z0-9_]*$/;
/**
* The base class for the various command-line parameter types.
* @public
*/
class CommandLineParameter {
/** @internal */
constructor(definition) {
this.longName = definition.parameterLongName;
this._shortNameValue = definition.parameterShortName;
this.parameterGroup = definition.parameterGroup;
this.parameterScope = definition.parameterScope;
this.description = definition.description;
this.required = !!definition.required;
this.environmentVariable = definition.environmentVariable;
this.undocumentedSynonyms = definition.undocumentedSynonyms;
if (!LONG_NAME_REGEXP.test(this.longName)) {
throw new Error(`Invalid name: "${this.longName}". The parameter long name must be` +
` lower-case and use dash delimiters (e.g. "--do-a-thing")`);
}
if (this.shortName) {
if (!SHORT_NAME_REGEXP.test(this.shortName)) {
throw new Error(`Invalid name: "${this.shortName}". The parameter short name must be` +
` a dash followed by a single upper-case or lower-case letter (e.g. "-a")`);
}
}
if (this.parameterScope) {
if (!SCOPE_REGEXP.test(this.parameterScope)) {
throw new Error(`Invalid scope: "${this.parameterScope}". The parameter scope name must be` +
` lower-case and use dash delimiters (e.g. "my-scope")`);
}
// Parameter long name is guaranteed to start with '--' since this is validated above
const unprefixedLongName = this.longName.slice(2);
this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;
}
if (this.environmentVariable) {
if (this.required) {
// TODO: This constraint is imposed only because argparse enforces "required" parameters, but
// it does not know about ts-command-line environment variable mappings. We should fix this.
throw new Error(`An "environmentVariable" cannot be specified for "${this.longName}"` +
` because it is a required parameter`);
}
if (!ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)) {
throw new Error(`Invalid environment variable name: "${this.environmentVariable}". The name must` +
` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`);
}
}
if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {
for (const undocumentedSynonym of this.undocumentedSynonyms) {
if (this.longName === undocumentedSynonym) {
throw new Error(`Invalid name: "${undocumentedSynonym}". Undocumented synonyms must not be the same` +
` as the the long name.`);
}
else if (!LONG_NAME_REGEXP.test(undocumentedSynonym)) {
throw new Error(`Invalid name: "${undocumentedSynonym}". All undocumented synonyms name must be lower-case and ` +
'use dash delimiters (e.g. "--do-a-thing")');
}
}
}
}
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
get shortName() {
return this._shortNameValue;
}
/**
* Returns additional text used by the help formatter.
* @internal
*/
_getSupplementaryNotes(supplementaryNotes) {
// virtual
if (this.environmentVariable !== undefined) {
supplementaryNotes.push('This parameter may alternatively be specified via the ' +
this.environmentVariable +
' environment variable.');
}
}
/**
* Internal usage only. Used to report unexpected output from the argparse library.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reportInvalidData(data) {
throw new Error(`Unexpected data object for parameter "${this.longName}": ` + JSON.stringify(data));
}
validateDefaultValue(hasDefaultValue) {
if (this.required && hasDefaultValue) {
// If a parameter is "required", then the user understands that they always need to
// specify a value for this parameter (either via the command line or via an environment variable).
// It would be confusing to allow a default value that sometimes allows the "required" parameter
// to be omitted. If you sometimes don't have a suitable default value, then the better approach
// is to throw a custom error explaining why the parameter is required in that case.
throw new Error(`A default value cannot be specified for "${this.longName}" because it is a "required" parameter`);
}
}
}
exports.CommandLineParameter = CommandLineParameter;
/**
* The common base class for parameters types that receive an argument.
*
* @remarks
* An argument is an accompanying command-line token, such as "123" in the
* example "--max-count 123".
* @public
*/
class CommandLineParameterWithArgument extends CommandLineParameter {
/** @internal */
constructor(definition) {
super(definition);
if (definition.argumentName === '') {
throw new Error('The argument name cannot be an empty string. (For the default name, specify undefined.)');
}
if (definition.argumentName.toUpperCase() !== definition.argumentName) {
throw new Error(`Invalid name: "${definition.argumentName}". The argument name must be all upper case.`);
}
const match = definition.argumentName.match(CommandLineParameterWithArgument._invalidArgumentNameRegExp);
if (match) {
throw new Error(`The argument name "${definition.argumentName}" contains an invalid character "${match[0]}".` +
` Only upper-case letters, numbers, and underscores are allowed.`);
}
this.argumentName = definition.argumentName;
this.completions = definition.completions;
}
}
// Matches the first character that *isn't* part of a valid upper-case argument name such as "URL_2"
CommandLineParameterWithArgument._invalidArgumentNameRegExp = /[^A-Z_0-9]/;
exports.CommandLineParameterWithArgument = CommandLineParameterWithArgument;
//# sourceMappingURL=BaseClasses.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,33 @@
import type { ICommandLineChoiceListDefinition } from './CommandLineDefinition';
import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
/**
* The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
* @public
*/
export declare class CommandLineChoiceListParameter extends CommandLineParameter {
/** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */
readonly alternatives: ReadonlyArray<string>;
private _values;
/** {@inheritDoc ICommandLineChoiceListDefinition.completions} */
readonly completions: (() => Promise<string[]>) | undefined;
/** @internal */
constructor(definition: ICommandLineChoiceListDefinition);
/** {@inheritDoc CommandLineParameter.kind} */
get kind(): CommandLineParameterKind;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/**
* Returns the string arguments for a choice list parameter that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get values(): ReadonlyArray<string>;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineChoiceListParameter.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineChoiceListParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceListParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG/E;;;GAGG;AACH,qBAAa,8BAA+B,SAAQ,oBAAoB;IACtE,kEAAkE;IAClE,SAAgB,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEpD,OAAO,CAAC,OAAO,CAAgB;IAE/B,iEAAiE;IACjE,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEnE,gBAAgB;gBACG,UAAU,EAAE,gCAAgC;IAa/D,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAqCjC;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,CAEzC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAQhD"}

View File

@ -0,0 +1,84 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineChoiceListParameter = void 0;
const BaseClasses_1 = require("./BaseClasses");
const EnvironmentVariableParser_1 = require("./EnvironmentVariableParser");
/**
* The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
* @public
*/
class CommandLineChoiceListParameter extends BaseClasses_1.CommandLineParameter {
/** @internal */
constructor(definition) {
super(definition);
this._values = [];
if (definition.alternatives.length < 1) {
throw new Error(`When defining a choice list parameter, the alternatives list must contain at least one value.`);
}
this.alternatives = definition.alternatives;
this.completions = definition.completions;
}
/** {@inheritDoc CommandLineParameter.kind} */
get kind() {
return BaseClasses_1.CommandLineParameterKind.ChoiceList;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// If argparse passed us a value, confirm it is valid
if (data !== null && data !== undefined) {
if (!Array.isArray(data)) {
this.reportInvalidData(data);
}
for (const arrayItem of data) {
if (typeof arrayItem !== 'string') {
this.reportInvalidData(data);
}
}
this._values = data;
return;
}
if (this.environmentVariable !== undefined) {
const values = EnvironmentVariableParser_1.EnvironmentVariableParser.parseAsList(this.environmentVariable);
if (values) {
for (const value of values) {
if (this.alternatives.indexOf(value) < 0) {
const choices = '"' + this.alternatives.join('", "') + '"';
throw new Error(`Invalid value "${value}" for the environment variable` +
` ${this.environmentVariable}. Valid choices are: ${choices}`);
}
}
this._values = values;
return;
}
}
// (No default value for choice lists)
this._values = [];
}
/**
* Returns the string arguments for a choice list parameter that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get values() {
return this._values;
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.values.length > 0) {
for (const value of this.values) {
argList.push(this.longName);
argList.push(value);
}
}
}
}
exports.CommandLineChoiceListParameter = CommandLineChoiceListParameter;
//# sourceMappingURL=CommandLineChoiceListParameter.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,40 @@
import type { ICommandLineChoiceDefinition } from './CommandLineDefinition';
import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
/**
* The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
* @public
*/
export declare class CommandLineChoiceParameter extends CommandLineParameter {
/** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */
readonly alternatives: ReadonlyArray<string>;
/** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
readonly defaultValue: string | undefined;
private _value;
/** {@inheritDoc ICommandLineChoiceDefinition.completions} */
readonly completions: (() => Promise<string[]>) | undefined;
/** @internal */
constructor(definition: ICommandLineChoiceDefinition);
/** {@inheritDoc CommandLineParameter.kind} */
get kind(): CommandLineParameterKind;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/**
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
* @internal
*/
_getSupplementaryNotes(supplementaryNotes: string[]): void;
/**
* Returns the argument value for a choice parameter that was parsed from the command line.
*
* @remarks
* The return value will be `undefined` if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get value(): string | undefined;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineChoiceParameter.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineChoiceParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE/E;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,oBAAoB;IAClE,8DAA8D;IAC9D,SAAgB,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEpD,8DAA8D;IAC9D,SAAgB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjD,OAAO,CAAC,MAAM,CAAiC;IAE/C,6DAA6D;IAC7D,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEnE,gBAAgB;gBACG,UAAU,EAAE,4BAA4B;IAqB3D,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAkCjC;;;OAGG;IACI,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,IAAI;IAQjE;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,MAAM,GAAG,SAAS,CAErC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAMhD"}

View File

@ -0,0 +1,95 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineChoiceParameter = void 0;
const BaseClasses_1 = require("./BaseClasses");
/**
* The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
* @public
*/
class CommandLineChoiceParameter extends BaseClasses_1.CommandLineParameter {
/** @internal */
constructor(definition) {
super(definition);
this._value = undefined;
if (definition.alternatives.length < 1) {
throw new Error(`When defining a choice parameter, the alternatives list must contain at least one value.`);
}
if (definition.defaultValue && definition.alternatives.indexOf(definition.defaultValue) === -1) {
throw new Error(`The specified default value "${definition.defaultValue}"` +
` is not one of the available options: ${definition.alternatives.toString()}`);
}
this.alternatives = definition.alternatives;
this.defaultValue = definition.defaultValue;
this.validateDefaultValue(!!this.defaultValue);
this.completions = definition.completions;
}
/** {@inheritDoc CommandLineParameter.kind} */
get kind() {
return BaseClasses_1.CommandLineParameterKind.Choice;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// abstract
if (data !== null && data !== undefined) {
if (typeof data !== 'string') {
this.reportInvalidData(data);
}
this._value = data;
return;
}
if (this.environmentVariable !== undefined) {
// Try reading the environment variable
const environmentValue = process.env[this.environmentVariable];
if (environmentValue !== undefined && environmentValue !== '') {
if (this.alternatives.indexOf(environmentValue) < 0) {
const choices = '"' + this.alternatives.join('", "') + '"';
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
` ${this.environmentVariable}. Valid choices are: ${choices}`);
}
this._value = environmentValue;
return;
}
}
if (this.defaultValue !== undefined) {
this._value = this.defaultValue;
return;
}
this._value = undefined;
}
/**
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
* @internal
*/
_getSupplementaryNotes(supplementaryNotes) {
// virtual
super._getSupplementaryNotes(supplementaryNotes);
if (this.defaultValue !== undefined) {
supplementaryNotes.push(`The default value is "${this.defaultValue}".`);
}
}
/**
* Returns the argument value for a choice parameter that was parsed from the command line.
*
* @remarks
* The return value will be `undefined` if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get value() {
return this._value;
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.value !== undefined) {
argList.push(this.longName);
argList.push(this.value);
}
}
}
exports.CommandLineChoiceParameter = CommandLineChoiceParameter;
//# sourceMappingURL=CommandLineChoiceParameter.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,219 @@
import type { SCOPING_PARAMETER_GROUP } from '../Constants';
/**
* For use with CommandLineParser, this interface represents a generic command-line parameter
*
* @public
*/
export interface IBaseCommandLineDefinition {
/**
* The long name of the flag including double dashes, e.g. "--do-something"
*/
parameterLongName: string;
/**
* An optional short name for the flag including the dash, e.g. "-d"
*/
parameterShortName?: string;
/**
* An optional parameter group name, shown when invoking the tool with "--help"
*/
parameterGroup?: string | typeof SCOPING_PARAMETER_GROUP;
/**
* An optional parameter scope name, used to add a scope-prefixed parameter synonym,
* e.g. "--scope:do-something". Scopes provide additional flexibility for parameters
* in conflict resolution since when a scope is specified, parameters that have
* conflicting long names will be defined using only the scope-prefixed name.
*/
parameterScope?: string;
/**
* Documentation for the parameter that will be shown when invoking the tool with "--help"
*/
description: string;
/**
* If true, then an error occurs if the parameter was not included on the command-line.
*/
required?: boolean;
/**
* The name of an environment variable that the parameter value will be read from,
* if it was omitted from the command-line. An error will be reported if the
* environment value cannot be parsed.
*
* @remarks
* The environment variable name must consist only of upper-case letters, numbers,
* and underscores. It may not start with a number.
*
* This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,
* because in that case the environmentVariable would never be used.
*
* Syntax notes for environment variable values:
*
* - Choice Parameter: The value must match one of the defined choices,
* otherwise a validation error is reported.
* An empty string causes the environment variable to be ignored.
*
* - Flag Parameter: The value must be `1` for true, or `0` for false,
* otherwise a validation error is reported.
* An empty string causes the environment variable to be ignored.
*
* - Integer Parameter: The value must be an integer number,
* otherwise a validation error is reported.
* An empty string causes the environment variable to be ignored.
*
* - String Parameter: Any value is accepted, including an empty string.
*
* - String List Parameter: If the string starts with `[` (ignoring whitespace)
* then it will be parsed as a JSON array, whose elements must be strings,
* numbers, or boolean values.
* If the string does not start with `[`, then it behaves like an
* ordinary String Parameter: Any value is accepted, including an empty string.
*/
environmentVariable?: string;
/**
* Specifies additional names for this parameter that are accepted but not displayed
* in the command line help.
*
* @remarks
* This option can be used in cases where a command-line parameter may have been renamed,
* but the developer doesn't want to break backwards compatibility with systems that may
* still be using the old name. Only the `parameterLongName` syntax is currently allowed.
*/
undocumentedSynonyms?: string[];
}
/**
* The common base interface for parameter types that accept an argument.
*
* @remarks
* An argument is an accompanying command-line token, such as "123" in the
* example "--max-count 123".
* @public
*/
export interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {
/**
* The name of the argument, which will be shown in the command-line help.
*
* @remarks
* For example, if the parameter name is '--count" and the argument name is "NUMBER",
* then the command-line help would display "--count NUMBER". The argument name must
* be comprised of upper-case letters, numbers, and underscores. It should be kept short.
*/
argumentName: string;
/**
* An optional callback that provides a list of custom choices for tab completion.
* @remarks
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
* is enabled.
*/
completions?: () => Promise<string[]>;
}
/**
* For use with {@link CommandLineParameterProvider.defineChoiceParameter},
* this interface defines a command line parameter which is constrained to a list of possible
* options.
*
* @public
*/
export interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {
/**
* A list of strings (which contain no spaces), of possible options which can be selected
*/
alternatives: string[];
/**
* {@inheritDoc ICommandLineStringDefinition.defaultValue}
*/
defaultValue?: string;
/**
* An optional callback that provides a list of custom choices for tab completion.
* @remarks
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
* is enabled.
*/
completions?: () => Promise<string[]>;
}
/**
* For use with {@link CommandLineParameterProvider.defineChoiceListParameter},
* this interface defines a command line parameter which is constrained to a list of possible
* options. The parameter can be specified multiple times to build a list.
*
* @public
*/
export interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {
/**
* A list of strings (which contain no spaces), of possible options which can be selected
*/
alternatives: string[];
/**
* An optional callback that provides a list of custom choices for tab completion.
* @remarks
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
* is enabled.
*/
completions?: () => Promise<string[]>;
}
/**
* For use with {@link CommandLineParameterProvider.defineFlagParameter},
* this interface defines a command line parameter that is a boolean flag.
*
* @public
*/
export interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {
}
/**
* For use with {@link CommandLineParameterProvider.defineIntegerParameter},
* this interface defines a command line parameter whose argument is an integer value.
*
* @public
*/
export interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {
/**
* {@inheritDoc ICommandLineStringDefinition.defaultValue}
*/
defaultValue?: number;
}
/**
* For use with {@link CommandLineParameterProvider.defineIntegerListParameter},
* this interface defines a command line parameter whose argument is an integer value. The
* parameter can be specified multiple times to build a list.
*
* @public
*/
export interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {
}
/**
* For use with {@link CommandLineParameterProvider.defineStringParameter},
* this interface defines a command line parameter whose argument is a string value.
*
* @public
*/
export interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {
/**
* The default value which will be used if the parameter is omitted from the command line.
*
* @remarks
* If a default value is specified, then {@link IBaseCommandLineDefinition.required}
* must not be true. Instead, a custom error message should be used to report cases
* where a default value was not available.
*/
defaultValue?: string;
}
/**
* For use with {@link CommandLineParameterProvider.defineStringListParameter},
* this interface defines a command line parameter whose argument is a single text string.
* The parameter can be specified multiple times to build a list.
*
* @public
*/
export interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {
}
/**
* For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},
* this interface defines a rule that captures any remaining command line arguments after the recognized portion.
*
* @public
*/
export interface ICommandLineRemainderDefinition {
/**
* Documentation for how the remaining arguments will be used. This will be shown when invoking
* the tool with "--help".
*/
description: string;
}
//# sourceMappingURL=CommandLineDefinition.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineDefinition.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,uBAAuB,CAAC;IAEzD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;;;;;;OAOG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,4BAA6B,SAAQ,0BAA0B;IAC9E;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gCAAiC,SAAQ,0BAA0B;IAClF;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;GAKG;AACH,MAAM,WAAW,0BAA2B,SAAQ,0BAA0B;CAAG;AAEjF;;;;;GAKG;AACH,MAAM,WAAW,6BAA8B,SAAQ,sCAAsC;IAC3F;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iCAAkC,SAAQ,sCAAsC;CAAG;AAEpG;;;;;GAKG;AACH,MAAM,WAAW,4BAA6B,SAAQ,sCAAsC;IAC1F;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gCAAiC,SAAQ,sCAAsC;CAAG;AAEnG;;;;;GAKG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB"}

View File

@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=CommandLineDefinition.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,29 @@
import type { ICommandLineFlagDefinition } from './CommandLineDefinition';
import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
/**
* The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.
* @public
*/
export declare class CommandLineFlagParameter extends CommandLineParameter {
private _value;
/** @internal */
constructor(definition: ICommandLineFlagDefinition);
/** {@inheritDoc CommandLineParameter.kind} */
get kind(): CommandLineParameterKind;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/**
* Returns a boolean indicating whether the parameter was included in the command line.
*
* @remarks
* The return value will be false if the command-line has not been parsed yet,
* or if the flag was not used.
*/
get value(): boolean;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineFlagParameter.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineFlagParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineFlagParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE/E;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,oBAAoB;IAChE,OAAO,CAAC,MAAM,CAAkB;IAEhC,gBAAgB;gBACG,UAAU,EAAE,0BAA0B;IAIzD,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAkCjC;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,OAAO,CAE1B;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAKhD"}

View File

@ -0,0 +1,72 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineFlagParameter = void 0;
const BaseClasses_1 = require("./BaseClasses");
/**
* The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.
* @public
*/
class CommandLineFlagParameter extends BaseClasses_1.CommandLineParameter {
/** @internal */
constructor(definition) {
super(definition);
this._value = false;
}
/** {@inheritDoc CommandLineParameter.kind} */
get kind() {
return BaseClasses_1.CommandLineParameterKind.Flag;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// abstract
if (data !== null && data !== undefined) {
if (typeof data !== 'boolean') {
this.reportInvalidData(data);
}
// If the flag is omitted, then argparse sets the data to "false" instead of "undefined".
// This design prevents a syntax such as "--flag=false", probably because argparse prefers "--no-flag".
// If we switch to a new CLI parser, we should try to add support for "--flag=false".
if (data) {
this._value = data;
return;
}
}
if (this.environmentVariable !== undefined) {
// Try reading the environment variable
const environmentValue = process.env[this.environmentVariable];
if (environmentValue !== undefined && environmentValue !== '') {
if (environmentValue !== '0' && environmentValue !== '1') {
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
` ${this.environmentVariable}. Valid choices are 0 or 1.`);
}
this._value = environmentValue === '1';
return;
}
}
this._value = false;
}
/**
* Returns a boolean indicating whether the parameter was included in the command line.
*
* @remarks
* The return value will be false if the command-line has not been parsed yet,
* or if the flag was not used.
*/
get value() {
return this._value;
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.value) {
argList.push(this.longName);
}
}
}
exports.CommandLineFlagParameter = CommandLineFlagParameter;
//# sourceMappingURL=CommandLineFlagParameter.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineFlagParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineFlagParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA+E;AAE/E;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,kCAAoB;IAGhE,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,WAAM,GAAY,KAAK,CAAC;IAKhC,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,IAAI,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE;gBAC7B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YAED,yFAAyF;YACzF,uGAAuG;YACvG,qFAAqF;YACrF,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,OAAO;aACR;SACF;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,uCAAuC;YACvC,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACnF,IAAI,gBAAgB,KAAK,SAAS,IAAI,gBAAgB,KAAK,EAAE,EAAE;gBAC7D,IAAI,gBAAgB,KAAK,GAAG,IAAI,gBAAgB,KAAK,GAAG,EAAE;oBACxD,MAAM,IAAI,KAAK,CACb,kBAAkB,gBAAgB,gCAAgC;wBAChE,IAAI,IAAI,CAAC,mBAAmB,8BAA8B,CAC7D,CAAC;iBACH;gBACD,IAAI,CAAC,MAAM,GAAG,gBAAgB,KAAK,GAAG,CAAC;gBACvC,OAAO;aACR;SACF;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC7B;IACH,CAAC;CACF;AArED,4DAqEC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ICommandLineFlagDefinition } from './CommandLineDefinition';\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.\n * @public\n */\nexport class CommandLineFlagParameter extends CommandLineParameter {\n private _value: boolean = false;\n\n /** @internal */\n public constructor(definition: ICommandLineFlagDefinition) {\n super(definition);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.Flag;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._setValue}\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public _setValue(data: any): void {\n // abstract\n if (data !== null && data !== undefined) {\n if (typeof data !== 'boolean') {\n this.reportInvalidData(data);\n }\n\n // If the flag is omitted, then argparse sets the data to \"false\" instead of \"undefined\".\n // This design prevents a syntax such as \"--flag=false\", probably because argparse prefers \"--no-flag\".\n // If we switch to a new CLI parser, we should try to add support for \"--flag=false\".\n if (data) {\n this._value = data;\n return;\n }\n }\n\n if (this.environmentVariable !== undefined) {\n // Try reading the environment variable\n const environmentValue: string | undefined = process.env[this.environmentVariable];\n if (environmentValue !== undefined && environmentValue !== '') {\n if (environmentValue !== '0' && environmentValue !== '1') {\n throw new Error(\n `Invalid value \"${environmentValue}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are 0 or 1.`\n );\n }\n this._value = environmentValue === '1';\n return;\n }\n }\n\n this._value = false;\n }\n\n /**\n * Returns a boolean indicating whether the parameter was included in the command line.\n *\n * @remarks\n * The return value will be false if the command-line has not been parsed yet,\n * or if the flag was not used.\n */\n public get value(): boolean {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value) {\n argList.push(this.longName);\n }\n }\n}\n"]}

View File

@ -0,0 +1,29 @@
import type { ICommandLineIntegerListDefinition } from './CommandLineDefinition';
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
/**
* The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.
* @public
*/
export declare class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {
private _values;
/** @internal */
constructor(definition: ICommandLineIntegerListDefinition);
/** {@inheritDoc CommandLineParameter.kind} */
get kind(): CommandLineParameterKind;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/**
* Returns the integer arguments for an integer list parameter that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get values(): ReadonlyArray<number>;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineIntegerListParameter.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineIntegerListParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerListParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG3F;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,gCAAgC;IACnF,OAAO,CAAC,OAAO,CAAgB;IAE/B,gBAAgB;gBACG,UAAU,EAAE,iCAAiC;IAIhE,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAwCjC;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,CAEzC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAQhD"}

View File

@ -0,0 +1,82 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineIntegerListParameter = void 0;
const BaseClasses_1 = require("./BaseClasses");
const EnvironmentVariableParser_1 = require("./EnvironmentVariableParser");
/**
* The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.
* @public
*/
class CommandLineIntegerListParameter extends BaseClasses_1.CommandLineParameterWithArgument {
/** @internal */
constructor(definition) {
super(definition);
this._values = [];
}
/** {@inheritDoc CommandLineParameter.kind} */
get kind() {
return BaseClasses_1.CommandLineParameterKind.IntegerList;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// If argparse passed us a value, confirm it is valid
if (data !== null && data !== undefined) {
if (!Array.isArray(data)) {
this.reportInvalidData(data);
}
for (const arrayItem of data) {
if (typeof arrayItem !== 'number') {
this.reportInvalidData(data);
}
}
this._values = data;
return;
}
// If an environment variable exists, attempt to parse it as a list
if (this.environmentVariable !== undefined) {
const values = EnvironmentVariableParser_1.EnvironmentVariableParser.parseAsList(this.environmentVariable);
if (values) {
const parsedValues = [];
for (const value of values) {
const parsed = parseInt(value, 10);
if (isNaN(parsed) || value.indexOf('.') >= 0) {
throw new Error(`Invalid value "${value}" for the environment variable` +
` ${this.environmentVariable}. It must be an integer value.`);
}
parsedValues.push(parsed);
}
this._values = parsedValues;
return;
}
}
// (No default value for integer lists)
this._values = [];
}
/**
* Returns the integer arguments for an integer list parameter that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get values() {
return this._values;
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.values.length > 0) {
for (const value of this.values) {
argList.push(this.longName);
argList.push(value.toString());
}
}
}
}
exports.CommandLineIntegerListParameter = CommandLineIntegerListParameter;
//# sourceMappingURL=CommandLineIntegerListParameter.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineIntegerListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAC3F,2EAAwE;AAExE;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,8CAAgC;IAGnF,gBAAgB;IAChB,YAAmB,UAA6C;QAC9D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,YAAO,GAAa,EAAE,CAAC;IAK/B,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,WAAW,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,qDAAqD;QACrD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;gBAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;oBACjC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;iBAC9B;aACF;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO;SACR;QAED,mEAAmE;QACnE,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,MAAM,MAAM,GAAyB,qDAAyB,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACrG,IAAI,MAAM,EAAE;gBACV,MAAM,YAAY,GAAa,EAAE,CAAC;gBAClC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;oBAC1B,MAAM,MAAM,GAAW,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAC3C,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;wBAC5C,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,gCAAgC;4BACrD,IAAI,IAAI,CAAC,mBAAmB,iCAAiC,CAChE,CAAC;qBACH;oBACD,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;iBAC3B;gBACD,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC;gBAC5B,OAAO;aACR;SACF;QAED,uCAAuC;QAEvC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;aAChC;SACF;IACH,CAAC;CACF;AA9ED,0EA8EC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ICommandLineIntegerListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.\n * @public\n */\nexport class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {\n private _values: number[] = [];\n\n /** @internal */\n public constructor(definition: ICommandLineIntegerListDefinition) {\n super(definition);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.IntegerList;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._setValue}\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public _setValue(data: any): void {\n // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'number') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n // If an environment variable exists, attempt to parse it as a list\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n const parsedValues: number[] = [];\n for (const value of values) {\n const parsed: number = parseInt(value, 10);\n if (isNaN(parsed) || value.indexOf('.') >= 0) {\n throw new Error(\n `Invalid value \"${value}\" for the environment variable` +\n ` ${this.environmentVariable}. It must be an integer value.`\n );\n }\n parsedValues.push(parsed);\n }\n this._values = parsedValues;\n return;\n }\n }\n\n // (No default value for integer lists)\n\n this._values = [];\n }\n\n /**\n * Returns the integer arguments for an integer list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get values(): ReadonlyArray<number> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(value.toString());\n }\n }\n }\n}\n"]}

View File

@ -0,0 +1,36 @@
import type { ICommandLineIntegerDefinition } from './CommandLineDefinition';
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
/**
* The data type returned by {@link CommandLineParameterProvider.defineIntegerParameter}.
* @public
*/
export declare class CommandLineIntegerParameter extends CommandLineParameterWithArgument {
/** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
readonly defaultValue: number | undefined;
private _value;
/** @internal */
constructor(definition: ICommandLineIntegerDefinition);
/** {@inheritDoc CommandLineParameter.kind} */
get kind(): CommandLineParameterKind;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/**
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
* @internal
*/
_getSupplementaryNotes(supplementaryNotes: string[]): void;
/**
* Returns the argument value for an integer parameter that was parsed from the command line.
*
* @remarks
* The return value will be undefined if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get value(): number | undefined;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineIntegerParameter.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineIntegerParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE3F;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,gCAAgC;IAC/E,8DAA8D;IAC9D,SAAgB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjD,OAAO,CAAC,MAAM,CAAiC;IAE/C,gBAAgB;gBACG,UAAU,EAAE,6BAA6B;IAM5D,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAkCjC;;;OAGG;IACI,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,IAAI;IAQjE;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,MAAM,GAAG,SAAS,CAErC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAMhD"}

View File

@ -0,0 +1,86 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineIntegerParameter = void 0;
const BaseClasses_1 = require("./BaseClasses");
/**
* The data type returned by {@link CommandLineParameterProvider.defineIntegerParameter}.
* @public
*/
class CommandLineIntegerParameter extends BaseClasses_1.CommandLineParameterWithArgument {
/** @internal */
constructor(definition) {
super(definition);
this._value = undefined;
this.defaultValue = definition.defaultValue;
this.validateDefaultValue(!!this.defaultValue);
}
/** {@inheritDoc CommandLineParameter.kind} */
get kind() {
return BaseClasses_1.CommandLineParameterKind.Integer;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// abstract
if (data !== null && data !== undefined) {
if (typeof data !== 'number') {
this.reportInvalidData(data);
}
this._value = data;
return;
}
if (this.environmentVariable !== undefined) {
// Try reading the environment variable
const environmentValue = process.env[this.environmentVariable];
if (environmentValue !== undefined && environmentValue !== '') {
const parsed = parseInt(environmentValue, 10);
if (isNaN(parsed) || environmentValue.indexOf('.') >= 0) {
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
` ${this.environmentVariable}. It must be an integer value.`);
}
this._value = parsed;
return;
}
}
if (this.defaultValue !== undefined) {
this._value = this.defaultValue;
return;
}
this._value = undefined;
}
/**
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
* @internal
*/
_getSupplementaryNotes(supplementaryNotes) {
// virtual
super._getSupplementaryNotes(supplementaryNotes);
if (this.defaultValue !== undefined) {
supplementaryNotes.push(`The default value is ${this.defaultValue}.`);
}
}
/**
* Returns the argument value for an integer parameter that was parsed from the command line.
*
* @remarks
* The return value will be undefined if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get value() {
return this._value;
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.value !== undefined) {
argList.push(this.longName);
argList.push(this.value.toString());
}
}
}
exports.CommandLineIntegerParameter = CommandLineIntegerParameter;
//# sourceMappingURL=CommandLineIntegerParameter.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,28 @@
import type { ICommandLineRemainderDefinition } from './CommandLineDefinition';
/**
* The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.
* @public
*/
export declare class CommandLineRemainder {
private _values;
/** {@inheritDoc IBaseCommandLineDefinition.description} */
readonly description: string;
/** @internal */
constructor(definition: ICommandLineRemainderDefinition);
/**
* Returns any remaining command line arguments after the recognized portion
* that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet.
*/
get values(): ReadonlyArray<string>;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineRemainder.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineRemainder.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineRemainder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE/E;;;GAGG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAE/B,2DAA2D;IAC3D,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC,gBAAgB;gBACG,UAAU,EAAE,+BAA+B;IAI9D;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,CAEzC;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IASjC,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAOhD"}

View File

@ -0,0 +1,48 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineRemainder = void 0;
/**
* The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.
* @public
*/
class CommandLineRemainder {
/** @internal */
constructor(definition) {
this._values = [];
this.description = definition.description;
}
/**
* Returns any remaining command line arguments after the recognized portion
* that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet.
*/
get values() {
return this._values;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// abstract
if (!Array.isArray(data) || !data.every((x) => typeof x === 'string')) {
throw new Error(`Unexpected data object for remainder: ` + JSON.stringify(data));
}
this._values.push(...data);
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.values.length > 0) {
for (const value of this.values) {
argList.push(value);
}
}
}
}
exports.CommandLineRemainder = CommandLineRemainder;
//# sourceMappingURL=CommandLineRemainder.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineRemainder.js","sourceRoot":"","sources":["../../src/parameters/CommandLineRemainder.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D;;;GAGG;AACH,MAAa,oBAAoB;IAM/B,gBAAgB;IAChB,YAAmB,UAA2C;QANtD,YAAO,GAAa,EAAE,CAAC;QAO7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE;YACrE,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;SAClF;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC;CACF;AA5CD,oDA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ICommandLineRemainderDefinition } from './CommandLineDefinition';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.\n * @public\n */\nexport class CommandLineRemainder {\n private _values: string[] = [];\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** @internal */\n public constructor(definition: ICommandLineRemainderDefinition) {\n this.description = definition.description;\n }\n\n /**\n * Returns any remaining command line arguments after the recognized portion\n * that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet.\n */\n public get values(): ReadonlyArray<string> {\n return this._values;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._setValue}\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public _setValue(data: any): void {\n // abstract\n if (!Array.isArray(data) || !data.every((x) => typeof x === 'string')) {\n throw new Error(`Unexpected data object for remainder: ` + JSON.stringify(data));\n }\n\n this._values.push(...data);\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(value);\n }\n }\n }\n}\n"]}

View File

@ -0,0 +1,29 @@
import type { ICommandLineStringListDefinition } from './CommandLineDefinition';
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
/**
* The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.
* @public
*/
export declare class CommandLineStringListParameter extends CommandLineParameterWithArgument {
private _values;
/** @internal */
constructor(definition: ICommandLineStringListDefinition);
/** {@inheritDoc CommandLineParameter.kind} */
get kind(): CommandLineParameterKind;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/**
* Returns the string arguments for a string list parameter that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get values(): ReadonlyArray<string>;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineStringListParameter.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineStringListParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineStringListParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG3F;;;GAGG;AACH,qBAAa,8BAA+B,SAAQ,gCAAgC;IAClF,OAAO,CAAC,OAAO,CAAgB;IAE/B,gBAAgB;gBACG,UAAU,EAAE,gCAAgC;IAI/D,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IA6BjC;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,CAEzC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAQhD"}

View File

@ -0,0 +1,73 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineStringListParameter = void 0;
const BaseClasses_1 = require("./BaseClasses");
const EnvironmentVariableParser_1 = require("./EnvironmentVariableParser");
/**
* The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.
* @public
*/
class CommandLineStringListParameter extends BaseClasses_1.CommandLineParameterWithArgument {
/** @internal */
constructor(definition) {
super(definition);
this._values = [];
}
/** {@inheritDoc CommandLineParameter.kind} */
get kind() {
return BaseClasses_1.CommandLineParameterKind.StringList;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// If argparse passed us a value, confirm it is valid
if (data !== null && data !== undefined) {
if (!Array.isArray(data)) {
this.reportInvalidData(data);
}
for (const arrayItem of data) {
if (typeof arrayItem !== 'string') {
this.reportInvalidData(data);
}
}
this._values = data;
return;
}
// If an environment variable exists, attempt to parse it as a list
if (this.environmentVariable !== undefined) {
const values = EnvironmentVariableParser_1.EnvironmentVariableParser.parseAsList(this.environmentVariable);
if (values) {
this._values = values;
return;
}
}
// (No default value for string lists)
this._values = [];
}
/**
* Returns the string arguments for a string list parameter that was parsed from the command line.
*
* @remarks
* The array will be empty if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get values() {
return this._values;
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.values.length > 0) {
for (const value of this.values) {
argList.push(this.longName);
argList.push(value);
}
}
}
}
exports.CommandLineStringListParameter = CommandLineStringListParameter;
//# sourceMappingURL=CommandLineStringListParameter.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineStringListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAC3F,2EAAwE;AAExE;;;GAGG;AACH,MAAa,8BAA+B,SAAQ,8CAAgC;IAGlF,gBAAgB;IAChB,YAAmB,UAA4C;QAC7D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,YAAO,GAAa,EAAE,CAAC;IAK/B,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,UAAU,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,qDAAqD;QACrD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;gBAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;oBACjC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;iBAC9B;aACF;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO;SACR;QAED,mEAAmE;QACnE,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,MAAM,MAAM,GAAyB,qDAAyB,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACrG,IAAI,MAAM,EAAE;gBACV,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;gBACtB,OAAO;aACR;SACF;QAED,sCAAsC;QAEtC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC;CACF;AAnED,wEAmEC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ICommandLineStringListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.\n * @public\n */\nexport class CommandLineStringListParameter extends CommandLineParameterWithArgument {\n private _values: string[] = [];\n\n /** @internal */\n public constructor(definition: ICommandLineStringListDefinition) {\n super(definition);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.StringList;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._setValue}\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public _setValue(data: any): void {\n // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'string') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n // If an environment variable exists, attempt to parse it as a list\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n this._values = values;\n return;\n }\n }\n\n // (No default value for string lists)\n\n this._values = [];\n }\n\n /**\n * Returns the string arguments for a string list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get values(): ReadonlyArray<string> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(value);\n }\n }\n }\n}\n"]}

View File

@ -0,0 +1,36 @@
import type { ICommandLineStringDefinition } from './CommandLineDefinition';
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
/**
* The data type returned by {@link CommandLineParameterProvider.defineStringParameter}.
* @public
*/
export declare class CommandLineStringParameter extends CommandLineParameterWithArgument {
/** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
readonly defaultValue: string | undefined;
private _value;
/** @internal */
constructor(definition: ICommandLineStringDefinition);
/** {@inheritDoc CommandLineParameter.kind} */
get kind(): CommandLineParameterKind;
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
_setValue(data: any): void;
/**
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
* @internal
*/
_getSupplementaryNotes(supplementaryNotes: string[]): void;
/**
* Returns the argument value for a string parameter that was parsed from the command line.
*
* @remarks
* The return value will be undefined if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get value(): string | undefined;
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList: string[]): void;
}
//# sourceMappingURL=CommandLineStringParameter.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineStringParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineStringParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE3F;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,gCAAgC;IAC9E,8DAA8D;IAC9D,SAAgB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjD,OAAO,CAAC,MAAM,CAAiC;IAE/C,gBAAgB;gBACG,UAAU,EAAE,4BAA4B;IAO3D,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IA6BjC;;;OAGG;IACI,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,IAAI;IAUjE;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,MAAM,GAAG,SAAS,CAErC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAMhD"}

View File

@ -0,0 +1,85 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandLineStringParameter = void 0;
const BaseClasses_1 = require("./BaseClasses");
/**
* The data type returned by {@link CommandLineParameterProvider.defineStringParameter}.
* @public
*/
class CommandLineStringParameter extends BaseClasses_1.CommandLineParameterWithArgument {
/** @internal */
constructor(definition) {
super(definition);
this._value = undefined;
this.defaultValue = definition.defaultValue;
this.validateDefaultValue(!!this.defaultValue);
}
/** {@inheritDoc CommandLineParameter.kind} */
get kind() {
return BaseClasses_1.CommandLineParameterKind.String;
}
/**
* {@inheritDoc CommandLineParameter._setValue}
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_setValue(data) {
// abstract
if (data !== null && data !== undefined) {
if (typeof data !== 'string') {
this.reportInvalidData(data);
}
this._value = data;
return;
}
if (this.environmentVariable !== undefined) {
// Try reading the environment variable
const environmentValue = process.env[this.environmentVariable];
if (environmentValue !== undefined) {
// NOTE: If the environment variable is defined as an empty string,
// here we will accept the empty string as our value. (For number/flag we don't do that.)
this._value = environmentValue;
return;
}
}
if (this.defaultValue !== undefined) {
this._value = this.defaultValue;
return;
}
this._value = undefined;
}
/**
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
* @internal
*/
_getSupplementaryNotes(supplementaryNotes) {
// virtual
super._getSupplementaryNotes(supplementaryNotes);
if (this.defaultValue !== undefined) {
if (this.defaultValue.length < 160) {
supplementaryNotes.push(`The default value is ${JSON.stringify(this.defaultValue)}.`);
}
}
}
/**
* Returns the argument value for a string parameter that was parsed from the command line.
*
* @remarks
* The return value will be undefined if the command-line has not been parsed yet,
* or if the parameter was omitted and has no default value.
*/
get value() {
return this._value;
}
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
appendToArgList(argList) {
if (this.value !== undefined) {
argList.push(this.longName);
argList.push(this.value);
}
}
}
exports.CommandLineStringParameter = CommandLineStringParameter;
//# sourceMappingURL=CommandLineStringParameter.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"CommandLineStringParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAE3F;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,8CAAgC;IAM9E,gBAAgB;IAChB,YAAmB,UAAwC;QACzD,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,WAAM,GAAuB,SAAS,CAAC;QAM7C,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjD,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,MAAM,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC5B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,OAAO;SACR;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,uCAAuC;YACvC,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACnF,IAAI,gBAAgB,KAAK,SAAS,EAAE;gBAClC,mEAAmE;gBACnE,0FAA0F;gBAC1F,IAAI,CAAC,MAAM,GAAG,gBAAgB,CAAC;gBAC/B,OAAO;aACR;SACF;QAED,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;YACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;YAChC,OAAO;SACR;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACI,sBAAsB,CAAC,kBAA4B;QACxD,UAAU;QACV,KAAK,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;YACnC,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,GAAG,EAAE;gBAClC,kBAAkB,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;aACvF;SACF;IACH,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;CACF;AArFD,gEAqFC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ICommandLineStringDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineStringParameter}.\n * @public\n */\nexport class CommandLineStringParameter extends CommandLineParameterWithArgument {\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\n public readonly defaultValue: string | undefined;\n\n private _value: string | undefined = undefined;\n\n /** @internal */\n public constructor(definition: ICommandLineStringDefinition) {\n super(definition);\n\n this.defaultValue = definition.defaultValue;\n this.validateDefaultValue(!!this.defaultValue);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.String;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._setValue}\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public _setValue(data: any): void {\n // abstract\n if (data !== null && data !== undefined) {\n if (typeof data !== 'string') {\n this.reportInvalidData(data);\n }\n this._value = data;\n return;\n }\n\n if (this.environmentVariable !== undefined) {\n // Try reading the environment variable\n const environmentValue: string | undefined = process.env[this.environmentVariable];\n if (environmentValue !== undefined) {\n // NOTE: If the environment variable is defined as an empty string,\n // here we will accept the empty string as our value. (For number/flag we don't do that.)\n this._value = environmentValue;\n return;\n }\n }\n\n if (this.defaultValue !== undefined) {\n this._value = this.defaultValue;\n return;\n }\n\n this._value = undefined;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._getSupplementaryNotes}\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n super._getSupplementaryNotes(supplementaryNotes);\n if (this.defaultValue !== undefined) {\n if (this.defaultValue.length < 160) {\n supplementaryNotes.push(`The default value is ${JSON.stringify(this.defaultValue)}.`);\n }\n }\n }\n\n /**\n * Returns the argument value for a string parameter that was parsed from the command line.\n *\n * @remarks\n * The return value will be undefined if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get value(): string | undefined {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value !== undefined) {\n argList.push(this.longName);\n argList.push(this.value);\n }\n }\n}\n"]}

View File

@ -0,0 +1,10 @@
/**
* Some parameter types can receive their values from an environment variable instead of
* a command line argument. This class provides some utility methods for parsing environment
* variable values.
* @internal
*/
export declare class EnvironmentVariableParser {
static parseAsList(envVarName: string): string[] | undefined;
}
//# sourceMappingURL=EnvironmentVariableParser.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"EnvironmentVariableParser.d.ts","sourceRoot":"","sources":["../../src/parameters/EnvironmentVariableParser.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,qBAAa,yBAAyB;WACtB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;CA2CpE"}

View File

@ -0,0 +1,51 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvironmentVariableParser = void 0;
/**
* Some parameter types can receive their values from an environment variable instead of
* a command line argument. This class provides some utility methods for parsing environment
* variable values.
* @internal
*/
class EnvironmentVariableParser {
static parseAsList(envVarName) {
const environmentValue = process.env[envVarName];
if (environmentValue !== undefined) {
// NOTE: If the environment variable is defined as an empty string,
// here we will accept the empty string as our value. (For number/flag we don't do that.)
if (environmentValue.trimLeft()[0] === '[') {
// Specifying multiple items in an environment variable is a somewhat rare case. But environment
// variables are actually a pretty reliable way for a tool to avoid shell escaping problems
// when spawning another tool. For this case, we need a reliable way to pass an array of strings
// that could contain any character. For example, if we simply used ";" as the list delimiter,
// then what to do if a string contains that character? We'd need to design an escaping mechanism.
// Since JSON is simple and standard and can escape every possible string, it's a better option
// than a custom delimiter.
try {
const parsedJson = JSON.parse(environmentValue);
if (!Array.isArray(parsedJson) ||
!parsedJson.every((x) => typeof x === 'string' || typeof x === 'boolean' || typeof x === 'number')) {
throw new Error(`The ${environmentValue} environment variable value must be a JSON ` +
` array containing only strings, numbers, and booleans.`);
}
return parsedJson.map((x) => x.toString());
}
catch (ex) {
throw new Error(`The ${environmentValue} environment variable value looks like a JSON array` +
` but failed to parse: ` +
ex.message);
}
}
else {
// As a shorthand, a single value may be specified without JSON encoding, as long as it does not
// start with the "[" character.
return [environmentValue];
}
}
return undefined;
}
}
exports.EnvironmentVariableParser = EnvironmentVariableParser;
//# sourceMappingURL=EnvironmentVariableParser.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"EnvironmentVariableParser.js","sourceRoot":"","sources":["../../src/parameters/EnvironmentVariableParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;;GAKG;AACH,MAAa,yBAAyB;IAC7B,MAAM,CAAC,WAAW,CAAC,UAAkB;QAC1C,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAErE,IAAI,gBAAgB,KAAK,SAAS,EAAE;YAClC,mEAAmE;YACnE,0FAA0F;YAE1F,IAAI,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC1C,iGAAiG;gBACjG,2FAA2F;gBAC3F,iGAAiG;gBACjG,+FAA+F;gBAC/F,mGAAmG;gBACnG,+FAA+F;gBAC/F,2BAA2B;gBAC3B,IAAI;oBACF,MAAM,UAAU,GAAY,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;oBACzD,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;wBAC1B,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC,EAClG;wBACA,MAAM,IAAI,KAAK,CACb,OAAO,gBAAgB,6CAA6C;4BAClE,wDAAwD,CAC3D,CAAC;qBACH;oBACD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAC5C;gBAAC,OAAO,EAAE,EAAE;oBACX,MAAM,IAAI,KAAK,CACb,OAAO,gBAAgB,qDAAqD;wBAC1E,wBAAwB;wBACvB,EAAY,CAAC,OAAO,CACxB,CAAC;iBACH;aACF;iBAAM;gBACL,gGAAgG;gBAChG,gCAAgC;gBAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC;aAC3B;SACF;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5CD,8DA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * Some parameter types can receive their values from an environment variable instead of\n * a command line argument. This class provides some utility methods for parsing environment\n * variable values.\n * @internal\n */\nexport class EnvironmentVariableParser {\n public static parseAsList(envVarName: string): string[] | undefined {\n const environmentValue: string | undefined = process.env[envVarName];\n\n if (environmentValue !== undefined) {\n // NOTE: If the environment variable is defined as an empty string,\n // here we will accept the empty string as our value. (For number/flag we don't do that.)\n\n if (environmentValue.trimLeft()[0] === '[') {\n // Specifying multiple items in an environment variable is a somewhat rare case. But environment\n // variables are actually a pretty reliable way for a tool to avoid shell escaping problems\n // when spawning another tool. For this case, we need a reliable way to pass an array of strings\n // that could contain any character. For example, if we simply used \";\" as the list delimiter,\n // then what to do if a string contains that character? We'd need to design an escaping mechanism.\n // Since JSON is simple and standard and can escape every possible string, it's a better option\n // than a custom delimiter.\n try {\n const parsedJson: unknown = JSON.parse(environmentValue);\n if (\n !Array.isArray(parsedJson) ||\n !parsedJson.every((x) => typeof x === 'string' || typeof x === 'boolean' || typeof x === 'number')\n ) {\n throw new Error(\n `The ${environmentValue} environment variable value must be a JSON ` +\n ` array containing only strings, numbers, and booleans.`\n );\n }\n return parsedJson.map((x) => x.toString());\n } catch (ex) {\n throw new Error(\n `The ${environmentValue} environment variable value looks like a JSON array` +\n ` but failed to parse: ` +\n (ex as Error).message\n );\n }\n } else {\n // As a shorthand, a single value may be specified without JSON encoding, as long as it does not\n // start with the \"[\" character.\n return [environmentValue];\n }\n }\n\n return undefined;\n }\n}\n"]}