BadScript 2
Loading...
Searching...
No Matches
Error.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4using System.Collections.Generic;
5using System.Linq;
6
7namespace CommandLine
8{
104
109 public abstract class Error : IEquatable<Error>
110 {
116 protected internal Error(ErrorType tag, bool stopsProcessing)
117 {
118 Tag = tag;
119 StopsProcessing = stopsProcessing;
120 }
121
126 protected internal Error(ErrorType tag)
127 : this(tag, false) { }
128
132 public ErrorType Tag { get; }
133
139 public bool StopsProcessing { get; }
140
141#region IEquatable<Error> Members
142
154 public bool Equals(Error other)
155 {
156 if (other == null)
157 {
158 return false;
159 }
160
161 return Tag.Equals(other.Tag);
162 }
163
164#endregion
165
176 public override bool Equals(object obj)
177 {
178 Error other = obj as Error;
179
180 if (other != null)
181 {
182 return Equals(other);
183 }
184
185 return base.Equals(obj);
186 }
187
192 public override int GetHashCode()
193 {
194 return new { Tag, StopsProcessing }.GetHashCode();
195 }
196 }
197
201 public abstract class TokenError : Error, IEquatable<TokenError>
202 {
208 protected internal TokenError(ErrorType tag, string token)
209 : base(tag)
210 {
211 if (token == null)
212 {
213 throw new ArgumentNullException("token");
214 }
215
216 Token = token;
217 }
218
222 public string Token { get; }
223
224#region IEquatable<TokenError> Members
225
238 public bool Equals(TokenError other)
239 {
240 if (other == null)
241 {
242 return false;
243 }
244
245 return Tag.Equals(other.Tag) && Token.Equals(other.Token);
246 }
247
248#endregion
249
260 public override bool Equals(object obj)
261 {
262 TokenError other = obj as TokenError;
263
264 if (other != null)
265 {
266 return Equals(other);
267 }
268
269 return base.Equals(obj);
270 }
271
276 public override int GetHashCode()
277 {
278 return new { Tag, StopsProcessing, Token }.GetHashCode();
279 }
280 }
281
285 public sealed class BadFormatTokenError : TokenError
286 {
287 internal BadFormatTokenError(string token)
288 : base(ErrorType.BadFormatTokenError, token) { }
289 }
290
294 public abstract class NamedError : Error, IEquatable<NamedError>
295 {
301 protected internal NamedError(ErrorType tag, NameInfo nameInfo)
302 : base(tag)
303 {
304 NameInfo = nameInfo;
305 }
306
310 public NameInfo NameInfo { get; }
311
312#region IEquatable<NamedError> Members
313
326 public bool Equals(NamedError other)
327 {
328 if (other == null)
329 {
330 return false;
331 }
332
333 return Tag.Equals(other.Tag) && NameInfo.Equals(other.NameInfo);
334 }
335
336#endregion
337
348 public override bool Equals(object obj)
349 {
350 NamedError other = obj as NamedError;
351
352 if (other != null)
353 {
354 return Equals(other);
355 }
356
357 return base.Equals(obj);
358 }
359
364 public override int GetHashCode()
365 {
366 return new { Tag, StopsProcessing, NameInfo }.GetHashCode();
367 }
368 }
369
374 {
376 : base(ErrorType.MissingValueOptionError, nameInfo) { }
377 }
378
382 public sealed class UnknownOptionError : TokenError
383 {
384 internal UnknownOptionError(string token)
385 : base(ErrorType.UnknownOptionError, token) { }
386 }
387
392 {
394 : base(ErrorType.MissingRequiredOptionError, nameInfo) { }
395 }
396
401 {
402 internal MutuallyExclusiveSetError(NameInfo nameInfo, string setName)
403 : base(ErrorType.MutuallyExclusiveSetError, nameInfo)
404 {
405 SetName = setName;
406 }
407
411 public string SetName { get; }
412 }
413
418 {
420 : base(ErrorType.BadFormatConversionError, nameInfo) { }
421 }
422
427 {
429 : base(ErrorType.SequenceOutOfRangeError, nameInfo) { }
430 }
431
435 public sealed class RepeatedOptionError : NamedError
436 {
437 internal RepeatedOptionError(NameInfo nameInfo)
438 : base(ErrorType.RepeatedOptionError, nameInfo) { }
439 }
440
444 public sealed class BadVerbSelectedError : TokenError
445 {
446 internal BadVerbSelectedError(string token)
447 : base(ErrorType.BadVerbSelectedError, token) { }
448 }
449
453 public sealed class HelpRequestedError : Error
454 {
456 : base(ErrorType.HelpRequestedError, true) { }
457 }
458
462 public sealed class HelpVerbRequestedError : Error
463 {
464 internal HelpVerbRequestedError(string verb, Type type, bool matched)
466 {
467 Verb = verb;
468 Type = type;
469 Matched = matched;
470 }
471
475 public string Verb { get; }
476
480 public Type Type { get; }
481
488 public bool Matched { get; }
489 }
490
494 public sealed class NoVerbSelectedError : Error
495 {
498 }
499
503 public sealed class VersionRequestedError : Error
504 {
506 : base(ErrorType.VersionRequestedError, true) { }
507 }
508
512 public sealed class SetValueExceptionError : NamedError
513 {
514 internal SetValueExceptionError(NameInfo nameInfo, Exception exception, object value)
515 : base(ErrorType.SetValueExceptionError, nameInfo)
516 {
517 Exception = exception;
518 Value = value;
519 }
520
524 public Exception Exception { get; }
525
529 public object Value { get; }
530 }
531
536 {
537 public const string ErrorMessage =
538 "Check if Option or Value attribute values are set properly for the given type.";
539
542 }
543
544 public sealed class MissingGroupOptionError : Error, IEquatable<Error>, IEquatable<MissingGroupOptionError>
545 {
546 public const string ErrorMessage = "At least one option in a group must have value.";
547
548 internal MissingGroupOptionError(string group, IEnumerable<NameInfo> names)
550 {
551 Group = group;
552 Names = names;
553 }
554
555 public string Group { get; }
556
557 public IEnumerable<NameInfo> Names { get; }
558
559#region IEquatable<Error> Members
560
561 public new bool Equals(Error obj)
562 {
564
565 if (other != null)
566 {
567 return Equals(other);
568 }
569
570 return base.Equals(obj);
571 }
572
573#endregion
574
575#region IEquatable<MissingGroupOptionError> Members
576
578 {
579 if (other == null)
580 {
581 return false;
582 }
583
584 return Group.Equals(other.Group) && Names.SequenceEqual(other.Names);
585 }
586
587#endregion
588 }
589
591 {
593
596 {
597 Option = option;
598 }
599 }
600
604 public sealed class MultipleDefaultVerbsError : Error
605 {
606 public const string ErrorMessage = "More than one default verb is not allowed.";
607
610 }
611}
Models an error generated when a value conversion fails.
Definition Error.cs:418
BadFormatConversionError(NameInfo nameInfo)
Definition Error.cs:419
Models an error generated when an invalid token is detected.
Definition Error.cs:286
BadFormatTokenError(string token)
Definition Error.cs:287
Models an error generated when an unknown verb is detected.
Definition Error.cs:445
BadVerbSelectedError(string token)
Definition Error.cs:446
Base type of all errors.
Definition Error.cs:110
Error(ErrorType tag, bool stopsProcessing)
Initializes a new instance of the CommandLine.Error class.
Definition Error.cs:116
override bool Equals(object obj)
Determines whether the specified System.Object is equal to the current System.Object.
Definition Error.cs:176
Error(ErrorType tag)
Initializes a new instance of the CommandLine.Error class.
Definition Error.cs:126
ErrorType Tag
Error type discriminator, defined as CommandLine.ErrorType enumeration.
Definition Error.cs:132
override int GetHashCode()
Serves as a hash function for a particular type.
Definition Error.cs:192
bool Equals(Error other)
Returns a value that indicates whether the current instance and a specified CommandLine....
Definition Error.cs:154
bool StopsProcessing
Tells if error stops parsing process. Filtered by CommandLine.ErrorExtensions.OnlyMeaningfulOnes(Syst...
Definition Error.cs:139
GroupOptionAmbiguityError(NameInfo option)
Definition Error.cs:594
Models an error generated when a user explicitly requests help.
Definition Error.cs:454
Models an error generated when a user explicitly requests help in verb commands scenario.
Definition Error.cs:463
Type Type
System.Type of verb command.
Definition Error.cs:480
HelpVerbRequestedError(string verb, Type type, bool matched)
Definition Error.cs:464
bool Matched
trueif verb command is found; otherwise false
Definition Error.cs:488
string Verb
Verb command string.
Definition Error.cs:475
Models an error generated when an invalid token is detected.
Definition Error.cs:536
MissingGroupOptionError(string group, IEnumerable< NameInfo > names)
Definition Error.cs:548
bool Equals(MissingGroupOptionError other)
Definition Error.cs:577
new bool Equals(Error obj)
Definition Error.cs:561
IEnumerable< NameInfo > Names
Definition Error.cs:557
Models an error generated when a required option is required.
Definition Error.cs:392
MissingRequiredOptionError(NameInfo nameInfo)
Definition Error.cs:393
Models an error generated when an option lacks its value.
Definition Error.cs:374
MissingValueOptionError(NameInfo nameInfo)
Definition Error.cs:375
Models an error generated when multiple default verbs are defined.
Definition Error.cs:605
Models an error generated when a an option from another set is defined.
Definition Error.cs:401
MutuallyExclusiveSetError(NameInfo nameInfo, string setName)
Definition Error.cs:402
string SetName
Option's set name.
Definition Error.cs:411
Models name information, used in CommandLine.Error instances.
Definition NameInfo.cs:11
override int GetHashCode()
Serves as a hash function for a particular type.
Definition NameInfo.cs:102
bool Equals(NameInfo other)
Returns a value that indicates whether the current instance and a specified CommandLine....
Definition NameInfo.cs:64
Base type of all erros with name information.
Definition Error.cs:295
NameInfo NameInfo
Name information relative to this error instance.
Definition Error.cs:310
NamedError(ErrorType tag, NameInfo nameInfo)
Initializes a new instance of the CommandLine.NamedError class.
Definition Error.cs:301
bool Equals(NamedError other)
Returns a value that indicates whether the current instance and a specified CommandLine....
Definition Error.cs:326
override int GetHashCode()
Serves as a hash function for a particular type.
Definition Error.cs:364
override bool Equals(object obj)
Determines whether the specified System.Object is equal to the current System.Object.
Definition Error.cs:348
Models an error generated when no verb is selected.
Definition Error.cs:495
Models an error generated when an option is repeated two or more times.
Definition Error.cs:436
RepeatedOptionError(NameInfo nameInfo)
Definition Error.cs:437
Models an error generated when a sequence value lacks elements.
Definition Error.cs:427
SequenceOutOfRangeError(NameInfo nameInfo)
Definition Error.cs:428
Models as error generated when exception is thrown at Property.SetValue.
Definition Error.cs:513
Exception Exception
The expection thrown from Property.SetValue.
Definition Error.cs:524
SetValueExceptionError(NameInfo nameInfo, Exception exception, object value)
Definition Error.cs:514
object Value
The value that had to be set to the property.
Definition Error.cs:529
Base type of all errors related to bad token detection.
Definition Error.cs:202
TokenError(ErrorType tag, string token)
Initializes a new instance of the CommandLine.TokenError class.
Definition Error.cs:208
override bool Equals(object obj)
Determines whether the specified System.Object is equal to the current System.Object.
Definition Error.cs:260
string Token
The string containing the token text.
Definition Error.cs:222
bool Equals(TokenError other)
Returns a value that indicates whether the current instance and a specified CommandLine....
Definition Error.cs:238
override int GetHashCode()
Serves as a hash function for a particular type.
Definition Error.cs:276
Models an error generated when an unknown option is detected.
Definition Error.cs:383
UnknownOptionError(string token)
Definition Error.cs:384
Models an error generated when a user explicitly requests version.
Definition Error.cs:504
ErrorType
Discriminator enumeration of CommandLine.Error derivates.
Definition Error.cs:13