command-line-director 2.0.0-beta.1 → 2.0.0-beta.2

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.
package/dist/index.d.ts CHANGED
@@ -15,40 +15,40 @@ declare enum CommandLineArgumentType {
15
15
  Value = 1
16
16
  }
17
17
 
18
- declare class CommandLineArgument {
18
+ declare class CommandLineArgument<T extends string | number | boolean> {
19
19
  propertyName: string;
20
20
  required: boolean;
21
21
  argumentName: string | null;
22
22
  alias: string | null;
23
23
  dataType: CommandLineArgumentDataType;
24
24
  type: CommandLineArgumentType;
25
- defaultValue: string | number | boolean | null;
26
- allowedValues: string[] | number[] | boolean[] | null;
25
+ defaultValue: T | null;
26
+ allowedValues: T[] | null;
27
27
  regularExpression: RegExp | null;
28
28
  description: string | null;
29
- constructor(propertyName: string, required: boolean, argumentName: string | null, alias: string | null, dataType: CommandLineArgumentDataType | null, type: CommandLineArgumentType, defaultValue?: string | number | boolean | null, allowedValues?: string[] | number[] | boolean[] | null, regularExpression?: RegExp | null, description?: string | null);
29
+ constructor(propertyName: string, required: boolean, argumentName: string | null, alias: string | null, dataType: CommandLineArgumentDataType | null, type: CommandLineArgumentType, defaultValue: T | null, allowedValues: T[] | null, regularExpression?: RegExp | null, description?: string | null);
30
30
  toString(): string;
31
31
  }
32
32
 
33
33
  declare class Command {
34
34
  identifier: string;
35
- commandLineArguments: Array<CommandLineArgument>;
35
+ commandLineArguments: Array<CommandLineArgument<string | number | boolean>>;
36
36
  values: Map<string, string | number | boolean | null>;
37
- constructor(identifier: string, commandLineArguments: Array<CommandLineArgument>, values: Map<string, string | number | boolean | null>);
37
+ constructor(identifier: string, commandLineArguments: Array<CommandLineArgument<string | number | boolean>>, values: Map<string, string | number | boolean | null>);
38
38
  }
39
39
 
40
40
  declare class CommandLine {
41
41
  identifier: string;
42
42
  title: string;
43
43
  description: string;
44
- commandLineArguments: CommandLineArgument[];
44
+ commandLineArguments: CommandLineArgument<string | number | boolean>[];
45
45
  /**
46
46
  * CommandLine constructor
47
47
  * @param identifier - string
48
48
  * @param commandLineArguments - array
49
49
  * @thows Error
50
50
  */
51
- constructor(identifier: string, title: string, description: string, commandLineArguments: CommandLineArgument[]);
51
+ constructor(identifier: string, title: string, description: string, commandLineArguments: CommandLineArgument<string | number | boolean>[]);
52
52
  /**
53
53
  * Create lookup table for process arguments
54
54
  * @result object
@@ -75,11 +75,12 @@ declare class CommandLineArgumentFactory {
75
75
  * @param required - boolean
76
76
  * @param argumentName - string
77
77
  * @param alias - string
78
- * @param defaultValue - any
78
+ * @param defaultValue - string
79
79
  * @param allowedValues
80
80
  * @param regularExpression
81
81
  */
82
- keyValueArgument(propertyName: string, description: string, required: boolean, argumentName: string, alias: string, defaultValue?: string | number | boolean | null, allowedValues?: string[] | number[] | boolean[] | null, regularExpression?: RegExp | null): CommandLineArgument;
82
+ keyStringValueArgument(propertyName: string, description: string, required: boolean, argumentName: string, alias: string, defaultValue?: string | null, allowedValues?: string[] | null, regularExpression?: RegExp | null): CommandLineArgument<string>;
83
+ keyNumberValueArgument(propertyName: string, description: string, required: boolean, argumentName: string, alias: string, defaultValue?: number | null, allowedValues?: number[] | null, regularExpression?: RegExp | null): CommandLineArgument<number>;
83
84
  /**
84
85
  * Create boolean argument
85
86
  * Examples:
@@ -91,7 +92,7 @@ declare class CommandLineArgumentFactory {
91
92
  * @param argumentName - string
92
93
  * @param alias - string
93
94
  */
94
- flagArgument(propertyName: string, description: string, argumentName: string, alias: string): CommandLineArgument;
95
+ flagArgument(propertyName: string, description: string, argumentName: string, alias: string): CommandLineArgument<boolean>;
95
96
  /**
96
97
  * Create command
97
98
  * Examples:
@@ -103,7 +104,8 @@ declare class CommandLineArgumentFactory {
103
104
  * @param allowedValues
104
105
  * @param regularExpression
105
106
  */
106
- valueArgument(propertyName: string, description: string, required: boolean, allowedValues?: string[] | number[] | boolean[] | null, regularExpression?: RegExp | null): CommandLineArgument;
107
+ stringValueArgument(propertyName: string, description: string, required: boolean, allowedValues?: string[] | null, regularExpression?: RegExp | null): CommandLineArgument<string>;
108
+ numberValueArgument(propertyName: string, description: string, required: boolean, allowedValues?: number[] | null, regularExpression?: RegExp | null): CommandLineArgument<number>;
107
109
  }
108
110
 
109
111
  declare class CommandLineDirector {
package/dist/index.js CHANGED
@@ -147,12 +147,11 @@ var CommandLine = class {
147
147
  }
148
148
  });
