@rushstack/ts-command-line 4.17.4 → 4.18.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 (33) hide show
  1. package/dist/ts-command-line.d.ts +109 -29
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/lib/index.d.ts +3 -3
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js.map +1 -1
  6. package/lib/parameters/BaseClasses.d.ts +2 -0
  7. package/lib/parameters/BaseClasses.d.ts.map +1 -1
  8. package/lib/parameters/BaseClasses.js +2 -1
  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 +1 -1
  13. package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -1
  14. package/lib/parameters/CommandLineChoiceParameter.d.ts +14 -7
  15. package/lib/parameters/CommandLineChoiceParameter.d.ts.map +1 -1
  16. package/lib/parameters/CommandLineChoiceParameter.js +2 -2
  17. package/lib/parameters/CommandLineChoiceParameter.js.map +1 -1
  18. package/lib/parameters/CommandLineDefinition.d.ts +32 -14
  19. package/lib/parameters/CommandLineDefinition.d.ts.map +1 -1
  20. package/lib/parameters/CommandLineDefinition.js.map +1 -1
  21. package/lib/parameters/CommandLineIntegerParameter.d.ts +8 -1
  22. package/lib/parameters/CommandLineIntegerParameter.d.ts.map +1 -1
  23. package/lib/parameters/CommandLineIntegerParameter.js +1 -1
  24. package/lib/parameters/CommandLineIntegerParameter.js.map +1 -1
  25. package/lib/parameters/CommandLineStringParameter.d.ts +8 -1
  26. package/lib/parameters/CommandLineStringParameter.d.ts.map +1 -1
  27. package/lib/parameters/CommandLineStringParameter.js +1 -1
  28. package/lib/parameters/CommandLineStringParameter.js.map +1 -1
  29. package/lib/providers/CommandLineParameterProvider.d.ts +42 -6
  30. package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -1
  31. package/lib/providers/CommandLineParameterProvider.js +0 -28
  32. package/lib/providers/CommandLineParameterProvider.js.map +1 -1
  33. package/package.json +3 -3
@@ -71,12 +71,12 @@ export declare abstract class CommandLineAction extends CommandLineParameterProv
71
71
  * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
72
72
  * @public
73
73
  */
