-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathSpecificationGuards.cs
More file actions
43 lines (37 loc) · 1.88 KB
/
Copy pathSpecificationGuards.cs
File metadata and controls
43 lines (37 loc) · 1.88 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
38
39
40
41
42
43
// 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 CSharpx;
namespace CommandLine.Core
{
static class SpecificationGuards
{
public static readonly IEnumerable<Tuple<Func<Specification, bool>, string>> Lookup = new List<Tuple<Func<Specification, bool>, string>>
{
Tuple.Create(GuardAgainstScalarWithRange(), "Scalar option specifications do not support range specification."),
Tuple.Create(GuardAgainstSequenceWithWrongRange(), "Bad range in sequence option specifications."),
Tuple.Create(GuardAgainstSequenceWithZeroRange(), "Zero is not allowed in range of sequence option specifications."),
Tuple.Create(GuardAgainstOneCharLongName(), "Long name should be longer than one character.")
};
private static Func<Specification, bool> GuardAgainstScalarWithRange()
{
return spec => spec.TargetType == TargetType.Scalar
&& (spec.Min.IsJust() || spec.Max.IsJust());
}
private static Func<Specification, bool> GuardAgainstSequenceWithWrongRange()
{
return spec => spec.TargetType == TargetType.Sequence
&& spec.HavingRange((min, max) => min > max);
}
private static Func<Specification, bool> GuardAgainstOneCharLongName()
{
return spec => spec.IsOption() && ((OptionSpecification)spec).LongName.Length == 1;
}
private static Func<Specification, bool> GuardAgainstSequenceWithZeroRange()
{
return spec => spec.TargetType == TargetType.Sequence
&& (spec.HavingMin(min => min == 0)
|| spec.HavingMax(max => max == 0));
}
}
}