-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy pathErrorExtensions.cs
28 lines (24 loc) · 1014 Bytes
/
ErrorExtensions.cs
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
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using CommandLine.Core;
using CommandLine.Infrastructure;
namespace CommandLine
{
static class ErrorExtensions
{
public static ParserResult<T> ToParserResult<T>(this IEnumerable<Error> errors, T instance)
{
return errors.Any()
? (ParserResult<T>)new NotParsed<T>(instance.GetType().ToTypeInfo(), errors)
: (ParserResult<T>)new Parsed<T>(instance);
}
public static IEnumerable<Error> OnlyMeaningfulOnes(this IEnumerable<Error> errors)
{
return errors
.Where(e => !e.StopsProcessing)
.Where(e => !(e.Tag == ErrorType.UnknownOptionError
&& ((UnknownOptionError)e).Token.EqualsOrdinalIgnoreCase("help")));
}
}
}