57 private static Func<IEnumerable<SpecificationProperty>, IEnumerable<Error>>
EnforceGroup()
63 where sp.Specification.IsOption()
65 where o.Group.Length > 0
66 select
new {
Option = o, sp.Value, sp.Specification.DefaultValue };
68 var groups = from o in optionsValues
69 group o by o.Option.Group
73 var errorGroups = groups.Where(gr => gr.All(g => g.Value.IsNothing() && g.DefaultValue.IsNothing()));
75 if (errorGroups.Any())
88 return Enumerable.Empty<
Error>();
96 IEnumerable<OptionSpecification> options =
98 where sp.Specification.IsOption()
99 where sp.Value.IsJust()
101 where o.SetName.Length > 0
104 IEnumerable<IGrouping<string, OptionSpecification>> groups = from o in options
109 if (groups.Count() > 1)
116 return Enumerable.Empty<
Error>();
120 private static Func<IEnumerable<SpecificationProperty>, IEnumerable<Error>>
EnforceRequired()
124 IEnumerable<Specification> requiredWithValue = from sp in specProps
125 where sp.Specification.IsOption()
126 where sp.Specification.Required
127 where sp.Value.IsJust()
129 where o.SetName.Length > 0
130 select sp.Specification;
132 IEnumerable<string> setWithRequiredValue = (
133 from s in requiredWithValue
135 where o.SetName.Length > 0
139 IEnumerable<Specification> requiredWithoutValue = from sp in specProps
140 where sp.Specification.IsOption()
141 where sp.Specification.Required
142 where sp.Value.IsNothing()
144 where o.SetName.Length > 0
145 where o.Group.Length == 0
146 where setWithRequiredValue
147 .ContainsIfNotEmpty(o.SetName)
148 select sp.Specification;
150 IEnumerable<Specification> missing =
152 .Except(requiredWithValue)
153 .Concat(from sp in specProps
154 where sp.Specification.IsOption()
155 where sp.Specification.Required
156 where sp.Value.IsNothing()
158 where o.SetName.Length == 0
159 where o.Group.Length == 0
160 select sp.Specification
162 .Concat(from sp in specProps
163 where sp.Specification.IsValue()
164 where sp.Specification.Required
165 where sp.Value.IsNothing()
166 select sp.Specification
175 private static Func<IEnumerable<SpecificationProperty>, IEnumerable<Error>>
EnforceRange()
179 IEnumerable<SpecificationProperty> options = specProps
180 .Where(sp => sp.Specification.TargetType ==
183 .Where(sp => sp.Value.IsJust())
185 (sp.Specification.Min.IsJust() &&
186 ((Array)sp.Value.FromJustOrFail()).Length <
187 sp.Specification.Min.FromJustOrFail()) ||
188 (sp.Specification.Max.IsJust() &&
189 ((Array)sp.Value.FromJustOrFail()).Length >
190 sp.Specification.Max.FromJustOrFail())
200 return Enumerable.Empty<
Error>();
204 private static Func<IEnumerable<SpecificationProperty>, IEnumerable<Error>>
EnforceSingle(
205 IEnumerable<Token> tokens,
206 bool allowMultiInstance)
210 if (allowMultiInstance)
212 return Enumerable.Empty<
Error>();
215 IEnumerable<OptionSpecification> specs = from sp in specProps
216 where sp.Specification.IsOption()
217 where sp.Value.IsJust()
220 var shortOptions = from t in tokens
222 join o in specs on t.Text equals o.ShortName into to
223 from o in to.DefaultIfEmpty()
225 select
new { o.ShortName, o.LongName };
227 var longOptions = from t in tokens
229 join o in specs on t.Text equals o.LongName into to
230 from o in to.DefaultIfEmpty()
232 select
new { o.ShortName, o.LongName };
234 var groups = from x in shortOptions.Concat(longOptions)
237 let count = g.Count()
238 select
new {
Value = g.Key, Count = count };
240 IEnumerable<RepeatedOptionError> errors = from y in groups