public OptionInfo this[string key] { get { OptionInfo option = null; if (_map.ContainsKey(key)) { option = _map[key]; } else { string optionKey = null; if (_names.ContainsKey(key)) { optionKey = _names[key]; option = _map[optionKey]; } } return(option); } set { _map[key] = value; if (value.HasBothNames) { _names[value.LongName] = value.ShortName; } } }
protected static void EnsureOptionArrayAttributeIsNotBoundToScalar(OptionInfo option) { if (!option.IsArray && option.IsAttributeArrayCompatible) { throw new CommandLineParserException(); } }
public override ParserState Parse(IStringEnumerator argumentEnumerator, OptionMap map, object options) { string[] parts = argumentEnumerator.Current.Substring(2).Split(new char[] { '=' }, 2); OptionInfo option = map[parts[0]]; if (option == null) { return(ParserState.Failure); } option.IsDefined = true; if (!option.IsBoolean) { if (parts.Length == 1 && !argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next)) { return(ParserState.Failure); } if (parts.Length == 2) { if (option.SetValue(parts[1], options)) { return(ParserState.Success); } else { return(ParserState.Failure); } } else { if (option.SetValue(argumentEnumerator.Next, options)) { return(ParserState.Success | ParserState.MoveOnNextElement); } else { return(ParserState.Failure); } } } else { if (parts.Length == 2) { return(ParserState.Failure); } if (option.SetValue(true, options)) { return(ParserState.Success); } else { return(ParserState.Failure); } } }
private void BuildMutuallyExclusiveMap(OptionInfo option) { var setName = option.MutuallyExclusiveSet; if (!_mutuallyExclusiveSetMap.ContainsKey(setName)) { _mutuallyExclusiveSetMap.Add(setName, 0); } _mutuallyExclusiveSetMap[setName]++; }
private bool DoParseArguments(string[] args, object options) { bool hadError = false; var optionMap = OptionInfo.CreateMap(options, _settings); var target = new TargetWrapper(options); IArgumentEnumerator arguments = new StringArrayEnumerator(args); while (arguments.MoveNext()) { string argument = arguments.Current; if (argument != null && argument.Length > 0) { ArgumentParser parser = ArgumentParser.Create(argument); if (parser != null) { ParserState result = parser.Parse(arguments, optionMap, options); if ((result & ParserState.Failure) == ParserState.Failure) { SetPostParsingStateIfNeeded(options, parser.PostParsingState); hadError = true; break; } if ((result & ParserState.MoveOnNextElement) == ParserState.MoveOnNextElement) { arguments.MoveNext(); } } else if (target.IsValueListDefined) { if (!target.AddValueItemIfAllowed(argument)) { hadError = true; break; } } } } hadError |= !optionMap.EnforceRules(); return(!hadError); }
private static void BuildAndSetPostParsingStateIfNeeded(object options, OptionInfo option, bool?required, bool?mutualExclusiveness) { if (options is CommandLineOptionsBase) { PostParsingState state = new PostParsingState(); if (option != null) { state.BadOptionInfo = option; } if (required != null) { state.ViolatesRequired = required.Value; } if (mutualExclusiveness != null) { state.ViolatesMutualExclusiveness = mutualExclusiveness.Value; } ((CommandLineOptionsBase)options).LastPostParsingState = state; } }
protected static void EnsureOptionArrayAttributeIsNotBoundToScalar(OptionInfo option) { if (!option.IsArray && option.IsAttributeArrayCompatible) throw new CommandLineParserException(); }
protected static void EnsureOptionAttributeIsArrayCompatible(OptionInfo option) { if (!option.IsAttributeArrayCompatible) throw new CommandLineParserException(); }
protected void DefineOptionThatViolatesFormat(OptionInfo option) { this.PostParsingState.BadOptionInfo = option; this.PostParsingState.ViolatesFormat = true; }
public override ParserState Parse(IStringEnumerator argumentEnumerator, OptionMap map, object options) { IStringEnumerator group = new CharEnumeratorEx(argumentEnumerator.Current.Substring(1)); while (group.MoveNext()) { OptionInfo option = map[group.Current]; if (option == null) { return(ParserState.Failure); } option.IsDefined = true; if (!option.IsBoolean) { if (argumentEnumerator.IsLast && group.IsLast) { return(ParserState.Failure); } if (!group.IsLast) { if (option.SetValue(group.GetRemainingFromNext(), options)) { return(ParserState.Success); } else { return(ParserState.Failure); } } if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next)) { return(ParserState.Failure); } else { if (option.SetValue(argumentEnumerator.Next, options)) { return(ParserState.Success | ParserState.MoveOnNextElement); } else { return(ParserState.Failure); } } } else { if (!group.IsLast && map[group.Next] == null) { return(ParserState.Failure); } if (!option.SetValue(true, options)) { return(ParserState.Failure); } } } return(ParserState.Success); }
public MutuallyExclusiveInfo(OptionInfo option) { //BadOption = new BadOptionInfo(); BadOption = option; }
private void BuildMutuallyExclusiveMap(OptionInfo option) { var setName = option.MutuallyExclusiveSet; if (!_mutuallyExclusiveSetMap.ContainsKey(setName)) { //_mutuallyExclusiveSetMap.Add(setName, 0); _mutuallyExclusiveSetMap.Add(setName, new MutuallyExclusiveInfo(option)); } //_mutuallyExclusiveSetMap[setName]++; _mutuallyExclusiveSetMap[setName].IncrementOccurrence(); }
private static void BuildAndSetPostParsingStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness) { if (options is CommandLineOptionsBase) { ParsingError error = new ParsingError(); //if (option != null) //{ error.BadOption.ShortName = option.ShortName; //error.BadOptionShortName = option.ShortName; error.BadOption.LongName = option.LongName; //error.BadOptionLongName = option.LongName; //} if (required != null) error.ViolatesRequired = required.Value; if (mutualExclusiveness != null) error.ViolatesMutualExclusiveness = mutualExclusiveness.Value; ((CommandLineOptionsBase)options).InternalLastPostParsingState.Errors.Add(error); } }
private static void BuildAndSetPostParsingStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness) { if (options is CommandLineOptionsBase) { PostParsingState state = new PostParsingState(); if (option != null) state.BadOptionInfo = option; if (required != null) state.ViolatesRequired = required.Value; if (mutualExclusiveness != null) state.ViolatesMutualExclusiveness = mutualExclusiveness.Value; ((CommandLineOptionsBase)options).LastPostParsingState = state; } }
private static bool ParseArgumentList(string[] args, object options) { bool hadError = false; OptionMap optionMap = OptionInfo.CreateMap(options); IList <string> valueList = ValueListAttribute.GetReference(options); ValueListAttribute vlAttr = ValueListAttribute.GetAttribute(options); IStringEnumerator arguments = new StringEnumeratorEx(args); while (arguments.MoveNext()) { string argument = arguments.Current; if (argument != null && argument.Length > 0) { ArgumentParser parser = ArgumentParser.Create(argument); if (parser != null) { ParserState result = parser.Parse(arguments, optionMap, options); if ((result & ParserState.Failure) == ParserState.Failure) { hadError = true; break; } if ((result & ParserState.MoveOnNextElement) == ParserState.MoveOnNextElement) { arguments.MoveNext(); } } else if (valueList != null) { if (vlAttr.MaximumElements < 0) { lock (valueListLock) { valueList.Add(argument); } } else if (vlAttr.MaximumElements == 0) { hadError = true; break; } else { if (vlAttr.MaximumElements > valueList.Count) { lock (valueListLock) { valueList.Add(argument); } } else { hadError = true; break; } } } } } hadError |= !optionMap.EnforceRules(); return(!hadError); }
private void BuildMutuallyExclusiveMap(OptionInfo option) { var setName = option.MutuallyExclusiveSet; if (!_mutuallyExclusiveSetMap.ContainsKey(setName)) _mutuallyExclusiveSetMap.Add(setName, 0); _mutuallyExclusiveSetMap[setName]++; }
protected void DefineOptionThatViolatesFormat(OptionInfo option) { //this.PostParsingState.BadOptionInfo = option; //this.PostParsingState.ViolatesFormat = true; this.PostParsingState.Add(new ParsingError(option.ShortName, option.LongName, true)); }