@rushstack/ts-command-line 4.18.1 → 4.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/ts-command-line.d.ts +49 -22
  2. package/lib/index.d.ts +1 -1
  3. package/lib/index.d.ts.map +1 -1
  4. package/lib/index.js +2 -1
  5. package/lib/index.js.map +1 -1
  6. package/lib/parameters/BaseClasses.d.ts +24 -4
  7. package/lib/parameters/BaseClasses.d.ts.map +1 -1
  8. package/lib/parameters/BaseClasses.js +5 -11
  9. package/lib/parameters/BaseClasses.js.map +1 -1
  10. package/lib/parameters/CommandLineChoiceListParameter.d.ts +5 -5
  11. package/lib/parameters/CommandLineChoiceListParameter.d.ts.map +1 -1
  12. package/lib/parameters/CommandLineChoiceListParameter.js +3 -6
  13. package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -1
  14. package/lib/parameters/CommandLineChoiceParameter.d.ts +6 -6
  15. package/lib/parameters/CommandLineChoiceParameter.d.ts.map +1 -1
  16. package/lib/parameters/CommandLineChoiceParameter.js +3 -6
  17. package/lib/parameters/CommandLineChoiceParameter.js.map +1 -1
  18. package/lib/parameters/CommandLineDefinition.d.ts +0 -3
  19. package/lib/parameters/CommandLineDefinition.d.ts.map +1 -1
  20. package/lib/parameters/CommandLineDefinition.js.map +1 -1
  21. package/lib/parameters/CommandLineFlagParameter.d.ts +5 -5
  22. package/lib/parameters/CommandLineFlagParameter.d.ts.map +1 -1
  23. package/lib/parameters/CommandLineFlagParameter.js +3 -6
  24. package/lib/parameters/CommandLineFlagParameter.js.map +1 -1
  25. package/lib/parameters/CommandLineIntegerListParameter.d.ts +3 -3
  26. package/lib/parameters/CommandLineIntegerListParameter.d.ts.map +1 -1
  27. package/lib/parameters/CommandLineIntegerListParameter.js +2 -5
  28. package/lib/parameters/CommandLineIntegerListParameter.js.map +1 -1
  29. package/lib/parameters/CommandLineIntegerParameter.d.ts +4 -4
  30. package/lib/parameters/CommandLineIntegerParameter.d.ts.map +1 -1
  31. package/lib/parameters/CommandLineIntegerParameter.js +2 -5
  32. package/lib/parameters/CommandLineIntegerParameter.js.map +1 -1
  33. package/lib/parameters/CommandLineRemainder.d.ts +1 -1
  34. package/lib/parameters/CommandLineRemainder.d.ts.map +1 -1
  35. package/lib/parameters/CommandLineRemainder.js +0 -1
  36. package/lib/parameters/CommandLineRemainder.js.map +1 -1
  37. package/lib/parameters/CommandLineStringListParameter.d.ts +3 -3
  38. package/lib/parameters/CommandLineStringListParameter.d.ts.map +1 -1
  39. package/lib/parameters/CommandLineStringListParameter.js +2 -5
  40. package/lib/parameters/CommandLineStringListParameter.js.map +1 -1
  41. package/lib/parameters/CommandLineStringParameter.d.ts +4 -4
  42. package/lib/parameters/CommandLineStringParameter.d.ts.map +1 -1
  43. package/lib/parameters/CommandLineStringParameter.js +2 -5
  44. package/lib/parameters/CommandLineStringParameter.js.map +1 -1
  45. package/lib/providers/AliasCommandLineAction.d.ts +1 -1
  46. package/lib/providers/AliasCommandLineAction.d.ts.map +1 -1
  47. package/lib/providers/AliasCommandLineAction.js +13 -19
  48. package/lib/providers/AliasCommandLineAction.js.map +1 -1
  49. package/lib/providers/CommandLineAction.d.ts +2 -8
  50. package/lib/providers/CommandLineAction.d.ts.map +1 -1
  51. package/lib/providers/CommandLineAction.js +0 -7
  52. package/lib/providers/CommandLineAction.js.map +1 -1
  53. package/lib/providers/CommandLineParameterProvider.d.ts +38 -4
  54. package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -1
  55. package/lib/providers/CommandLineParameterProvider.js +118 -43
  56. package/lib/providers/CommandLineParameterProvider.js.map +1 -1
  57. package/lib/providers/CommandLineParser.d.ts.map +1 -1
  58. package/lib/providers/CommandLineParser.js +20 -0
  59. package/lib/providers/CommandLineParser.js.map +1 -1
  60. package/lib/providers/ScopedCommandLineAction.d.ts +6 -3
  61. package/lib/providers/ScopedCommandLineAction.d.ts.map +1 -1
  62. package/lib/providers/ScopedCommandLineAction.js +4 -1
  63. package/lib/providers/ScopedCommandLineAction.js.map +1 -1
  64. package/lib/providers/TabCompletionAction.d.ts +2 -2
  65. package/lib/providers/TabCompletionAction.d.ts.map +1 -1
  66. package/lib/providers/TabCompletionAction.js +5 -7
  67. package/lib/providers/TabCompletionAction.js.map +1 -1
  68. package/package.json +1 -1
@@ -58,7 +58,6 @@ export declare abstract class CommandLineAction extends CommandLineParameterProv
58
58
  private _argumentParser;
59
59
  constructor(options: ICommandLineActionOptions);
60
60
  /* Excluded from this release type: _buildParser */
61
- /* Excluded from this release type: _processParsedData */
62
61
  /* Excluded from this release type: _execute */
63
62
  /* Excluded from this release type: _getArgumentParser */
64
63
  /**
@@ -77,9 +76,9 @@ export declare class CommandLineChoiceListParameter<TChoice extends string = str
77
76
  private _values;
78
77
  /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */
79
78
  readonly completions: (() => Promise<TChoice[]>) | undefined;
80
- /* Excluded from this release type: __constructor */
81
79
  /** {@inheritDoc CommandLineParameter.kind} */
82
- get kind(): CommandLineParameterKind;
80
+ readonly kind: CommandLineParameterKind.ChoiceList;
81
+ /* Excluded from this release type: __constructor */
83
82
  /* Excluded from this release type: _setValue */
84
83
  /**
85
84
  * Returns the string arguments for a choice list parameter that was parsed from the command line.
@@ -105,9 +104,9 @@ export declare class CommandLineChoiceParameter<TChoice extends string = string>
105
104
  private _value;
106
105
  /** {@inheritDoc ICommandLineChoiceDefinition.completions} */
107
106
  readonly completions: (() => Promise<TChoice[]>) | undefined;
108
- /* Excluded from this release type: __constructor */
109
107
  /** {@inheritDoc CommandLineParameter.kind} */
110
- get kind(): CommandLineParameterKind;
108
+ readonly kind: CommandLineParameterKind.Choice;
109
+ /* Excluded from this release type: __constructor */
111
110
  /* Excluded from this release type: _setValue */
112
111
  /* Excluded from this release type: _getSupplementaryNotes */
113
112
  /**
@@ -140,9 +139,9 @@ export declare const enum CommandLineConstants {
140
139
  */
