public override ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options) { var parts = argumentEnumerator.Current.Substring(2).Split(new[] { '=' }, 2); var option = map[parts[0]]; bool valueSetting; if (option == null) return _ignoreUnkwnownArguments ? ParserState.MoveOnNextElement : ParserState.Failure; option.IsDefined = true; EnsureOptionArrayAttributeIsNotBoundToScalar(option); if (!option.IsBoolean) { if (parts.Length == 1 && (argumentEnumerator.IsLast || !IsInputValue(argumentEnumerator.Next))) return ParserState.Failure; if (parts.Length == 2) { if (!option.IsArray) { valueSetting = option.SetValue(parts[1], options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting); } EnsureOptionAttributeIsArrayCompatible(option); var items = GetNextInputValues(argumentEnumerator); items.Insert(0, parts[1]); valueSetting = option.SetValue(items, options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting); } else { if (!option.IsArray) { valueSetting = option.SetValue(argumentEnumerator.Next, options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting, true); } EnsureOptionAttributeIsArrayCompatible(option); var items = GetNextInputValues(argumentEnumerator); valueSetting = option.SetValue(items, options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting); } } if (parts.Length == 2) return ParserState.Failure; valueSetting = option.SetValue(true, options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting); }
public abstract ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options);
public static OptionMap CreateMap(object target, CommandLineParserSettings settings) { var list = ReflectionUtil.RetrievePropertyList<OptionAttribute>(target); if (list != null) { var map = new OptionMap(list.Count, settings); foreach (var pair in list.Where(pair => pair != null && pair.Right != null)) { map[pair.Right.UniqueName] = new OptionInfo(pair.Right, pair.Left); } map.RawOptions = target; return map; } return null; }
public override ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options) { using (IArgumentEnumerator group = new OneCharStringEnumerator(argumentEnumerator.Current.Substring(1))) { while (group.MoveNext()) { var option = map[group.Current]; if (option == null) return _ignoreUnkwnownArguments ? ParserState.MoveOnNextElement : ParserState.Failure; option.IsDefined = true; EnsureOptionArrayAttributeIsNotBoundToScalar(option); if (!option.IsBoolean) { if (argumentEnumerator.IsLast && group.IsLast) return ParserState.Failure; bool valueSetting; IList<string> items; if (!group.IsLast) { if (!option.IsArray) { valueSetting = option.SetValue(group.GetRemainingFromNext(), options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting); } EnsureOptionAttributeIsArrayCompatible(option); items = GetNextInputValues(argumentEnumerator); items.Insert(0, @group.GetRemainingFromNext()); valueSetting = option.SetValue(items, options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting, true); } if (!argumentEnumerator.IsLast && !IsInputValue(argumentEnumerator.Next)) return ParserState.Failure; if (!option.IsArray) { valueSetting = option.SetValue(argumentEnumerator.Next, options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting, true); } EnsureOptionAttributeIsArrayCompatible(option); items = GetNextInputValues(argumentEnumerator); valueSetting = option.SetValue(items, options); if (!valueSetting) DefineOptionThatViolatesFormat(option); return BooleanToParserState(valueSetting); } if ([email protected] && map[@group.Next] == null) return ParserState.Failure; if (!option.SetValue(true, options)) return ParserState.Failure; } } return ParserState.Success; }