-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathParsedOptionSet.cs
More file actions
550 lines (508 loc) · 24.2 KB
/
Copy pathParsedOptionSet.cs
File metadata and controls
550 lines (508 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
using BytecodeApi.Extensions;
using System.Collections.ObjectModel;
using System.Diagnostics;
namespace BytecodeApi.CommandLineParser;
/// <summary>
/// Represents a set of commandline options, parsed from a given commandline.
/// </summary>
[DebuggerDisplay($"{nameof(ParsedOptionSet)}: Arguments: {{Arguments.Count}}, Options: {{Options.Count}}")]
public sealed class ParsedOptionSet
{
/// <summary>
/// Gets a <see cref="string" /> collection with arguments that are not associated to any <see cref="Option" />. These are the first arguments before any option parameter, e.g. anything before "-a".
/// </summary>
public ReadOnlyCollection<string> Arguments { get; }
/// <summary>
/// Gets a collection of <see cref="ParsedOption" /> objects that were parsed from the given commandline.
/// </summary>
public ReadOnlyCollection<ParsedOption> Options { get; }
/// <summary>
/// Gets the <see cref="ParsedOption" />, identified by an <see cref="Option" /> that matches the <paramref name="argument" /> parameter and throws an exception, if it was not found.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />. If <paramref name="argument" /> matches any of the strings in the <see cref="Option.Arguments" /> property, the <see cref="ParsedOption" /> is returned.</param>
public ParsedOption this[string argument]
{
get
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return GetOptions(argument).FirstOrDefault() ?? throw Throw.KeyNotFound("An option that matches the specified argument was not found.");
}
}
/// <summary>
/// Gets a value indicating whether multiple <see cref="ParsedOption" /> objects share the same <see cref="Option" /> object. This can be used to sanitize commandline arguments.
/// </summary>
public bool HasDuplicateOptions => Options.Select(option => option.Option).Distinct().Count() != Options.Count;
/// <summary>
/// Validates conditions of this <see cref="ParsedOptionSet" /> and invokes a custom handler, if the condition was not met.
/// </summary>
public ValidateHelper Validate { get; }
/// <summary>
/// Asserts conditions of this <see cref="ParsedOptionSet" /> and throws a <see cref="CommandLineParserException" />, if the condition was not met.
/// </summary>
public AssertHelper Assert { get; }
internal ParsedOptionSet(IEnumerable<string> arguments, IEnumerable<ParsedOption> options)
{
Check.ArgumentNull(arguments);
Check.ArgumentNull(options);
Arguments = arguments.ToReadOnlyCollection();
Options = options.ToReadOnlyCollection();
Validate = new(this);
Assert = new(this);
}
/// <summary>
/// Determines whether a <see cref="ParsedOption" /> with the specified <see cref="Option" /> argument exists in this collection.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <returns>
/// <see langword="true" />, if the <see cref="ParsedOption" /> with the specified <see cref="Option" /> argument exists;
/// otherwise, <see langword="false" />.
/// </returns>
public bool HasOption(string argument)
{
return GetOptions(argument).Any();
}
/// <summary>
/// Returns an enumerable collection of all <see cref="ParsedOption" />, identified by an <see cref="Option" /> that matches the <paramref name="argument" /> parameter.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />. If <paramref name="argument" /> matches any of the strings in the <see cref="Option.Arguments" /> property, the <see cref="ParsedOption" /> is returned.</param>
/// <returns>
/// An enumerable collection of all <see cref="ParsedOption" />, identified by an <see cref="Option" /> that matches the <paramref name="argument" /> parameter.
/// </returns>
public IEnumerable<ParsedOption> GetOptions(string argument)
{
foreach (ParsedOption option in Options)
{
if (option.Option.Arguments.Contains(argument))
{
yield return option;
}
}
}
/// <summary>
/// Handles all <see cref="ParsedOption" /> objects with the specified argument using a custom handler.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="handler">A custom handler that is invoked with a <see cref="string" />[] containing the values of the <see cref="ParsedOption" />.</param>
/// <returns>
/// A reference to this instance after the operation has completed.
/// </returns>
public ParsedOptionSet Handle(string argument, Action<string[]> handler)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(handler);
foreach (ParsedOption option in GetOptions(argument))
{
handler(option.Values.ToArray());
}
return this;
}
/// <summary>
/// Helper class that validates <see cref="CommandLineParser.ParsedOptionSet" /> conditions. If a condition is not met, a custom handler is invoked.
/// </summary>
public sealed class ValidateHelper
{
private readonly ParsedOptionSet ParsedOptionSet;
internal ValidateHelper(ParsedOptionSet parsedOptionSet)
{
ParsedOptionSet = parsedOptionSet;
}
/// <summary>
/// Validates that the specified argument is present.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet OptionRequired(string argument, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
if (!ParsedOptionSet.HasOption(argument))
{
failed();
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that the argument has only one occurrence, or none.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet OptionNotDuplicate(string argument, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
if (ParsedOptionSet.GetOptions(argument).Count() > 1)
{
failed();
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that the argument has a specific amount of values. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="count">A <see cref="int" /> specifying the amount of values for the <see cref="ParsedOption" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet ValueCount(string argument, int count, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (option.Values.Count != count)
{
failed();
}
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that the argument has a minimum amount of values. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="count">A <see cref="int" /> specifying the minimum amount of values for the <see cref="ParsedOption" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet MinimumValueCount(string argument, int count, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (option.Values.Count < count)
{
failed();
}
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that the argument does not exceed a maximum amount of values. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="count">A <see cref="int" /> specifying the maximum amount of values for the <see cref="ParsedOption" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet MaximumValueCount(string argument, int count, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (option.Values.Count > count)
{
failed();
}
}
return ParsedOptionSet;
}
/// <summary>
/// Performs a custom validation on the values. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="validate">The <see cref="Func{T, TResult}" /> that determines whether the validation succeeded.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet Custom(string argument, Func<string[], bool> validate, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(validate);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (!validate(option.Values.ToArray()))
{
failed();
}
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that all values represent a valid <see cref="int" /> value. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet Int32(string argument, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (!option.Values.All(value => value.ToInt32OrNull() != null))
{
failed();
}
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that all values represent existing files. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet FileExists(string argument, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (!option.Values.All(File.Exists))
{
failed();
}
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that all values represent filenames with one of several specific extensions. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="extensions">A set of allowed extensions for each filename.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet FileExtension(string argument, string[] extensions, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (!option.Values.All(value => extensions.Any(extension => extension.TrimStart('.').Equals(Path.GetExtension(value).TrimStart('.'), StringComparison.OrdinalIgnoreCase))))
{
failed();
}
}
return ParsedOptionSet;
}
/// <summary>
/// Validates that all values represent existing directories. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="failed">A custom handler that is invoked, if the condition is not met.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet DirectoryExists(string argument, Action failed)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
Check.ArgumentNull(failed);
foreach (ParsedOption option in ParsedOptionSet.GetOptions(argument))
{
if (!option.Values.All(Directory.Exists))
{
failed();
}
}
return ParsedOptionSet;
}
}
/// <summary>
/// Helper class that asserts <see cref="CommandLineParser.ParsedOptionSet" /> conditions. If a condition is not met, an exception is thrown.
/// </summary>
public sealed class AssertHelper
{
private readonly ParsedOptionSet ParsedOptionSet;
internal AssertHelper(ParsedOptionSet parsedOptionSet)
{
ParsedOptionSet = parsedOptionSet;
}
/// <summary>
/// Validates that the specified argument is present; otherwise, a <see cref="CommandLineParserException" /> is thrown.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet OptionRequired(string argument)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.OptionRequired(argument, () =>
{
throw new CommandLineParserException(CommandLineParserError.OptionRequired, $"Option '{argument}' is required.");
});
}
/// <summary>
/// Validates that the argument has only one occurrence, or none; otherwise, a <see cref="CommandLineParserException" /> is thrown.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet OptionNotDuplicate(string argument)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.OptionNotDuplicate(argument, () =>
{
throw new CommandLineParserException(CommandLineParserError.OptionNotDuplicate, $"Option '{argument}' must not have multiple occurrences.");
});
}
/// <summary>
/// Validates that the argument has a specific amount of values; otherwise, a <see cref="CommandLineParserException" /> is thrown. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="count">A <see cref="int" /> specifying the amount of values for the <see cref="ParsedOption" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet ValueCount(string argument, int count)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.ValueCount(argument, count, () =>
{
throw new CommandLineParserException(CommandLineParserError.ValueCount, $"Option '{argument}' must have at least {count} values.");
});
}
/// <summary>
/// Validates that the argument has a minimum amount of values; otherwise, a <see cref="CommandLineParserException" /> is thrown. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="count">A <see cref="int" /> specifying the minimum amount of values for the <see cref="ParsedOption" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet MinimumValueCount(string argument, int count)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.MinimumValueCount(argument, count, () =>
{
throw new CommandLineParserException(CommandLineParserError.MinimumValueCount, $"Option '{argument}' must have at least {count} values.");
});
}
/// <summary>
/// Validates that the argument does not exceed a maximum amount of values; otherwise, a <see cref="CommandLineParserException" /> is thrown. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="count">A <see cref="int" /> specifying the maximum amount of values for the <see cref="ParsedOption" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet MaximumValueCount(string argument, int count)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.MaximumValueCount(argument, count, () =>
{
throw new CommandLineParserException(CommandLineParserError.MaximumValueCount, $"Option '{argument}' must not have more than {count} values.");
});
}
/// <summary>
/// Performs a custom validation on the values and throws a <see cref="CommandLineParserException" />, if the validation failed. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="validate">The <see cref="Func{T, TResult}" /> that determines whether the validation succeeded.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet Custom(string argument, Func<string[], bool> validate)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.Custom(argument, validate, () =>
{
throw new CommandLineParserException(CommandLineParserError.Custom, $"Custom validation for option '{argument}' failed.");
});
}
/// <summary>
/// Validates that all values represent a valid <see cref="int" /> value; otherwise, a <see cref="CommandLineParserException" /> is thrown. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet Int32(string argument)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.Int32(argument, () =>
{
throw new CommandLineParserException(CommandLineParserError.Int32, $"The value of option '{argument}' is not a valid Int32 value.");
});
}
/// <summary>
/// Validates that all values represent existing files; otherwise, a <see cref="CommandLineParserException" /> is thrown. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet FileExists(string argument)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.FileExists(argument, () =>
{
throw new CommandLineParserException(CommandLineParserError.FileExists, $"File as specified in option '{argument}' was not found.");
});
}
/// <summary>
/// Validates that all values represent filenames with one of several specific extensions; otherwise, a <see cref="CommandLineParserException" /> is thrown. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <param name="extensions">A set of allowed extensions for each filename.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet FileExtension(string argument, params string[] extensions)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.FileExtension(argument, extensions, () =>
{
throw new CommandLineParserException(CommandLineParserError.FileExtension, $"File extension as specified in option '{argument}' is not allowed.");
});
}
/// <summary>
/// Validates that all values represent existing directories; otherwise, a <see cref="CommandLineParserException" /> is thrown. If the <see cref="Option" /> was not found, this validation succeeds.
/// </summary>
/// <param name="argument">A <see cref="string" /> that identifies an <see cref="Option" />.</param>
/// <returns>
/// A reference to the instance of <see cref="CommandLineParser.ParsedOptionSet" /> after the operation has completed.
/// </returns>
public ParsedOptionSet DirectoryExists(string argument)
{
Check.ArgumentNull(argument);
Check.ArgumentEx.StringNotEmpty(argument);
return ParsedOptionSet.Validate.DirectoryExists(argument, () =>
{
throw new CommandLineParserException(CommandLineParserError.DirectoryExists, $"Directory as specified in option '{argument}' was not found.");
});
}
}
}