141
140
  export declare class CommandLineFlagParameter extends CommandLineParameter {
142
141
  private _value;
143
- /* Excluded from this release type: __constructor */
144
142
  /** {@inheritDoc CommandLineParameter.kind} */
145
- get kind(): CommandLineParameterKind;
143
+ readonly kind: CommandLineParameterKind.Flag;
144
+ /* Excluded from this release type: __constructor */
146
145
  /* Excluded from this release type: _setValue */
147
146
  /**
148
147
  * Returns a boolean indicating whether the parameter was included in the command line.
@@ -176,9 +175,9 @@ export declare class CommandLineHelper {
176
175
  */
177
176
  export declare class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {
178
177
  private _values;
179
- /* Excluded from this release type: __constructor */
180
178
  /** {@inheritDoc CommandLineParameter.kind} */
181
- get kind(): CommandLineParameterKind;
179
+ readonly kind: CommandLineParameterKind.IntegerList;
180
+ /* Excluded from this release type: __constructor */
182
181
  /* Excluded from this release type: _setValue */
183
182
  /**
184
183
  * Returns the integer arguments for an integer list parameter that was parsed from the command line.
@@ -200,9 +199,9 @@ export declare class CommandLineIntegerParameter extends CommandLineParameterWit
200
199
  /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
201
200
  readonly defaultValue: number | undefined;
202
201
  private _value;
203
- /* Excluded from this release type: __constructor */
204
202
  /** {@inheritDoc CommandLineParameter.kind} */
205
- get kind(): CommandLineParameterKind;
203
+ readonly kind: CommandLineParameterKind.Integer;
204
+ /* Excluded from this release type: __constructor */
206
205
  /* Excluded from this release type: _setValue */
207
206
  /* Excluded from this release type: _getSupplementaryNotes */
208
207
  /**
@@ -224,6 +223,9 @@ export declare class CommandLineIntegerParameter extends CommandLineParameterWit
224
223
  export declare abstract class CommandLineParameter {
225
224
  private _shortNameValue;
226
225
  /* Excluded from this release type: _parserKey */
226
+ /* Excluded from this release type: _preParse */
227
+ /* Excluded from this release type: _postParse */
228
+ /* Excluded from this release type: _validateValue */
227
229
  /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */
228
230
  readonly longName: string;
229
231
  /**
@@ -271,10 +273,12 @@ export declare abstract class CommandLineParameter {
271
273
  /**
272
274
  * Internal usage only. Used to report unexpected output from the argparse library.
273
275
  */
274
- protected reportInvalidData(data: any): never;
276
+ protected reportInvalidData(data: unknown): never;
275
277
  protected validateDefaultValue(hasDefaultValue: boolean): void;
276
278
  }
277
279
 
280
+ declare type CommandLineParameter_2 = CommandLineChoiceListParameter | CommandLineChoiceParameter | CommandLineFlagParameter | CommandLineIntegerListParameter | CommandLineIntegerParameter | CommandLineStringListParameter | CommandLineStringParameter;
281
+
278
282
  /**
279
283
  * Identifies the kind of a CommandLineParameter.
280
284
  * @public
@@ -339,6 +343,7 @@ export declare abstract class CommandLineParameterProvider {
339
343
  */
340
344
  defineChoiceParameter<TChoice extends string = string>(definition: ICommandLineChoiceDefinition<TChoice> & {
341
345
  required: false | undefined;
346
+ defaultValue: undefined;
342
347
  }): CommandLineChoiceParameter<TChoice>;
343
348
  /**
344
349
  * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}
@@ -346,6 +351,12 @@ export declare abstract class CommandLineParameterProvider {
346
351
  defineChoiceParameter<TChoice extends string = string>(definition: ICommandLineChoiceDefinition<TChoice> & {
347
352
  required: true;
348
353
  }): IRequiredCommandLineChoiceParameter<TChoice>;
354
+ /**
355
+ * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}
356
+ */
357
+ defineChoiceParameter<TChoice extends string = string>(definition: ICommandLineChoiceDefinition<TChoice> & {
358
+ defaultValue: TChoice;
359
+ }): IRequiredCommandLineChoiceParameter<TChoice>;
349
360
  /**
350
361
  * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}
351
362
  */
@@ -402,6 +413,7 @@ export declare abstract class CommandLineParameterProvider {
402
413
  */
403
414
  defineIntegerParameter(definition: ICommandLineIntegerDefinition & {
404
415
  required: false | undefined;
416
+ defaultValue: undefined;
405
417
  }): CommandLineIntegerParameter;
406
418
  /**
407
419
  * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}
@@ -409,6 +421,12 @@ export declare abstract class CommandLineParameterProvider {
409
421
  defineIntegerParameter(definition: ICommandLineIntegerDefinition & {
410
422
  required: true;
411
423
  }): IRequiredCommandLineIntegerParameter;
424
+ /**
425
+ * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}
426
+ */
427
+ defineIntegerParameter(definition: ICommandLineIntegerDefinition & {
428
+ defaultValue: number;
429
+ }): IRequiredCommandLineIntegerParameter;
412
430
  /**
413
431
  * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}
414
432
  */
@@ -447,6 +465,7 @@ export declare abstract class CommandLineParameterProvider {
447
465
  */
448
466
  defineStringParameter(definition: ICommandLineStringDefinition & {
449
467
  required: false | undefined;
468
+ defaultValue: undefined;
450
469
  }): CommandLineStringParameter;
451
470
  /**
452
471
  * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}
@@ -454,6 +473,12 @@ export declare abstract class CommandLineParameterProvider {
454
473
  defineStringParameter(definition: ICommandLineStringDefinition & {
455
474
  required: true;
456
475
  }): IRequiredCommandLineStringParameter;
476
+ /**
477
+ * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}
478
+ */
479
+ defineStringParameter(definition: ICommandLineStringDefinition & {
480
+ defaultValue: string;
481
+ }): IRequiredCommandLineStringParameter;
457
482
  /**
458
483
  * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}
459
484
  */
@@ -522,6 +547,8 @@ export declare abstract class CommandLineParameterProvider {
522
547
  */
523
548
  protected onDefineParameters?(): void;
524
549
  /* Excluded from this release type: _getArgumentParser */
550
+ /* Excluded from this release type: _preParse */
551
+ /* Excluded from this release type: _postParse */
525
552
  /* Excluded from this release type: _processParsedData */
526
553
  /* Excluded from this release type: _defineParameter */
527
554
  /* Excluded from this release type: _defineAmbiguousParameter */
@@ -653,9 +680,9 @@ export declare class CommandLineRemainder {
653
680
  */
654
681
  export declare class CommandLineStringListParameter extends CommandLineParameterWithArgument {
655
682
  private _values;
656
- /* Excluded from this release type: __constructor */
657
683
  /** {@inheritDoc CommandLineParameter.kind} */
658
- get kind(): CommandLineParameterKind;
684
+ readonly kind: CommandLineParameterKind.StringList;
685
+ /* Excluded from this release type: __constructor */
659
686
  /* Excluded from this release type: _setValue */
660
687
  /**
661
688
  * Returns the string arguments for a string list parameter that was parsed from the command line.
@@ -677,9 +704,9 @@ export declare class CommandLineStringParameter extends CommandLineParameterWith
677
704
  /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
678
705
  readonly defaultValue: string | undefined;
679
706
  private _value;
680
- /* Excluded from this release type: __constructor */
681
707
  /** {@inheritDoc CommandLineParameter.kind} */
682
- get kind(): CommandLineParameterKind;
708
+ readonly kind: CommandLineParameterKind.String;
709
+ /* Excluded from this release type: __constructor */
683
710
  /* Excluded from this release type: _setValue */
684
711
  /* Excluded from this release type: _getSupplementaryNotes */
685
712
  /**
@@ -775,9 +802,6 @@ export declare interface IBaseCommandLineDefinition {
775
802
  * `{@link IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames}`
776
803
  * to `true`.
777
804
  *
778
- * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,
779
- * because in that case the environmentVariable would never be used.
780
- *
781
805
  * Syntax notes for environment variable values:
782
806
  *
783
807
  * - Choice Parameter: The value must match one of the defined choices,
@@ -1031,7 +1055,7 @@ export declare interface ICommandLineStringListDefinition extends IBaseCommandLi
1031
1055
  * @public
1032
1056
  */
1033
1057
  export declare interface IRequiredCommandLineChoiceParameter<TChoice extends string = string> extends CommandLineChoiceParameter<TChoice> {
1034
- value: TChoice;
1058
+ readonly value: TChoice;
1035
1059
  }
1036
1060
 
1037
1061
  /**
@@ -1039,7 +1063,7 @@ export declare interface IRequiredCommandLineChoiceParameter<TChoice extends str
1039
1063
  * @public
1040
1064
  */
1041
1065
  export declare interface IRequiredCommandLineIntegerParameter extends CommandLineIntegerParameter {
1042
- value: number;
1066
+ readonly value: number;
1043
1067
  }
1044
1068
 
1045
1069
  /**
@@ -1047,7 +1071,7 @@ export declare interface IRequiredCommandLineIntegerParameter extends CommandLin
1047
1071
  * @public
1048
1072
  */
1049
1073
  export declare interface IRequiredCommandLineStringParameter extends CommandLineStringParameter {
1050
- value: string;
1074
+ readonly value: string;
1051
1075
  }
1052
1076
 
1053
1077
  /**
@@ -1103,6 +1127,9 @@ export declare abstract class ScopedCommandLineAction extends CommandLineAction
1103
1127
  constructor(options: ICommandLineActionOptions);
1104
1128
  /**
1105
1129
  * {@inheritDoc CommandLineParameterProvider.parameters}
1130
+ *
1131
+ * @internalremarks
1132
+ * TODO: Replace this type with `CommandLineParameter` in the next major bump.
1106
1133
  */
1107
1134
  get parameters(): ReadonlyArray<CommandLineParameter>;
1108
1135
  /* Excluded from this release type: _processParsedData */
package/lib/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';
8
8
  export { ScopedCommandLineAction } from './providers/ScopedCommandLineAction';
9
9
  export { AliasCommandLineAction, type IAliasCommandLineActionOptions } from './providers/AliasCommandLineAction';
10
10
  export type { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument, ICommandLineFlagDefinition, ICommandLineStringDefinition, ICommandLineStringListDefinition, ICommandLineIntegerDefinition, ICommandLineIntegerListDefinition, ICommandLineChoiceDefinition, ICommandLineChoiceListDefinition, ICommandLineRemainderDefinition } from './parameters/CommandLineDefinition';
11
- export { CommandLineParameterKind, CommandLineParameter, CommandLineParameterWithArgument } from './parameters/BaseClasses';
11
+ export { CommandLineParameterKind, CommandLineParameterBase as CommandLineParameter, CommandLineParameterWithArgument } from './parameters/BaseClasses';
12
12
  export { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';
13
13
  export { CommandLineStringParameter, type IRequiredCommandLineStringParameter } from './parameters/CommandLineStringParameter';
14
14
  export { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,EAAE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MAAM,mCAAmC,CAAC;AAEzE,OAAO,EACL,4BAA4B,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,IAAI,uBAAuB,EACtD,KAAK,+BAA+B,IAAI,gCAAgC,EACzE,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,KAAK,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
package/lib/index.js CHANGED
@@ -18,7 +18,8 @@ var AliasCommandLineAction_1 = require("./providers/AliasCommandLineAction");
18
18
  Object.defineProperty(exports, "AliasCommandLineAction", { enumerable: true, get: function () { return AliasCommandLineAction_1.AliasCommandLineAction; } });
19
19
  var BaseClasses_1 = require("./parameters/BaseClasses");
20
20
  Object.defineProperty(exports, "CommandLineParameterKind", { enumerable: true, get: function () { return BaseClasses_1.CommandLineParameterKind; } });
21
- Object.defineProperty(exports, "CommandLineParameter", { enumerable: true, get: function () { return BaseClasses_1.CommandLineParameter; } });
21
+ // TODO: Export both `CommandLineParameter` and `CommandLineParameterBase` in the next major bump
22
+ Object.defineProperty(exports, "CommandLineParameter", { enumerable: true, get: function () { return BaseClasses_1.CommandLineParameterBase; } });
22
23
  Object.defineProperty(exports, "CommandLineParameterWithArgument", { enumerable: true, get: function () { return BaseClasses_1.CommandLineParameterWithArgument; } });
23
24
  var CommandLineFlagParameter_1 = require("./parameters/CommandLineFlagParameter");
24
25
  Object.defineProperty(exports, "CommandLineFlagParameter", { enumerable: true, get: function () { return CommandLineFlagParameter_1.CommandLineFlagParameter; } });
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;GAIG;AAEH,mEAAkG;AAAzF,sHAAA,iBAAiB,OAAA;AAC1B,iFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AACjC,+EAA8E;AAArE,kIAAA,uBAAuB,OAAA;AAChC,6EAG4C;AAF1C,gIAAA,sBAAsB,OAAA;AAiBxB,wDAIkC;AAHhC,uHAAA,wBAAwB,OAAA;AACxB,mHAAA,oBAAoB,OAAA;AACpB,+HAAA,gCAAgC,OAAA;AAGlC,kFAAiF;AAAxE,oIAAA,wBAAwB,OAAA;AACjC,sFAGiD;AAF/C,wIAAA,0BAA0B,OAAA;AAG5B,8FAA6F;AAApF,gJAAA,8BAA8B,OAAA;AACvC,wFAGkD;AAFhD,0IAAA,2BAA2B,OAAA;AAG7B,gGAA+F;AAAtF,kJAAA,+BAA+B,OAAA;AACxC,sFAGiD;AAF/C,wIAAA,0BAA0B,OAAA;AAG5B,8FAA6F;AAApF,gJAAA,8BAA8B,OAAA;AACvC,0EAAyE;AAAhE,4HAAA,oBAAoB,OAAA;AAE7B,yFAKkD;AAJhD,4IAAA,4BAA4B,OAAA;AAM9B,mEAAkG;AAAzF,sHAAA,iBAAiB,OAAA;AAC1B,iFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AAIjC,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA","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 * An object-oriented command-line parser for TypeScript projects.\n *\n * @packageDocumentation\n */\n\nexport { CommandLineAction, type ICommandLineActionOptions } from './providers/CommandLineAction';\nexport { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';\nexport { ScopedCommandLineAction } from './providers/ScopedCommandLineAction';\nexport {\n AliasCommandLineAction,\n type IAliasCommandLineActionOptions\n} from './providers/AliasCommandLineAction';\n\nexport type {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineRemainderDefinition\n} from './parameters/CommandLineDefinition';\n\nexport {\n CommandLineParameterKind,\n CommandLineParameter,\n CommandLineParameterWithArgument\n} from './parameters/BaseClasses';\n\nexport { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';\nexport {\n CommandLineStringParameter,\n type IRequiredCommandLineStringParameter\n} from './parameters/CommandLineStringParameter';\nexport { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';\nexport {\n CommandLineIntegerParameter,\n type IRequiredCommandLineIntegerParameter\n} from './parameters/CommandLineIntegerParameter';\nexport { CommandLineIntegerListParameter } from './parameters/CommandLineIntegerListParameter';\nexport {\n CommandLineChoiceParameter,\n type IRequiredCommandLineChoiceParameter\n} from './parameters/CommandLineChoiceParameter';\nexport { CommandLineChoiceListParameter } from './parameters/CommandLineChoiceListParameter';\nexport { CommandLineRemainder } from './parameters/CommandLineRemainder';\n\nexport {\n CommandLineParameterProvider,\n type IScopedLongNameParseResult,\n type ICommandLineParserData as _ICommandLineParserData,\n type IRegisterDefinedParametersState as _IRegisterDefinedParametersState\n} from './providers/CommandLineParameterProvider';\n\nexport { CommandLineParser, type ICommandLineParserOptions } from './providers/CommandLineParser';\nexport { DynamicCommandLineParser } from './providers/DynamicCommandLineParser';\n\nexport { CommandLineConstants } from './Constants';\n\nexport { CommandLineHelper } from './CommandLineHelper';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;GAIG;AAEH,mEAAkG;AAAzF,sHAAA,iBAAiB,OAAA;AAC1B,iFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AACjC,+EAA8E;AAArE,kIAAA,uBAAuB,OAAA;AAChC,6EAG4C;AAF1C,gIAAA,sBAAsB,OAAA;AAiBxB,wDAKkC;AAJhC,uHAAA,wBAAwB,OAAA;AACxB,iGAAiG;AACjG,mHAAA,wBAAwB,OAAwB;AAChD,+HAAA,gCAAgC,OAAA;AAGlC,kFAAiF;AAAxE,oIAAA,wBAAwB,OAAA;AACjC,sFAGiD;AAF/C,wIAAA,0BAA0B,OAAA;AAG5B,8FAA6F;AAApF,gJAAA,8BAA8B,OAAA;AACvC,wFAGkD;AAFhD,0IAAA,2BAA2B,OAAA;AAG7B,gGAA+F;AAAtF,kJAAA,+BAA+B,OAAA;AACxC,sFAGiD;AAF/C,wIAAA,0BAA0B,OAAA;AAG5B,8FAA6F;AAApF,gJAAA,8BAA8B,OAAA;AACvC,0EAAyE;AAAhE,4HAAA,oBAAoB,OAAA;AAE7B,yFAKkD;AAJhD,4IAAA,4BAA4B,OAAA;AAM9B,mEAAkG;AAAzF,sHAAA,iBAAiB,OAAA;AAC1B,iFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AAIjC,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA","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 * An object-oriented command-line parser for TypeScript projects.\n *\n * @packageDocumentation\n */\n\nexport { CommandLineAction, type ICommandLineActionOptions } from './providers/CommandLineAction';\nexport { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';\nexport { ScopedCommandLineAction } from './providers/ScopedCommandLineAction';\nexport {\n AliasCommandLineAction,\n type IAliasCommandLineActionOptions\n} from './providers/AliasCommandLineAction';\n\nexport type {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineRemainderDefinition\n} from './parameters/CommandLineDefinition';\n\nexport {\n CommandLineParameterKind,\n // TODO: Export both `CommandLineParameter` and `CommandLineParameterBase` in the next major bump\n CommandLineParameterBase as CommandLineParameter,\n CommandLineParameterWithArgument\n} from './parameters/BaseClasses';\n\nexport { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';\nexport {\n CommandLineStringParameter,\n type IRequiredCommandLineStringParameter\n} from './parameters/CommandLineStringParameter';\nexport { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';\nexport {\n CommandLineIntegerParameter,\n type IRequiredCommandLineIntegerParameter\n} from './parameters/CommandLineIntegerParameter';\nexport { CommandLineIntegerListParameter } from './parameters/CommandLineIntegerListParameter';\nexport {\n CommandLineChoiceParameter,\n type IRequiredCommandLineChoiceParameter\n} from './parameters/CommandLineChoiceParameter';\nexport { CommandLineChoiceListParameter } from './parameters/CommandLineChoiceListParameter';\nexport { CommandLineRemainder } from './parameters/CommandLineRemainder';\n\nexport {\n CommandLineParameterProvider,\n type IScopedLongNameParseResult,\n type ICommandLineParserData as _ICommandLineParserData,\n type IRegisterDefinedParametersState as _IRegisterDefinedParametersState\n} from './providers/CommandLineParameterProvider';\n\nexport { CommandLineParser, type ICommandLineParserOptions } from './providers/CommandLineParser';\nexport { DynamicCommandLineParser } from './providers/DynamicCommandLineParser';\n\nexport { CommandLineConstants } from './Constants';\n\nexport { CommandLineHelper } from './CommandLineHelper';\n"]}
@@ -1,5 +1,12 @@
1
1
  import type { SCOPING_PARAMETER_GROUP } from '../Constants';
2
2
  import type { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument } from './CommandLineDefinition';
3
+ import type { CommandLineChoiceListParameter } from './CommandLineChoiceListParameter';
4
+ import type { CommandLineChoiceParameter } from './CommandLineChoiceParameter';
5
+ import type { CommandLineFlagParameter } from './CommandLineFlagParameter';
6
+ import type { CommandLineIntegerListParameter } from './CommandLineIntegerListParameter';
7
+ import type { CommandLineIntegerParameter } from './CommandLineIntegerParameter';
8
+ import type { CommandLineStringListParameter } from './CommandLineStringListParameter';
9
+ import type { CommandLineStringParameter } from './CommandLineStringParameter';
3
10
  /**
4
11
  * Identifies the kind of a CommandLineParameter.
5
12
  * @public
@@ -20,17 +27,30 @@ export declare enum CommandLineParameterKind {
20
27
  /** Indicates a CommandLineIntegerListParameter */
21
28
  IntegerList = 6
22
29
  }
30
+ export type CommandLineParameter = CommandLineChoiceListParameter | CommandLineChoiceParameter | CommandLineFlagParameter | CommandLineIntegerListParameter | CommandLineIntegerParameter | CommandLineStringListParameter | CommandLineStringParameter;
23
31
  /**
24
32
  * The base class for the various command-line parameter types.
25
33
  * @public
26
34
  */
27
- export declare abstract class CommandLineParameter {
35
+ export declare abstract class CommandLineParameterBase {
28
36
  private _shortNameValue;
29
37
  /**
30
38
  * A unique internal key used to retrieve the value from the parser's dictionary.
31
39
  * @internal
32
40
  */
33
41
  _parserKey: string | undefined;
42
+ /**
43
+ * @internal
44
+ */
45
+ _preParse?: () => void;
46
+ /**
47
+ * @internal
48
+ */
49
+ _postParse?: () => void;
50
+ /**
51
+ * @internal
52
+ */
53
+ _validateValue?: () => void;
34
54
  /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */
35
55
  readonly longName: string;
36
56
  /**
@@ -60,7 +80,7 @@ export declare abstract class CommandLineParameter {
60
80
  * Called internally by CommandLineParameterProvider._processParsedData()
61
81
  * @internal
62
82
  */
63
- abstract _setValue(data: any): void;
83
+ abstract _setValue(data: unknown): void;
64
84
  /**
65
85
  * Returns additional text used by the help formatter.
66
86
  * @internal
@@ -87,7 +107,7 @@ export declare abstract class CommandLineParameter {
87
107
  /**
88
108
  * Internal usage only. Used to report unexpected output from the argparse library.
89
109
  */
90
- protected reportInvalidData(data: any): never;
110
+ protected reportInvalidData(data: unknown): never;
91
111
  protected validateDefaultValue(hasDefaultValue: boolean): void;
92
112
  }
93
113
  /**
@@ -98,7 +118,7 @@ export declare abstract class CommandLineParameter {
98
118
  * example "--max-count 123".
99
119
  * @public
100
120
  */
101
- export declare abstract class CommandLineParameterWithArgument extends CommandLineParameter {
121
+ export declare abstract class CommandLineParameterWithArgument extends CommandLineParameterBase {
102
122
  private static _invalidArgumentNameRegExp;
103
123
  /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */
104
124
  readonly argumentName: string;
@@ -1 +1 @@
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,wFAAwF;IACxF,SAAg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@@ -2,7 +2,7 @@
2
2
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.CommandLineParameterWithArgument = exports.CommandLineParameter = exports.CommandLineParameterKind = void 0;
5
+ exports.CommandLineParameterWithArgument = exports.CommandLineParameterBase = exports.CommandLineParameterKind = void 0;
6
6
  /**
7
7
  * Identifies the kind of a CommandLineParameter.
8
8
  * @public
@@ -50,7 +50,7 @@ const ENVIRONMENT_VARIABLE_NAME_REGEXP = /^[A-Z_][A-Z0-9_]*$/;
50
50
  * The base class for the various command-line parameter types.
51
51
  * @public
52
52
  */
53
- class CommandLineParameter {
53
+ class CommandLineParameterBase {
54
54
  /** @internal */
55
55
  constructor(definition) {
56
56
  this.longName = definition.parameterLongName;
@@ -61,6 +61,7 @@ class CommandLineParameter {
61
61
  this.required = !!definition.required;
62
62
  this.environmentVariable = definition.environmentVariable;
63
63
  this.undocumentedSynonyms = definition.undocumentedSynonyms;
64
+ this.allowNonStandardEnvironmentVariableNames = definition.allowNonStandardEnvironmentVariableNames;
64
65
  if (!LONG_NAME_REGEXP.test(this.longName)) {
65
66
  throw new Error(`Invalid name: "${this.longName}". The parameter long name must be` +
66
67
  ` lower-case and use dash delimiters (e.g. "--do-a-thing")`);
@@ -81,12 +82,6 @@ class CommandLineParameter {
81
82
  this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;
82
83
  }
83
84
  if (this.environmentVariable) {
84
- if (this.required) {
85
- // TODO: This constraint is imposed only because argparse enforces "required" parameters, but
86
- // it does not know about ts-command-line environment variable mappings. We should fix this.
87
- throw new Error(`An "environmentVariable" cannot be specified for "${this.longName}"` +
88
- ` because it is a required parameter`);
89
- }
90
85
  if (!this.allowNonStandardEnvironmentVariableNames &&
91
86
  !ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)) {
92
87
  throw new Error(`Invalid environment variable name: "${this.environmentVariable}". The name must` +
@@ -125,7 +120,6 @@ class CommandLineParameter {
125
120
  /**
126
121
  * Internal usage only. Used to report unexpected output from the argparse library.
127
122
  */
128
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
123
  reportInvalidData(data) {
130
124
  throw new Error(`Unexpected data object for parameter "${this.longName}": ` + JSON.stringify(data));
131
125
  }
@@ -140,7 +134,7 @@ class CommandLineParameter {
140
134
  }
141
135
  }
142
136
  }
143
- exports.CommandLineParameter = CommandLineParameter;
137
+ exports.CommandLineParameterBase = CommandLineParameterBase;
144
138
  /**
145
139
  * The common base class for parameters types that receive an argument.
146
140
  *
@@ -149,7 +143,7 @@ exports.CommandLineParameter = CommandLineParameter;
149
143
  * example "--max-count 123".
150
144
  * @public
151
145
  */
152
- class CommandLineParameterWithArgument extends CommandLineParameter {
146
+ class CommandLineParameterWithArgument extends CommandLineParameterBase {
153
147
  /** @internal */
154
148
  constructor(definition) {
155
149
  super(definition);
@@ -1 +1 @@
1
- {"version":3,"file":"BaseClasses.js","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAQ3D;;;GAGG;AACH,IAAY,wBAeX;AAfD,WAAY,wBAAwB;IAClC,6CAA6C;IAC7C,2EAAM,CAAA;IACN,2CAA2C;IAC3C,uEAAI,CAAA;IACJ,8CAA8C;IAC9C,6EAAO,CAAA;IACP,6CAA6C;IAC7C,2EAAM,CAAA;IACN,iDAAiD;IACjD,mFAAU,CAAA;IACV,iDAAiD;IACjD,mFAAU,CAAA;IACV,kDAAkD;IAClD,qFAAW,CAAA;AACb,CAAC,EAfW,wBAAwB,wCAAxB,wBAAwB,QAenC;AAED;;;GAGG;AACH,MAAM,gBAAgB,GAAW,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,MAAM,iBAAiB,GAAW,aAAa,CAAC;AAEhD;;;GAGG;AACH,MAAM,YAAY,GAAW,0BAA0B,CAAC;AAExD;;;;;GAKG;AACH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,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,CAAC,YAAY,oCAAoC,KAAK,CAAC,CAAC,CAAC,IAAI;gBAC3F,iEAAiE,CACpE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;;AAnCH,4EAoCC;AAnCC,oGAAoG;AACrF,2DAA0B,GAAW,YAAY,CAAC","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 { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport type {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument\n} from './CommandLineDefinition';\n\n/**\n * Identifies the kind of a CommandLineParameter.\n * @public\n */\nexport enum CommandLineParameterKind {\n /** Indicates a CommandLineChoiceParameter */\n Choice,\n /** Indicates a CommandLineFlagParameter */\n Flag,\n /** Indicates a CommandLineIntegerParameter */\n Integer,\n /** Indicates a CommandLineStringParameter */\n String,\n /** Indicates a CommandLineStringListParameter */\n StringList,\n /** Indicates a CommandLineChoiceListParameter */\n ChoiceList,\n /** Indicates a CommandLineIntegerListParameter */\n IntegerList\n}\n\n/**\n * Matches kebab-case formatted strings prefixed with double dashes.\n * Example: \"--do-something\"\n */\nconst LONG_NAME_REGEXP: RegExp = /^-(-[a-z0-9]+)+$/;\n\n/**\n * Matches a single upper-case or lower-case letter prefixed with a dash.\n * Example: \"-d\"\n */\nconst SHORT_NAME_REGEXP: RegExp = /^-[a-zA-Z]$/;\n\n/**\n * Matches kebab-case formatted strings\n * Example: \"my-scope\"\n */\nconst SCOPE_REGEXP: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/;\n\n/**\n * \"Environment variable names used by the utilities in the Shell and Utilities volume of\n * IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)\n * from the characters defined in Portable Character Set and do not begin with a digit.\"\n * Example: \"THE_SETTING\"\n */\nconst ENVIRONMENT_VARIABLE_NAME_REGEXP: RegExp = /^[A-Z_][A-Z0-9_]*$/;\n\n/**\n * The base class for the various command-line parameter types.\n * @public\n */\nexport abstract class CommandLineParameter {\n private _shortNameValue: string | undefined;\n\n /**\n * A unique internal key used to retrieve the value from the parser's dictionary.\n * @internal\n */\n public _parserKey: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */\n public readonly longName: string;\n\n /**\n * If a parameterScope is provided, returns the scope-prefixed long name of the flag,\n * including double dashes, eg. \"--scope:do-something\". Otherwise undefined.\n */\n public readonly scopedLongName: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */\n public readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */\n public readonly parameterScope: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** {@inheritDoc IBaseCommandLineDefinition.required} */\n public readonly required: boolean;\n\n /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */\n public readonly environmentVariable: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames} */\n public readonly allowNonStandardEnvironmentVariableNames: boolean | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */\n public readonly undocumentedSynonyms: string[] | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinition) {\n this.longName = definition.parameterLongName;\n this._shortNameValue = definition.parameterShortName;\n this.parameterGroup = definition.parameterGroup;\n this.parameterScope = definition.parameterScope;\n this.description = definition.description;\n this.required = !!definition.required;\n this.environmentVariable = definition.environmentVariable;\n this.undocumentedSynonyms = definition.undocumentedSynonyms;\n\n if (!LONG_NAME_REGEXP.test(this.longName)) {\n throw new Error(\n `Invalid name: \"${this.longName}\". The parameter long name must be` +\n ` lower-case and use dash delimiters (e.g. \"--do-a-thing\")`\n );\n }\n\n if (this.shortName) {\n if (!SHORT_NAME_REGEXP.test(this.shortName)) {\n throw new Error(\n `Invalid name: \"${this.shortName}\". The parameter short name must be` +\n ` a dash followed by a single upper-case or lower-case letter (e.g. \"-a\")`\n );\n }\n }\n\n if (this.parameterScope) {\n if (!SCOPE_REGEXP.test(this.parameterScope)) {\n throw new Error(\n `Invalid scope: \"${this.parameterScope}\". The parameter scope name must be` +\n ` lower-case and use dash delimiters (e.g. \"my-scope\")`\n );\n }\n // Parameter long name is guaranteed to start with '--' since this is validated above\n const unprefixedLongName: string = this.longName.slice(2);\n this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;\n }\n\n if (this.environmentVariable) {\n if (this.required) {\n // TODO: This constraint is imposed only because argparse enforces \"required\" parameters, but\n // it does not know about ts-command-line environment variable mappings. We should fix this.\n throw new Error(\n `An \"environmentVariable\" cannot be specified for \"${this.longName}\"` +\n ` because it is a required parameter`\n );\n }\n\n if (\n !this.allowNonStandardEnvironmentVariableNames &&\n !ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)\n ) {\n throw new Error(\n `Invalid environment variable name: \"${this.environmentVariable}\". The name must` +\n ` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`\n );\n }\n }\n\n if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {\n for (const undocumentedSynonym of this.undocumentedSynonyms) {\n if (this.longName === undocumentedSynonym) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". Undocumented synonyms must not be the same` +\n ` as the the long name.`\n );\n } else if (!LONG_NAME_REGEXP.test(undocumentedSynonym)) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". All undocumented synonyms name must be lower-case and ` +\n 'use dash delimiters (e.g. \"--do-a-thing\")'\n );\n }\n }\n }\n }\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */\n public get shortName(): string | undefined {\n return this._shortNameValue;\n }\n\n /**\n * Called internally by CommandLineParameterProvider._processParsedData()\n * @internal\n */\n public abstract _setValue(data: any): void; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /**\n * Returns additional text used by the help formatter.\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n if (this.environmentVariable !== undefined) {\n supplementaryNotes.push(\n 'This parameter may alternatively be specified via the ' +\n this.environmentVariable +\n ' environment variable.'\n );\n }\n }\n\n /**\n * Indicates the type of parameter.\n */\n public abstract get kind(): CommandLineParameterKind;\n\n /**\n * Append the parsed values to the provided string array.\n * @remarks\n * Sometimes a command line parameter is not used directly, but instead gets passed through to another\n * tool that will use it. For example if our parameter comes in as \"--max-count 3\", then we might want to\n * call `child_process.spawn()` and append [\"--max-count\", \"3\"] to the args array for that tool.\n * appendToArgList() appends zero or more strings to the provided array, based on the input command-line\n * that we parsed.\n *\n * If the parameter was omitted from our command-line and has no default value, then\n * nothing will be appended. If the short name was used, the long name will be appended instead.\n * @param argList - the parsed strings will be appended to this string array\n */\n public abstract appendToArgList(argList: string[]): void;\n\n /**\n * Internal usage only. Used to report unexpected output from the argparse library.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected reportInvalidData(data: any): never {\n throw new Error(`Unexpected data object for parameter \"${this.longName}\": ` + JSON.stringify(data));\n }\n\n protected validateDefaultValue(hasDefaultValue: boolean): void {\n if (this.required && hasDefaultValue) {\n // If a parameter is \"required\", then the user understands that they always need to\n // specify a value for this parameter (either via the command line or via an environment variable).\n // It would be confusing to allow a default value that sometimes allows the \"required\" parameter\n // to be omitted. If you sometimes don't have a suitable default value, then the better approach\n // is to throw a custom error explaining why the parameter is required in that case.\n throw new Error(\n `A default value cannot be specified for \"${this.longName}\" because it is a \"required\" parameter`\n );\n }\n }\n}\n\n/**\n * The common base class for parameters types that receive an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport abstract class CommandLineParameterWithArgument extends CommandLineParameter {\n // Matches the first character that *isn't* part of a valid upper-case argument name such as \"URL_2\"\n private static _invalidArgumentNameRegExp: RegExp = /[^A-Z_0-9]/;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */\n public readonly argumentName: string;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */\n public readonly completions: (() => Promise<string[]>) | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinitionWithArgument) {\n super(definition);\n\n if (definition.argumentName === '') {\n throw new Error(\n 'The argument name cannot be an empty string. (For the default name, specify undefined.)'\n );\n }\n if (definition.argumentName.toUpperCase() !== definition.argumentName) {\n throw new Error(\n `Invalid name: \"${definition.argumentName}\". The argument name must be all upper case.`\n );\n }\n const match: RegExpMatchArray | null = definition.argumentName.match(\n CommandLineParameterWithArgument._invalidArgumentNameRegExp\n );\n if (match) {\n throw new Error(\n `The argument name \"${definition.argumentName}\" contains an invalid character \"${match[0]}\".` +\n ` Only upper-case letters, numbers, and underscores are allowed.`\n );\n }\n this.argumentName = definition.argumentName;\n this.completions = definition.completions;\n }\n}\n"]}
1
+ {"version":3,"file":"BaseClasses.js","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAe3D;;;GAGG;AACH,IAAY,wBAeX;AAfD,WAAY,wBAAwB;IAClC,6CAA6C;IAC7C,2EAAM,CAAA;IACN,2CAA2C;IAC3C,uEAAI,CAAA;IACJ,8CAA8C;IAC9C,6EAAO,CAAA;IACP,6CAA6C;IAC7C,2EAAM,CAAA;IACN,iDAAiD;IACjD,mFAAU,CAAA;IACV,iDAAiD;IACjD,mFAAU,CAAA;IACV,kDAAkD;IAClD,qFAAW,CAAA;AACb,CAAC,EAfW,wBAAwB,wCAAxB,wBAAwB,QAenC;AAED;;;GAGG;AACH,MAAM,gBAAgB,GAAW,kBAAkB,CAAC;AAEpD;;;GA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AAM,IAAI,KAAK,CACb,sBAAsB,UAAU,CAAC,YAAY,oCAAoC,KAAK,CAAC,CAAC,CAAC,IAAI;gBAC3F,iEAAiE,CACpE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;;AAnCH,4EAoCC;AAnCC,oGAAoG;AACrF,2DAA0B,GAAW,YAAY,CAAC","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 { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport type {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument\n} from './CommandLineDefinition';\nimport type { CommandLineChoiceListParameter } from './CommandLineChoiceListParameter';\nimport type { CommandLineChoiceParameter } from './CommandLineChoiceParameter';\nimport type { CommandLineFlagParameter } from './CommandLineFlagParameter';\nimport type { CommandLineIntegerListParameter } from './CommandLineIntegerListParameter';\nimport type { CommandLineIntegerParameter } from './CommandLineIntegerParameter';\nimport type { CommandLineStringListParameter } from './CommandLineStringListParameter';\nimport type { CommandLineStringParameter } from './CommandLineStringParameter';\n\n/**\n * Identifies the kind of a CommandLineParameter.\n * @public\n */\nexport enum CommandLineParameterKind {\n /** Indicates a CommandLineChoiceParameter */\n Choice,\n /** Indicates a CommandLineFlagParameter */\n Flag,\n /** Indicates a CommandLineIntegerParameter */\n Integer,\n /** Indicates a CommandLineStringParameter */\n String,\n /** Indicates a CommandLineStringListParameter */\n StringList,\n /** Indicates a CommandLineChoiceListParameter */\n ChoiceList,\n /** Indicates a CommandLineIntegerListParameter */\n IntegerList\n}\n\n/**\n * Matches kebab-case formatted strings prefixed with double dashes.\n * Example: \"--do-something\"\n */\nconst LONG_NAME_REGEXP: RegExp = /^-(-[a-z0-9]+)+$/;\n\n/**\n * Matches a single upper-case or lower-case letter prefixed with a dash.\n * Example: \"-d\"\n */\nconst SHORT_NAME_REGEXP: RegExp = /^-[a-zA-Z]$/;\n\n/**\n * Matches kebab-case formatted strings\n * Example: \"my-scope\"\n */\nconst SCOPE_REGEXP: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/;\n\n/**\n * \"Environment variable names used by the utilities in the Shell and Utilities volume of\n * IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)\n * from the characters defined in Portable Character Set and do not begin with a digit.\"\n * Example: \"THE_SETTING\"\n */\nconst ENVIRONMENT_VARIABLE_NAME_REGEXP: RegExp = /^[A-Z_][A-Z0-9_]*$/;\n\nexport type CommandLineParameter =\n | CommandLineChoiceListParameter\n | CommandLineChoiceParameter\n | CommandLineFlagParameter\n | CommandLineIntegerListParameter\n | CommandLineIntegerParameter\n | CommandLineStringListParameter\n | CommandLineStringParameter;\n\n/**\n * The base class for the various command-line parameter types.\n * @public\n */\nexport abstract class CommandLineParameterBase {\n private _shortNameValue: string | undefined;\n\n /**\n * A unique internal key used to retrieve the value from the parser's dictionary.\n * @internal\n */\n public _parserKey: string | undefined;\n\n /**\n * @internal\n */\n public _preParse?: () => void;\n\n /**\n * @internal\n */\n public _postParse?: () => void;\n\n /**\n * @internal\n */\n public _validateValue?: () => void;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */\n public readonly longName: string;\n\n /**\n * If a parameterScope is provided, returns the scope-prefixed long name of the flag,\n * including double dashes, eg. \"--scope:do-something\". Otherwise undefined.\n */\n public readonly scopedLongName: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */\n public readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */\n public readonly parameterScope: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** {@inheritDoc IBaseCommandLineDefinition.required} */\n public readonly required: boolean;\n\n /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */\n public readonly environmentVariable: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames} */\n public readonly allowNonStandardEnvironmentVariableNames: boolean | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */\n public readonly undocumentedSynonyms: string[] | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinition) {\n this.longName = definition.parameterLongName;\n this._shortNameValue = definition.parameterShortName;\n this.parameterGroup = definition.parameterGroup;\n this.parameterScope = definition.parameterScope;\n this.description = definition.description;\n this.required = !!definition.required;\n this.environmentVariable = definition.environmentVariable;\n this.undocumentedSynonyms = definition.undocumentedSynonyms;\n this.allowNonStandardEnvironmentVariableNames = definition.allowNonStandardEnvironmentVariableNames;\n\n if (!LONG_NAME_REGEXP.test(this.longName)) {\n throw new Error(\n `Invalid name: \"${this.longName}\". The parameter long name must be` +\n ` lower-case and use dash delimiters (e.g. \"--do-a-thing\")`\n );\n }\n\n if (this.shortName) {\n if (!SHORT_NAME_REGEXP.test(this.shortName)) {\n throw new Error(\n `Invalid name: \"${this.shortName}\". The parameter short name must be` +\n ` a dash followed by a single upper-case or lower-case letter (e.g. \"-a\")`\n );\n }\n }\n\n if (this.parameterScope) {\n if (!SCOPE_REGEXP.test(this.parameterScope)) {\n throw new Error(\n `Invalid scope: \"${this.parameterScope}\". The parameter scope name must be` +\n ` lower-case and use dash delimiters (e.g. \"my-scope\")`\n );\n }\n // Parameter long name is guaranteed to start with '--' since this is validated above\n const unprefixedLongName: string = this.longName.slice(2);\n this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;\n }\n\n if (this.environmentVariable) {\n if (\n !this.allowNonStandardEnvironmentVariableNames &&\n !ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)\n ) {\n throw new Error(\n `Invalid environment variable name: \"${this.environmentVariable}\". The name must` +\n ` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`\n );\n }\n }\n\n if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {\n for (const undocumentedSynonym of this.undocumentedSynonyms) {\n if (this.longName === undocumentedSynonym) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". Undocumented synonyms must not be the same` +\n ` as the the long name.`\n );\n } else if (!LONG_NAME_REGEXP.test(undocumentedSynonym)) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". All undocumented synonyms name must be lower-case and ` +\n 'use dash delimiters (e.g. \"--do-a-thing\")'\n );\n }\n }\n }\n }\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */\n public get shortName(): string | undefined {\n return this._shortNameValue;\n }\n\n /**\n * Called internally by CommandLineParameterProvider._processParsedData()\n * @internal\n */\n public abstract _setValue(data: unknown): void;\n\n /**\n * Returns additional text used by the help formatter.\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n if (this.environmentVariable !== undefined) {\n supplementaryNotes.push(\n 'This parameter may alternatively be specified via the ' +\n this.environmentVariable +\n ' environment variable.'\n );\n }\n }\n\n /**\n * Indicates the type of parameter.\n */\n public abstract get kind(): CommandLineParameterKind;\n\n /**\n * Append the parsed values to the provided string array.\n * @remarks\n * Sometimes a command line parameter is not used directly, but instead gets passed through to another\n * tool that will use it. For example if our parameter comes in as \"--max-count 3\", then we might want to\n * call `child_process.spawn()` and append [\"--max-count\", \"3\"] to the args array for that tool.\n * appendToArgList() appends zero or more strings to the provided array, based on the input command-line\n * that we parsed.\n *\n * If the parameter was omitted from our command-line and has no default value, then\n * nothing will be appended. If the short name was used, the long name will be appended instead.\n * @param argList - the parsed strings will be appended to this string array\n */\n public abstract appendToArgList(argList: string[]): void;\n\n /**\n * Internal usage only. Used to report unexpected output from the argparse library.\n */\n protected reportInvalidData(data: unknown): never {\n throw new Error(`Unexpected data object for parameter \"${this.longName}\": ` + JSON.stringify(data));\n }\n\n protected validateDefaultValue(hasDefaultValue: boolean): void {\n if (this.required && hasDefaultValue) {\n // If a parameter is \"required\", then the user understands that they always need to\n // specify a value for this parameter (either via the command line or via an environment variable).\n // It would be confusing to allow a default value that sometimes allows the \"required\" parameter\n // to be omitted. If you sometimes don't have a suitable default value, then the better approach\n // is to throw a custom error explaining why the parameter is required in that case.\n throw new Error(\n `A default value cannot be specified for \"${this.longName}\" because it is a \"required\" parameter`\n );\n }\n }\n}\n\n/**\n * The common base class for parameters types that receive an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport abstract class CommandLineParameterWithArgument extends CommandLineParameterBase {\n // Matches the first character that *isn't* part of a valid upper-case argument name such as \"URL_2\"\n private static _invalidArgumentNameRegExp: RegExp = /[^A-Z_0-9]/;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */\n public readonly argumentName: string;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */\n public readonly completions: (() => Promise<string[]>) | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinitionWithArgument) {\n super(definition);\n\n if (definition.argumentName === '') {\n throw new Error(\n 'The argument name cannot be an empty string. (For the default name, specify undefined.)'\n );\n }\n if (definition.argumentName.toUpperCase() !== definition.argumentName) {\n throw new Error(\n `Invalid name: \"${definition.argumentName}\". The argument name must be all upper case.`\n );\n }\n const match: RegExpMatchArray | null = definition.argumentName.match(\n CommandLineParameterWithArgument._invalidArgumentNameRegExp\n );\n if (match) {\n throw new Error(\n `The argument name \"${definition.argumentName}\" contains an invalid character \"${match[0]}\".` +\n ` Only upper-case letters, numbers, and underscores are allowed.`\n );\n }\n this.argumentName = definition.argumentName;\n this.completions = definition.completions;\n }\n}\n"]}
@@ -1,24 +1,24 @@
1
1
  import type { ICommandLineChoiceListDefinition } from './CommandLineDefinition';
2
- import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
2
+ import { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';
3
3
  /**
4
4
  * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
5
5
  * @public
6
6
  */
7
- export declare class CommandLineChoiceListParameter<TChoice extends string = string> extends CommandLineParameter {
7
+ export declare class CommandLineChoiceListParameter<TChoice extends string = string> extends CommandLineParameterBase {
8
8
  /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */
9
9
  readonly alternatives: ReadonlyArray<TChoice>;
10
10
  private _values;
11
11
  /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */
12
12
  readonly completions: (() => Promise<TChoice[]>) | undefined;
13
+ /** {@inheritDoc CommandLineParameter.kind} */
14
+ readonly kind: CommandLineParameterKind.ChoiceList;
13
15
  /** @internal */
14
16
  constructor(definition: ICommandLineChoiceListDefinition<TChoice>);
15
- /** {@inheritDoc CommandLineParameter.kind} */
16
- get kind(): CommandLineParameterKind;
17
17
  /**
18
18
  * {@inheritDoc CommandLineParameter._setValue}
19
19
  * @internal
20
20
  */
21
- _setValue(data: any): void;
21
+ _setValue(data: unknown): void;
22
22
  /**
23
23
  * Returns the string arguments for a choice list parameter that was parsed from the command line.
24
24
  *
@@ -1 +1 @@
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,8BAA8B,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,oBAAoB;IACvG,kEAAkE;IAClE,SAAgB,YAAY,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,OAAO,CAAiB;IAEhC,iEAAiE;IACjE,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEpE,gBAAgB;gBACG,UAAU,EAAE,gCAAgC,CAAC,OAAO,CAAC;IAaxE,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAsCjC;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAE1C;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAQhD"}
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,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAGnF;;;GAGG;AACH,qBAAa,8BAA8B,CACzC,OAAO,SAAS,MAAM,GAAG,MAAM,CAC/B,SAAQ,wBAAwB;IAChC,kEAAkE;IAClE,SAAgB,YAAY,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,OAAO,CAAiB;IAEhC,iEAAiE;IACjE,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEpE,8CAA8C;IAC9C,SAAgB,IAAI,EAAE,wBAAwB,CAAC,UAAU,CAAuC;IAEhG,gBAAgB;gBACG,UAAU,EAAE,gCAAgC,CAAC,OAAO,CAAC;IAaxE;;;OAGG;IACI,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAsCrC;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAE1C;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAQhD"}
@@ -9,26 +9,23 @@ const EnvironmentVariableParser_1 = require("./EnvironmentVariableParser");
9
9
  * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
10
10
  * @public
11
11
  */
12
- class CommandLineChoiceListParameter extends BaseClasses_1.CommandLineParameter {
12
+ class CommandLineChoiceListParameter extends BaseClasses_1.CommandLineParameterBase {
13
13
  /** @internal */
14
14
  constructor(definition) {
15
15
  super(definition);
16
16
  this._values = [];
17
+ /** {@inheritDoc CommandLineParameter.kind} */
18
+ this.kind = BaseClasses_1.CommandLineParameterKind.ChoiceList;
17
19
  if (definition.alternatives.length < 1) {
18
20
  throw new Error(`When defining a choice list parameter, the alternatives list must contain at least one value.`);
19
21
  }
20
22
  this.alternatives = definition.alternatives;
21
23
  this.completions = definition.completions;
22
24
  }
23
- /** {@inheritDoc CommandLineParameter.kind} */
24
- get kind() {
25
- return BaseClasses_1.CommandLineParameterKind.ChoiceList;
26
- }
27
25
  /**
28
26
  * {@inheritDoc CommandLineParameter._setValue}
29
27
  * @internal
30
28
  */
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
29
  _setValue(data) {
33
30
  // If argparse passed us a value, confirm it is valid
34
31
  if (data !== null && data !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineChoiceListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA+E;AAC/E,2EAAwE;AAExE;;;GAGG;AACH,MAAa,8BAAgE,SAAQ,kCAAoB;IASvG,gBAAgB;IAChB,YAAmB,UAAqD;QACtE,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,YAAO,GAAc,EAAE,CAAC;QAS9B,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5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mB,CAAC;gBACnC,OAAO;YACT,CAAC;QACH,CAAC;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,CAAC;YAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA3FD,wEA2FC","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 { ICommandLineChoiceListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.\n * @public\n */\nexport class CommandLineChoiceListParameter<TChoice extends string = string> extends CommandLineParameter {\n /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */\n public readonly alternatives: ReadonlyArray<TChoice>;\n\n private _values: TChoice[] = [];\n\n /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */\n public readonly completions: (() => Promise<TChoice[]>) | undefined;\n\n /** @internal */\n public constructor(definition: ICommandLineChoiceListDefinition<TChoice>) {\n super(definition);\n\n if (definition.alternatives.length < 1) {\n throw new Error(\n `When defining a choice list parameter, the alternatives list must contain at least one value.`\n );\n }\n\n this.alternatives = definition.alternatives;\n this.completions = definition.completions;\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.ChoiceList;\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 (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n for (const value of values) {\n if (!this.alternatives.includes(value as TChoice)) {\n const choices: string = '\"' + this.alternatives.join('\", \"') + '\"';\n throw new Error(\n `Invalid value \"${value}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\n );\n }\n }\n\n this._values = values as TChoice[];\n return;\n }\n }\n\n // (No default value for choice lists)\n\n this._values = [];\n }\n\n /**\n * Returns the string arguments for a choice 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<TChoice> {\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"]}
1
+ {"version":3,"file":"CommandLineChoiceListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAAmF;AACnF,2EAAwE;AAExE;;;GAGG;AACH,MAAa,8BAEX,SAAQ,sCAAwB;IAYhC,gBAAgB;IAChB,YAAmB,UAAqD;QACtE,KAAK,CAAC,UAAU,CAAC,CAAC;QAVZ,YAAO,GAAc,EAAE,CAAC;QAKhC,8CAA8C;QAC9B,SAAI,G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ACrD,IAAI,IAAI,CAAC,mBAAmB,yBAAyB,OAAO,EAAE,CACjE,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAED,IAAI,CAAC,OAAO,GAAG,MAAmB,CAAC;gBACnC,OAAO;YACT,CAAC;QACH,CAAC;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,CAAC;YAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA1FD,wEA0FC","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 { ICommandLineChoiceListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.\n * @public\n */\nexport class CommandLineChoiceListParameter<\n TChoice extends string = string\n> extends CommandLineParameterBase {\n /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */\n public readonly alternatives: ReadonlyArray<TChoice>;\n\n private _values: TChoice[] = [];\n\n /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */\n public readonly completions: (() => Promise<TChoice[]>) | undefined;\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public readonly kind: CommandLineParameterKind.ChoiceList = CommandLineParameterKind.ChoiceList;\n\n /** @internal */\n public constructor(definition: ICommandLineChoiceListDefinition<TChoice>) {\n super(definition);\n\n if (definition.alternatives.length < 1) {\n throw new Error(\n `When defining a choice list parameter, the alternatives list must contain at least one value.`\n );\n }\n\n this.alternatives = definition.alternatives;\n this.completions = definition.completions;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._setValue}\n * @internal\n */\n public _setValue(data: unknown): 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 (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n for (const value of values) {\n if (!this.alternatives.includes(value as TChoice)) {\n const choices: string = '\"' + this.alternatives.join('\", \"') + '\"';\n throw new Error(\n `Invalid value \"${value}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\n );\n }\n }\n\n this._values = values as TChoice[];\n return;\n }\n }\n\n // (No default value for choice lists)\n\n this._values = [];\n }\n\n /**\n * Returns the string arguments for a choice 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<TChoice> {\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"]}