BadScript 2
Loading...
Searching...
No Matches
NameLookup.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
7using CSharpx;
8
9namespace CommandLine.Core
10{
17
18 internal static class NameLookup
19 {
20 public static NameLookupResult Contains(string name,
21 IEnumerable<OptionSpecification> specifications,
22 StringComparer comparer)
23 {
24 OptionSpecification option =
25 specifications.FirstOrDefault(a => name.MatchName(a.ShortName, a.LongName, comparer));
26
27 if (option == null)
28 {
29 return NameLookupResult.NoOptionFound;
30 }
31
32 return option.ConversionType == typeof(bool) || (option.ConversionType == typeof(int) && option.FlagCounter)
33 ? NameLookupResult.BooleanOptionFound
34 : NameLookupResult.OtherOptionFound;
35 }
36
37 public static Maybe<char> HavingSeparator(string name,
38 IEnumerable<OptionSpecification> specifications,
39 StringComparer comparer)
40 {
41 return specifications
42 .SingleOrDefault(a => name.MatchName(a.ShortName, a.LongName, comparer) && a.Separator != '\0')
43 .ToMaybe()
44 .MapValueOrDefault(spec => Maybe.Just(spec.Separator), Maybe.Nothing<char>());
45 }
46 }
47}
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
static NameLookupResult Contains(string name, IEnumerable< OptionSpecification > specifications, StringComparer comparer)
Definition NameLookup.cs:20
static Maybe< char > HavingSeparator(string name, IEnumerable< OptionSpecification > specifications, StringComparer comparer)
Definition NameLookup.cs:37
bool FlagCounter
Whether this is an int option that counts how many times a flag was set rather than taking a value on...