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
3
using
System;
4
using
System.Collections.Generic;
5
using
System.Linq;
6
7
using
CSharpx
;
8
9
namespace
CommandLine.Core
10
{
11
internal
enum
NameLookupResult
12
{
13
NoOptionFound
,
14
BooleanOptionFound
,
15
OtherOptionFound
,
16
}
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
}
CSharpx.Maybe
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
CommandLine.Core.NameLookup
Definition
NameLookup.cs:19
CommandLine.Core.NameLookup.Contains
static NameLookupResult Contains(string name, IEnumerable< OptionSpecification > specifications, StringComparer comparer)
Definition
NameLookup.cs:20
CommandLine.Core.NameLookup.HavingSeparator
static Maybe< char > HavingSeparator(string name, IEnumerable< OptionSpecification > specifications, StringComparer comparer)
Definition
NameLookup.cs:37
CommandLine.Core.OptionSpecification
Definition
OptionSpecification.cs:12
CommandLine.Core.OptionSpecification.FlagCounter
bool FlagCounter
Whether this is an int option that counts how many times a flag was set rather than taking a value on...
Definition
OptionSpecification.cs:64
CSharpx
Definition
Either.cs:7
CommandLine.Core
Definition
ArgumentsExtensions.cs:10
CommandLine.Core.NameLookupResult
NameLookupResult
Definition
NameLookup.cs:12
CommandLine.Core.NameLookupResult.NoOptionFound
@ NoOptionFound
CommandLine.Core.NameLookupResult.OtherOptionFound
@ OtherOptionFound
CommandLine.Core.NameLookupResult.BooleanOptionFound
@ BooleanOptionFound
deps
commandlineparser
src
CommandLine
Core
NameLookup.cs
Generated by
1.9.8