149
149
  this.commandLineArguments.forEach(function(arg) {
150
- var _a;
151
150
  if (arg.required === true && (result.get(arg.propertyName) === void 0 || result.get(arg.propertyName) === null)) {
152
151
  throw new Error(`Required field '${arg.propertyName}' is missing.`);
153
152
  }
154
153
  if (arg.allowedValues && arg.allowedValues.length > 0 && (arg.required === true || result.has(arg.propertyName) && result.get(arg.propertyName) !== null)) {
155
- if (((_a = arg.allowedValues) == null ? void 0 : _a.indexOf(result.get(arg.propertyName))) === -1) {
154
+ if (arg.allowedValues.indexOf(result.get(arg.propertyName)) === -1) {
156
155
  throw new Error(`Value for field '${arg.propertyName}' is not allowed.`);
157
156
  }
158
157
  }
@@ -169,13 +168,7 @@ var CommandLine = class {
169
168
 
170
169
  // src/command-line-argument.ts
171
170
  var CommandLineArgument = class {
172
- constructor(propertyName, required, argumentName, alias, dataType, type, defaultValue = null, allowedValues = null, regularExpression = null, description = null) {
173
- if (!propertyName) {
174
- throw new Error("'propertyName' parameter not defined.");
175
- }
176
- if (required === void 0 || required === null) {
177
- throw new Error("'required' parameter not defined.");
178
- }
171
+ constructor(propertyName, required, argumentName, alias, dataType, type, defaultValue, allowedValues, regularExpression = null, description = null) {
179
172
  if (type !== 0 /* KeyValue */ && type !== 1 /* Value */) {
180
173
  throw new Error("'type' parameter invalid.");
181
174
  }
@@ -235,11 +228,11 @@ var CommandLineArgumentFactory = class {
235
228
  * @param required - boolean
236
229
  * @param argumentName - string
237
230
  * @param alias - string
238
- * @param defaultValue - any
231
+ * @param defaultValue - string
239
232
  * @param allowedValues
240
233
  * @param regularExpression
241
234
  */
242
- keyValueArgument(propertyName, description, required, argumentName, alias, defaultValue = null, allowedValues = null, regularExpression = null) {
235
+ keyStringValueArgument(propertyName, description, required, argumentName, alias, defaultValue = null, allowedValues = null, regularExpression = null) {
243
236
  return new CommandLineArgument(
244
237
  propertyName,
245
238
  required,
@@ -253,6 +246,20 @@ var CommandLineArgumentFactory = class {
253
246
  description
254
247
  );
255
248
  }
249
+ keyNumberValueArgument(propertyName, description, required, argumentName, alias, defaultValue = null, allowedValues = null, regularExpression = null) {
250
+ return new CommandLineArgument(
251
+ propertyName,
252
+ required,
253
+ argumentName,
254
+ alias,
255
+ 1 /* Number */,
256
+ 0 /* KeyValue */,
257
+ defaultValue,
258
+ allowedValues,
259
+ regularExpression,
260
+ description
261
+ );
262
+ }
256
263
  /**
257
264
  * Create boolean argument
258
265
  * Examples:
@@ -289,7 +296,7 @@ var CommandLineArgumentFactory = class {
289
296
  * @param allowedValues
290
297
  * @param regularExpression
291
298
  */
292
- valueArgument(propertyName, description, required, allowedValues = null, regularExpression = null) {
299
+ stringValueArgument(propertyName, description, required, allowedValues = null, regularExpression = null) {
293
300
  return new CommandLineArgument(
294
301
  propertyName,
295
302
  required,
@@ -303,6 +310,20 @@ var CommandLineArgumentFactory = class {
303
310
  description
304
311
  );
305
312
  }
313
+ numberValueArgument(propertyName, description, required, allowedValues = null, regularExpression = null) {
314
+ return new CommandLineArgument(
315
+ propertyName,
316
+ required,
317
+ null,
318
+ null,
319
+ 1 /* Number */,
320
+ 1 /* Value */,
321
+ null,
322
+ allowedValues,
323
+ regularExpression,
324
+ description
325
+ );
326
+ }
306
327
  };
307
328
 
308
329
  // src/command-line-director.ts
package/dist/index.mjs CHANGED
@@ -114,12 +114,11 @@ var CommandLine = class {
114
114
  }
115
115
  });
116
116
  this.commandLineArguments.forEach(function(arg) {
117
- var _a;
118
117
  if (arg.required === true && (result.get(arg.propertyName) === void 0 || result.get(arg.propertyName) === null)) {
119
118
  throw new Error(`Required field '${arg.propertyName}' is missing.`);
120
119
  }
121
120
  if (arg.allowedValues && arg.allowedValues.length > 0 && (arg.required === true || result.has(arg.propertyName) && result.get(arg.propertyName) !== null)) {
122
- if (((_a = arg.allowedValues) == null ? void 0 : _a.indexOf(result.get(arg.propertyName))) === -1) {
121
+ if (arg.allowedValues.indexOf(result.get(arg.propertyName)) === -1) {
123
122
  throw new Error(`Value for field '${arg.propertyName}' is not allowed.`);
124
123
  }
125
124
  }
@@ -136,13 +135,7 @@ var CommandLine = class {
136
135
 
137
136
  // src/command-line-argument.ts
138
137
  var CommandLineArgument = class {
139
- constructor(propertyName, required, argumentName, alias, dataType, type, defaultValue = null, allowedValues = null, regularExpression = null, description = null) {
140
- if (!propertyName) {
141
- throw new Error("'propertyName' parameter not defined.");
142
- }
143
- if (required === void 0 || required === null) {
144
- throw new Error("'required' parameter not defined.");
145
- }
138
+ constructor(propertyName, required, argumentName, alias, dataType, type, defaultValue, allowedValues, regularExpression = null, description = null) {
146
139
  if (type !== 0 /* KeyValue */ && type !== 1 /* Value */) {
147
140
  throw new Error("'type' parameter invalid.");
148
141
  }
@@ -202,11 +195,11 @@ var CommandLineArgumentFactory = class {
202
195
  * @param required - boolean
203
196
  * @param argumentName - string
204
197
  * @param alias - string
205
- * @param defaultValue - any
198
+ * @param defaultValue - string
206
199
  * @param allowedValues
207
200
  * @param regularExpression
208
201
  */
209
- keyValueArgument(propertyName, description, required, argumentName, alias, defaultValue = null, allowedValues = null, regularExpression = null) {
202
+ keyStringValueArgument(propertyName, description, required, argumentName, alias, defaultValue = null, allowedValues = null, regularExpression = null) {
210
203
  return new CommandLineArgument(
211
204
  propertyName,
212
205
  required,
@@ -220,6 +213,20 @@ var CommandLineArgumentFactory = class {
220
213
  description
221
214
  );
222
215
  }
216
+ keyNumberValueArgument(propertyName, description, required, argumentName, alias, defaultValue = null, allowedValues = null, regularExpression = null) {
217
+ return new CommandLineArgument(
218
+ propertyName,
219
+ required,
220
+ argumentName,
221
+ alias,
222
+ 1 /* Number */,
223
+ 0 /* KeyValue */,
224
+ defaultValue,
225
+ allowedValues,
226
+ regularExpression,
227
+ description
228
+ );
229
+ }
223
230
  /**
224
231
  * Create boolean argument
225
232
  * Examples:
@@ -256,7 +263,7 @@ var CommandLineArgumentFactory = class {
256
263
  * @param allowedValues
257
264
  * @param regularExpression
258
265
  */
259
- valueArgument(propertyName, description, required, allowedValues = null, regularExpression = null) {
266
+ stringValueArgument(propertyName, description, required, allowedValues = null, regularExpression = null) {
260
267
  return new CommandLineArgument(
261
268
  propertyName,
262
269
  required,
@@ -270,6 +277,20 @@ var CommandLineArgumentFactory = class {
270
277
  description
271
278
  );
272
279
  }
280
+ numberValueArgument(propertyName, description, required, allowedValues = null, regularExpression = null) {
281
+ return new CommandLineArgument(
282
+ propertyName,
283
+ required,
284
+ null,
285
+ null,
286
+ 1 /* Number */,
287
+ 1 /* Value */,
288
+ null,
289
+ allowedValues,
290
+ regularExpression,
291
+ description
292
+ );
293
+ }
273
294
  };
274
295
 
275
296
  // src/command-line-director.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "command-line-director",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Gives direction to you nodejs command line application",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",