-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathNameLookup.cs
More file actions
37 lines (33 loc) · 1.42 KB
/
NameLookup.cs
File metadata and controls
37 lines (33 loc) · 1.42 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
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using CSharpx;
namespace CommandLine.Core
{
enum NameLookupResult
{
NoOptionFound,
BooleanOptionFound,
OtherOptionFound
}
static class NameLookup
{
public static NameLookupResult Contains(string name, IEnumerable<OptionSpecification> specifications, StringComparer comparer)
{
var option = specifications.FirstOrDefault(a => name.MatchName(a.ShortName, a.LongNames, comparer));
if (option == null) return NameLookupResult.NoOptionFound;
return option.ConversionType == typeof(bool) || (option.ConversionType == typeof(int) && option.FlagCounter)
? NameLookupResult.BooleanOptionFound
: NameLookupResult.OtherOptionFound;
}
public static Maybe<char> HavingSeparator(string name, IEnumerable<OptionSpecification> specifications,
StringComparer comparer)
{
return specifications.SingleOrDefault(
a => name.MatchName(a.ShortName, a.LongNames, comparer) && a.Separator != '\0')
.ToMaybe()
.MapValueOrDefault(spec => Maybe.Just(spec.Separator), Maybe.Nothing<char>());
}
}
}