BadScript 2
Loading...
Searching...
No Matches
SpecificationGuards.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;
5
6using CSharpx;
7
8namespace CommandLine.Core
9{
10 internal static class SpecificationGuards
11 {
12 public static readonly IEnumerable<Tuple<Func<Specification, bool>, string>> Lookup =
13 new List<Tuple<Func<Specification, bool>, string>>
14 {
15 Tuple.Create(GuardAgainstScalarWithRange(),
16 "Scalar option specifications do not support range specification."
17 ),
18 Tuple.Create(GuardAgainstSequenceWithWrongRange(), "Bad range in sequence option specifications."),
20 "Zero is not allowed in range of sequence option specifications."
21 ),
22 Tuple.Create(GuardAgainstOneCharLongName(), "Long name should be longer than one character."),
23 };
24
25 private static Func<Specification, bool> GuardAgainstScalarWithRange()
26 {
27 return spec => spec.TargetType == TargetType.Scalar && (spec.Min.IsJust() || spec.Max.IsJust());
28 }
29
30 private static Func<Specification, bool> GuardAgainstSequenceWithWrongRange()
31 {
32 return spec => spec.TargetType == TargetType.Sequence && spec.HavingRange((min, max) => min > max);
33 }
34
35 private static Func<Specification, bool> GuardAgainstOneCharLongName()
36 {
37 return spec => spec.IsOption() && ((OptionSpecification)spec).LongName.Length == 1;
38 }
39
40 private static Func<Specification, bool> GuardAgainstSequenceWithZeroRange()
41 {
42 return spec =>
43 spec.TargetType == TargetType.Sequence &&
44 (spec.HavingMin(min => min == 0) || spec.HavingMax(max => max == 0));
45 }
46 }
47}
static readonly IEnumerable< Tuple< Func< Specification, bool >, string > > Lookup
static Func< Specification, bool > GuardAgainstScalarWithRange()
static Func< Specification, bool > GuardAgainstOneCharLongName()
static Func< Specification, bool > GuardAgainstSequenceWithWrongRange()
static Func< Specification, bool > GuardAgainstSequenceWithZeroRange()