public static OptionMap CreateMap(object target, IList<Pair<PropertyInfo, VerbOptionAttribute>> verbs, CommandLineParserSettings settings) { var map = new OptionMap(verbs.Count, settings); foreach (var verb in verbs) { var optionInfo = new OptionInfo(verb.Right, verb.Left) { HasParameterLessCtor = verb.Left.PropertyType.GetConstructor(Type.EmptyTypes) != null }; if (!optionInfo.HasParameterLessCtor && verb.Left.GetValue(target, null) == null) { throw new CommandLineParserException(string.Format("Type {0} must have a parameterless constructor or" + " be already initialized to be used as a verb command.", verb.Left.PropertyType)); } map[verb.Right.UniqueName] = optionInfo; } map.RawOptions = target; return map; }
protected void DefineOptionThatViolatesFormat(OptionInfo option) { PostParsingState.Add(new ParsingError(option.ShortName, option.LongName, true)); }
protected static void EnsureOptionAttributeIsArrayCompatible(OptionInfo option) { if (!option.IsAttributeArrayCompatible) { throw new CommandLineParserException(); } }
public MutuallyExclusiveInfo(OptionInfo option) { BadOption = option; }
private static void SetParserStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness) { var list = ReflectionUtil.RetrievePropertyList<ParserStateAttribute>(options); if (list.Count == 0) { return; } var property = list[0].Left; // This method can be called when parser state is still not intialized if (property.GetValue(options, null) == null) { property.SetValue(options, new CommandLine.ParserState(), null); } var parserState = (IParserState)property.GetValue(options, null); if (parserState == null) { return; } var error = new ParsingError { BadOption = { ShortName = option.ShortName, LongName = option.LongName } }; if (required != null) { error.ViolatesRequired = required.Value; } if (mutualExclusiveness != null) { error.ViolatesMutualExclusiveness = mutualExclusiveness.Value; } parserState.Errors.Add(error); }
private void BuildMutuallyExclusiveMap(OptionInfo option) { var setName = option.MutuallyExclusiveSet; if (!_mutuallyExclusiveSetMap.ContainsKey(setName)) { _mutuallyExclusiveSetMap.Add(setName, new MutuallyExclusiveInfo(option)); } _mutuallyExclusiveSetMap[setName].IncrementOccurrence(); }