74
- export declare class CommandLineChoiceListParameter extends CommandLineParameter {
74
+ export declare class CommandLineChoiceListParameter<TChoice extends string = string> extends CommandLineParameter {
75
75
  /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */
76
- readonly alternatives: ReadonlyArray<string>;
76
+ readonly alternatives: ReadonlyArray<TChoice>;
77
77
  private _values;
78
78
  /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */
79
- readonly completions: (() => Promise<string[]>) | undefined;
79
+ readonly completions: (() => Promise<TChoice[]>) | undefined;
80
80
  /* Excluded from this release type: __constructor */
81
81
  /** {@inheritDoc CommandLineParameter.kind} */
82
82
  get kind(): CommandLineParameterKind;
@@ -88,23 +88,23 @@ export declare class CommandLineChoiceListParameter extends CommandLineParameter
88
88
  * The array will be empty if the command-line has not been parsed yet,
89
89
  * or if the parameter was omitted and has no default value.
90
90
  */
91
- get values(): ReadonlyArray<string>;
91
+ get values(): ReadonlyArray<TChoice>;
92
92
  /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
93
93
  appendToArgList(argList: string[]): void;
94
94
  }
95
95
 
96
96
  /**
97
- * The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
97
+ * The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:1)}.
98
98
  * @public
99
99
  */
100
- export declare class CommandLineChoiceParameter extends CommandLineParameter {
100
+ export declare class CommandLineChoiceParameter<TChoice extends string = string> extends CommandLineParameter {
101
101
  /** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */
102
- readonly alternatives: ReadonlyArray<string>;
102
+ readonly alternatives: ReadonlyArray<TChoice>;
103
103
  /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
104
- readonly defaultValue: string | undefined;
104
+ readonly defaultValue: TChoice | undefined;
105
105
  private _value;
106
106
  /** {@inheritDoc ICommandLineChoiceDefinition.completions} */
107
- readonly completions: (() => Promise<string[]>) | undefined;
107
+ readonly completions: (() => Promise<TChoice[]>) | undefined;
108
108
  /* Excluded from this release type: __constructor */
109
109
  /** {@inheritDoc CommandLineParameter.kind} */
110
110
  get kind(): CommandLineParameterKind;
@@ -117,7 +117,7 @@ export declare class CommandLineChoiceParameter extends CommandLineParameter {
117
117
  * The return value will be `undefined` if the command-line has not been parsed yet,
118
118
  * or if the parameter was omitted and has no default value.
119
119
  */
120
- get value(): string | undefined;
120
+ get value(): TChoice | undefined;
121
121
  /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
122
122
  appendToArgList(argList: string[]): void;
123
123
  }
@@ -193,7 +193,7 @@ export declare class CommandLineIntegerListParameter extends CommandLineParamete
193
193
  }
194
194
 
195
195
  /**
196
- * The data type returned by {@link CommandLineParameterProvider.defineIntegerParameter}.
196
+ * The data type returned by {@link CommandLineParameterProvider.(defineIntegerParameter:1)}.
197
197
  * @public
198
198
  */
199
199
  export declare class CommandLineIntegerParameter extends CommandLineParameterWithArgument {
@@ -241,6 +241,8 @@ export declare abstract class CommandLineParameter {
241
241
  readonly required: boolean;
242
242
  /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */
243
243
  readonly environmentVariable: string | undefined;
244
+ /** {@inheritDoc IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames} */
245
+ readonly allowNonStandardEnvironmentVariableNames: boolean | undefined;
244
246
  /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */
245
247
  readonly undocumentedSynonyms: string[] | undefined;
246
248
  /* Excluded from this release type: __constructor */
@@ -335,7 +337,19 @@ export declare abstract class CommandLineParameterProvider {
335
337
  * example-tool --log-level warn
336
338
  * ```
337
339
  */
338
- defineChoiceParameter(definition: ICommandLineChoiceDefinition): CommandLineChoiceParameter;
340
+ defineChoiceParameter<TChoice extends string = string>(definition: ICommandLineChoiceDefinition<TChoice> & {
341
+ required: false | undefined;
342
+ }): CommandLineChoiceParameter<TChoice>;
343
+ /**
344
+ * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}
345
+ */
346
+ defineChoiceParameter<TChoice extends string = string>(definition: ICommandLineChoiceDefinition<TChoice> & {
347
+ required: true;
348
+ }): IRequiredCommandLineChoiceParameter<TChoice>;
349
+ /**
350
+ * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}
351
+ */
352
+ defineChoiceParameter<TChoice extends string = string>(definition: ICommandLineChoiceDefinition<TChoice>): CommandLineChoiceParameter<TChoice>;
339
353
  /**
340
354
  * Returns the CommandLineChoiceParameter with the specified long name.
341
355
  * @remarks
@@ -353,7 +367,7 @@ export declare abstract class CommandLineParameterProvider {
353
367
  * example-tool --allow-color red --allow-color green
354
368
  * ```
355
369
  */
356
- defineChoiceListParameter(definition: ICommandLineChoiceListDefinition): CommandLineChoiceListParameter;
370
+ defineChoiceListParameter<TChoice extends string = string>(definition: ICommandLineChoiceListDefinition<TChoice>): CommandLineChoiceListParameter<TChoice>;
357
371
  /**
358
372
  * Returns the CommandLineChoiceListParameter with the specified long name.
359
373
  * @remarks
@@ -386,6 +400,18 @@ export declare abstract class CommandLineParameterProvider {
386
400
  * example-tool --max-attempts 5
387
401
  * ```
388
402
  */
403
+ defineIntegerParameter(definition: ICommandLineIntegerDefinition & {
404
+ required: false | undefined;
405
+ }): CommandLineIntegerParameter;
406
+ /**
407
+ * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}
408
+ */
409
+ defineIntegerParameter(definition: ICommandLineIntegerDefinition & {
410
+ required: true;
411
+ }): IRequiredCommandLineIntegerParameter;
412
+ /**
413
+ * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}
414
+ */
389
415
  defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter;
390
416
  /**
391
417
  * Returns the CommandLineIntegerParameter with the specified long name.
@@ -419,6 +445,18 @@ export declare abstract class CommandLineParameterProvider {
419
445
  * example-tool --message "Hello, world!"
420
446
  * ```
421
447
  */
448
+ defineStringParameter(definition: ICommandLineStringDefinition & {
449
+ required: false | undefined;
450
+ }): CommandLineStringParameter;
451
+ /**
452
+ * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}
453
+ */
454
+ defineStringParameter(definition: ICommandLineStringDefinition & {
455
+ required: true;
456
+ }): IRequiredCommandLineStringParameter;
457
+ /**
458
+ * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}
459
+ */
422
460
  defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter;
423
461
  /**
424
462
  * Returns the CommandLineStringParameter with the specified long name.
@@ -632,7 +670,7 @@ export declare class CommandLineStringListParameter extends CommandLineParameter
632
670
  }
633
671
 
634
672
  /**
635
- * The data type returned by {@link CommandLineParameterProvider.defineStringParameter}.
673
+ * The data type returned by {@link CommandLineParameterProvider.(defineStringParameter:1)}.
636
674
  * @public
637
675
  */
638
676
  export declare class CommandLineStringParameter extends CommandLineParameterWithArgument {
@@ -733,7 +771,9 @@ export declare interface IBaseCommandLineDefinition {
733
771
  *
734
772
  * @remarks
735
773
  * The environment variable name must consist only of upper-case letters, numbers,
736
- * and underscores. It may not start with a number.
774
+ * and underscores. It may not start with a number. To disable this validation, set
775
+ * `{@link IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames}`
776
+ * to `true`.
737
777
  *
738
778
  * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,
739
779
  * because in that case the environmentVariable would never be used.
@@ -761,6 +801,19 @@ export declare interface IBaseCommandLineDefinition {
761
801
  * ordinary String Parameter: Any value is accepted, including an empty string.
762
802
  */
763
803
  environmentVariable?: string;
804
+ /**
805
+ * Allows for the use of environment variable names that do not conform to the standard
806
+ * described by the Shell and Utilities volume of IEEE Std 1003.1-2001. This disables
807
+ * the validation that is performed on the provided
808
+ * {@link IBaseCommandLineDefinition.environmentVariable} value by default.
809
+ *
810
+ * @remarks
811
+ * if this is set to `true`, environment variable discovery will vary based on the
812
+ * platform in use. For example, Windows environment variable names are case-insensitive,
813
+ * while on Linux, environment variable names are case-sensitive. It is recommended that
814
+ * this option be used only when necessary based on environmental constraints.
815
+ */
816
+ allowNonStandardEnvironmentVariableNames?: boolean;
764
817
  /**
765
818
  * Specifies additional names for this parameter that are accepted but not displayed
766
819
  * in the command line help.
@@ -823,28 +876,29 @@ export declare interface ICommandLineActionOptions {
823
876
  }
824
877
 
825
878
  /**
826
- * For use with {@link CommandLineParameterProvider.defineChoiceParameter},
827
- * this interface defines a command line parameter which is constrained to a list of possible
879
+ * For use with {@link CommandLineParameterProvider.(defineChoiceParameter:1)} and
880
+ * {@link CommandLineParameterProvider.(defineChoiceParameter:2)}, this interface
881
+ * defines a command line parameter which is constrained to a list of possible
828
882
  * options.
829
883
  *
830
884
  * @public
831
885
  */
832
- export declare interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {
886
+ export declare interface ICommandLineChoiceDefinition<TChoice extends string = string> extends IBaseCommandLineDefinition {
833
887
  /**
834
888
  * A list of strings (which contain no spaces), of possible options which can be selected
835
889
  */
836
- alternatives: string[];
890
+ alternatives: TChoice[];
837
891
  /**
838
892
  * {@inheritDoc ICommandLineStringDefinition.defaultValue}
839
893
  */
840
- defaultValue?: string;
894
+ defaultValue?: TChoice;
841
895
  /**
842
896
  * An optional callback that provides a list of custom choices for tab completion.
843
897
  * @remarks
844
898
  * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
845
899
  * is enabled.
846
900
  */
847
- completions?: () => Promise<string[]>;
901
+ completions?: () => Promise<TChoice[]>;
848
902
  }
849
903
 
850
904
  /**
@@ -854,18 +908,18 @@ export declare interface ICommandLineChoiceDefinition extends IBaseCommandLineDe
854
908
  *
855
909
  * @public
856
910
  */
857
- export declare interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {
911
+ export declare interface ICommandLineChoiceListDefinition<TChoice extends string = string> extends IBaseCommandLineDefinition {
858
912
  /**
859
913
  * A list of strings (which contain no spaces), of possible options which can be selected
860
914
  */
861
- alternatives: string[];
915
+ alternatives: TChoice[];
862
916
  /**
863
917
  * An optional callback that provides a list of custom choices for tab completion.
864
918
  * @remarks
865
919
  * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
866
920
  * is enabled.
867
921
  */
868
- completions?: () => Promise<string[]>;
922
+ completions?: () => Promise<TChoice[]>;
869
923
  }
870
924
 
871
925
  /**
@@ -878,8 +932,9 @@ export declare interface ICommandLineFlagDefinition extends IBaseCommandLineDefi
878
932
  }
879
933
 
880
934
  /**
881
- * For use with {@link CommandLineParameterProvider.defineIntegerParameter},
882
- * this interface defines a command line parameter whose argument is an integer value.
935
+ * For use with {@link CommandLineParameterProvider.(defineIntegerParameter:1)},
936
+ * {@link CommandLineParameterProvider.(defineIntegerParameter:2)}, this interface
937
+ * defines a command line parameter whose argument is an integer value.
883
938
  *
884
939
  * @public
885
940
  */
@@ -941,8 +996,9 @@ export declare interface ICommandLineRemainderDefinition {
941
996
  }
942
997
 
943
998
  /**
944
- * For use with {@link CommandLineParameterProvider.defineStringParameter},
945
- * this interface defines a command line parameter whose argument is a string value.
999
+ * For use with {@link CommandLineParameterProvider.(defineStringParameter:1)} and
1000
+ * {@link CommandLineParameterProvider.(defineStringParameter:2)}, this interface
1001
+ * defines a command line parameter whose argument is a string value.
946
1002
  *
947
1003
  * @public
948
1004
  */
@@ -971,7 +1027,31 @@ export declare interface ICommandLineStringListDefinition extends IBaseCommandLi
971
1027
  /* Excluded from this release type: _IRegisterDefinedParametersState */
972
1028
 
973
1029
  /**
974
- * The result containing the parsed paramter long name and scope. Returned when calling
1030
+ * The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:2)}.
1031
+ * @public
1032
+ */
1033
+ export declare interface IRequiredCommandLineChoiceParameter<TChoice extends string = string> extends CommandLineChoiceParameter<TChoice> {
1034
+ value: TChoice;
1035
+ }
1036
+
1037
+ /**
1038
+ * The data type returned by {@link CommandLineParameterProvider.(defineIntegerParameter:2)}.
1039
+ * @public
1040
+ */
1041
+ export declare interface IRequiredCommandLineIntegerParameter extends CommandLineIntegerParameter {
1042
+ value: number;
1043
+ }
1044
+
1045
+ /**
1046
+ * The data type returned by {@link CommandLineParameterProvider.(defineStringParameter:2)}.
1047
+ * @public
1048
+ */
1049
+ export declare interface IRequiredCommandLineStringParameter extends CommandLineStringParameter {
1050
+ value: string;
1051
+ }
1052
+
1053
+ /**
1054
+ * The result containing the parsed parameter long name and scope. Returned when calling
975
1055
  * {@link CommandLineParameterProvider.parseScopedLongName}.
976
1056
  *
977
1057
  * @public
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.40.6"
8
+ "packageVersion": "7.41.0"
9
9
  }
10
10
  ]
11
11
  }
package/lib/index.d.ts CHANGED
@@ -10,11 +10,11 @@ export { AliasCommandLineAction, type IAliasCommandLineActionOptions } from './p
10
10
  export type { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument, ICommandLineFlagDefinition, ICommandLineStringDefinition, ICommandLineStringListDefinition, ICommandLineIntegerDefinition, ICommandLineIntegerListDefinition, ICommandLineChoiceDefinition, ICommandLineChoiceListDefinition, ICommandLineRemainderDefinition } from './parameters/CommandLineDefinition';
11
11
  export { CommandLineParameterKind, CommandLineParameter, CommandLineParameterWithArgument } from './parameters/BaseClasses';
12
12
  export { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';
13
- export { CommandLineStringParameter } from './parameters/CommandLineStringParameter';
13
+ export { CommandLineStringParameter, type IRequiredCommandLineStringParameter } from './parameters/CommandLineStringParameter';
14
14
  export { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';
15
- export { CommandLineIntegerParameter } from './parameters/CommandLineIntegerParameter';
15
+ export { CommandLineIntegerParameter, type IRequiredCommandLineIntegerParameter } from './parameters/CommandLineIntegerParameter';
16
16
  export { CommandLineIntegerListParameter } from './parameters/CommandLineIntegerListParameter';
17
- export { CommandLineChoiceParameter } from './parameters/CommandLineChoiceParameter';
17
+ export { CommandLineChoiceParameter, type IRequiredCommandLineChoiceParameter } from './parameters/CommandLineChoiceParameter';
18
18
  export { CommandLineChoiceListParameter } from './parameters/CommandLineChoiceListParameter';
19
19
  export { CommandLineRemainder } from './parameters/CommandLineRemainder';
20
20
  export { CommandLineParameterProvider, type IScopedLongNameParseResult, type ICommandLineParserData as _ICommandLineParserData, type IRegisterDefinedParametersState as _IRegisterDefinedParametersState } from './providers/CommandLineParameterProvider';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,KAAK,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EACL,sBAAsB,EACtB,KAAK,8BAA8B,EACpC,MAAM,oCAAoC,CAAC;AAE5C,YAAY,EACV,0BAA0B,EAC1B,sCAAsC,EACtC,0BAA0B,EAC1B,4BAA4B,EAC5B,gCAAgC,EAChC,6BAA6B,EAC7B,iCAAiC,EACjC,4BAA4B,EAC5B,gCAAgC,EAChC,+BAA+B,EAChC,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,gCAAgC,EACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,2BAA2B,EA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AA,oBAAoB,OAAA;AACpB,+HAAA,gCAAgC,OAAA;AAGlC,kFAAiF;AAAxE,oIAAA,wBAAwB,OAAA;AACjC,sFAAqF;AAA5E,wIAAA,0BAA0B,OAAA;AACnC,8FAA6F;AAApF,gJAAA,8BAA8B,OAAA;AACvC,wFAAuF;AAA9E,0IAAA,2BAA2B,OAAA;AACpC,gGAA+F;AAAtF,kJAAA,+BAA+B,OAAA;AACxC,sFAAqF;AAA5E,wIAAA,0BAA0B,OAAA;AACnC,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 { CommandLineStringParameter } from './parameters/CommandLineStringParameter';\nexport { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';\nexport { CommandLineIntegerParameter } from './parameters/CommandLineIntegerParameter';\nexport { CommandLineIntegerListParameter } from './parameters/CommandLineIntegerListParameter';\nexport { CommandLineChoiceParameter } 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,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"]}
@@ -48,6 +48,8 @@ export declare abstract class CommandLineParameter {
48
48
  readonly required: boolean;
49
49
  /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */
50
50
  readonly environmentVariable: string | undefined;
51
+ /** {@inheritDoc IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames} */
52
+ readonly allowNonStandardEnvironmentVariableNames: boolean | undefined;
51
53
  /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */
52
54
  readonly undocumentedSynonyms: string[] | undefined;
53
55
  /** @internal */
@@ -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,W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AE,OAAO,CAAC;IAElC,mEAAmE;IACnE,SAAgB,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IAExD,wFAAwF;IACxF,SAAgB,wCAAwC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE9E,qEAAqE;IACrE,SAAgB,oBAAoB,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAE3D,gBAAgB;gBACG,UAAU,EAAE,0BAA0B;IA4EzD,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"}
@@ -87,7 +87,8 @@ class CommandLineParameter {
87
87
  throw new Error(`An "environmentVariable" cannot be specified for "${this.longName}"` +
88
88
  ` because it is a required parameter`);
89
89
  }
90
- if (!ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)) {
90
+ if (!this.allowNonStandardEnvironmentVariableNames &&
91
+ !ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)) {
91
92
  throw new Error(`Invalid environment variable name: "${this.environmentVariable}". The name must` +
92
93
  ` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`);
93
94
  }
@@ -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,MAAM,gCAAgC,GAAW,oBAAoB,CAAC;AAEtE;;;GAGG;AACH,MAAsB,oBAAoB;IAoCxC,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,iBAAiB,CAAC;QAC7C,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,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AAoB,CAAC,eAAwB;QACrD,IAAI,IAAI,CAAC,QAAQ,IAAI,eAAe,EAAE,CAAC;YACrC,mFAAmF;YACnF,mGAAmG;YACnG,gGAAgG;YAChG,iGAAiG;YACjG,oFAAoF;YACpF,MAAM,IAAI,KAAK,CACb,4CAA4C,IAAI,CAAC,QAAQ,wCAAwC,CAClG,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAhLD,oDAgLC;AAED;;;;;;;GAOG;AACH,MAAsB,gCAAiC,SAAQ,oBAAoB;IAUjF,gBAAgB;IAChB,YAAmB,UAAkD;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;QACJ,CAAC;QACD,IAAI,UAAU,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,YAAY,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,CAAC,YAAY,8CAA8C,CACxF,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,GAA4B,UAAU,CAAC,YAAY,CAAC,KAAK,CAClE,gCAAgC,CAAC,0BAA0B,CAC5D,CAAC;QACF,IAAI,KAAK,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.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 (!ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)) {\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;;;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,MAAM,gCAAgC,GAAW,oBAAoB,CAAC;AAEtE;;;GAGG;AACH,MAAsB,oBAAoB;IAuCxC,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,iBAAiB,CAAC;QAC7C,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;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;QACrD,IAAI,IAAI,CAAC,QAAQ,IAAI,eAAe,EAAE,CAAC;YACrC,mFAAmF;YACnF,mGAAmG;YACnG,gGAAgG;YAChG,iGAAiG;YACjG,oFAAoF;YACpF,MAAM,IAAI,KAAK,CACb,4CAA4C,IAAI,CAAC,QAAQ,wCAAwC,CAClG,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAtLD,oDAsLC;AAED;;;;;;;GAOG;AACH,MAAsB,gCAAiC,SAAQ,oBAAoB;IAUjF,gBAAgB;IAChB,YAAmB,UAAkD;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;QACJ,CAAC;QACD,IAAI,UAAU,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,YAAY,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,CAAC,YAAY,8CAA8C,CACxF,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,GAA4B,UAAU,CAAC,YAAY,CAAC,KAAK,CAClE,gCAAgC,CAAC,0BAA0B,CAC5D,CAAC;QACF,IAAI,KAAK,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"]}
@@ -4,14 +4,14 @@ import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
4
4
  * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
5
5
  * @public
6
6
  */
7
- export declare class CommandLineChoiceListParameter extends CommandLineParameter {
7
+ export declare class CommandLineChoiceListParameter<TChoice extends string = string> extends CommandLineParameter {
8
8
  /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */
9
- readonly alternatives: ReadonlyArray<string>;
9
+ readonly alternatives: ReadonlyArray<TChoice>;
10
10
  private _values;
11
11
  /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */
12
- readonly completions: (() => Promise<string[]>) | undefined;
12
+ readonly completions: (() => Promise<TChoice[]>) | undefined;
13
13
  /** @internal */
14
- constructor(definition: ICommandLineChoiceListDefinition);
14
+ constructor(definition: ICommandLineChoiceListDefinition<TChoice>);
15
15
  /** {@inheritDoc CommandLineParameter.kind} */
16
16
  get kind(): CommandLineParameterKind;
17
17
  /**
@@ -26,7 +26,7 @@ export declare class CommandLineChoiceListParameter extends CommandLineParameter
26
26
  * The array will be empty if the command-line has not been parsed yet,
27
27
  * or if the parameter was omitted and has no default value.
28
28
  */
29
- get values(): ReadonlyArray<string>;
29
+ get values(): ReadonlyArray<TChoice>;
30
30
  /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
31
31
  appendToArgList(argList: string[]): void;
32
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineChoiceListParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceListParameter.ts"],"names":[],"mappings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,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"}
@@ -47,7 +47,7 @@ class CommandLineChoiceListParameter extends BaseClasses_1.CommandLineParameter
47
47
  const values = EnvironmentVariableParser_1.EnvironmentVariableParser.parseAsList(this.environmentVariable);
48
48
  if (values) {
49
49
  for (const value of values) {
50
- if (this.alternatives.indexOf(value) < 0) {
50
+ if (!this.alternatives.includes(value)) {
51
51
  const choices = '"' + this.alternatives.join('", "') + '"';
52
52
  throw new Error(`Invalid value "${value}" for the environment variable` +
53
53
  ` ${this.environmentVariable}. Valid choices are: ${choices}`);
@@ -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,8BAA+B,SAAQ,kCAAoB;IAStE,gBAAgB;IAChB,YAAmB,UAA4C;QAC7D,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,YAAO,GAAa,EAAE,CAAC;QAS7B,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;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED,8CAA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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 { 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 extends CommandLineParameter {\n /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */\n public readonly alternatives: ReadonlyArray<string>;\n\n private _values: string[] = [];\n\n /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */\n public readonly completions: (() => Promise<string[]>) | undefined;\n\n /** @internal */\n public constructor(definition: ICommandLineChoiceListDefinition) {\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.indexOf(value) < 0) {\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 this._values = values;\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<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"]}
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,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,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;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,19 +1,26 @@
1
1
  import type { ICommandLineChoiceDefinition } from './CommandLineDefinition';
2
2
  import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
3
3
  /**
4
- * The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
4
+ * The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:2)}.
5
5
  * @public
6
6
  */
7
- export declare class CommandLineChoiceParameter extends CommandLineParameter {
7
+ export interface IRequiredCommandLineChoiceParameter<TChoice extends string = string> extends CommandLineChoiceParameter<TChoice> {
8
+ value: TChoice;
9
+ }
10
+ /**
11
+ * The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:1)}.
12
+ * @public
13
+ */
14
+ export declare class CommandLineChoiceParameter<TChoice extends string = string> extends CommandLineParameter {
8
15
  /** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */
9
- readonly alternatives: ReadonlyArray<string>;
16
+ readonly alternatives: ReadonlyArray<TChoice>;
10
17
  /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
11
- readonly defaultValue: string | undefined;
18
+ readonly defaultValue: TChoice | undefined;
12
19
  private _value;
13
20
  /** {@inheritDoc ICommandLineChoiceDefinition.completions} */
14
- readonly completions: (() => Promise<string[]>) | undefined;
21
+ readonly completions: (() => Promise<TChoice[]>) | undefined;
15
22
  /** @internal */
16
- constructor(definition: ICommandLineChoiceDefinition);
23
+ constructor(definition: ICommandLineChoiceDefinition<TChoice>);
17
24
  /** {@inheritDoc CommandLineParameter.kind} */
18
25
  get kind(): CommandLineParameterKind;
19
26
  /**
@@ -33,7 +40,7 @@ export declare class CommandLineChoiceParameter extends CommandLineParameter {
33
40
  * The return value will be `undefined` if the command-line has not been parsed yet,
34
41
  * or if the parameter was omitted and has no default value.
35
42
  */
36
- get value(): string | undefined;
43
+ get value(): TChoice | undefined;
37
44
  /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
38
45
  appendToArgList(argList: string[]): void;
39
46
  }
@@ -1 +1 @@
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,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,OAAO,CAAC,MAAM,CAAkC;IAEhD,6DAA6D;IAC7D,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEpE,gBAAgB;gBACG,UAAU,EAAE,4BAA4B,CAAC,OAAO,CAAC;IAqBpE,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAmCjC;;;OAGG;IACI,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,IAAI;IAQjE;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,OAAO,GAAG,SAAS,CAEtC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAMhD"}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.CommandLineChoiceParameter = void 0;
6
6
  const BaseClasses_1 = require("./BaseClasses");
7
7
  /**
8
- * The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
8
+ * The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:1)}.
9
9
  * @public
10
10
  */
11
11
  class CommandLineChoiceParameter extends BaseClasses_1.CommandLineParameter {
@@ -47,7 +47,7 @@ class CommandLineChoiceParameter extends BaseClasses_1.CommandLineParameter {
47
47
  // Try reading the environment variable
48
48
  const environmentValue = process.env[this.environmentVariable];
49
49
  if (environmentValue !== undefined && environmentValue !== '') {
50
- if (this.alternatives.indexOf(environmentValue) < 0) {
50
+ if (!this.alternatives.includes(environmentValue)) {
51
51
  const choices = '"' + this.alternatives.join('", "') + '"';
52
52
  throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
53
53
  ` ${this.environmentVariable}. Valid choices are: ${choices}`);