protected ParserConfig(ParserOptions options, IEnumerable <ITerminatingTrigger> triggers, IVerbFactory factory) { Options = options; ArgumentPrefix = '-'; if (options.HasFlag(ParserOptions.CaseInsensitive)) { ShortNameArguments = new Dictionary <char, IShortNameArgument>(new CaseInsensitiveCharComparer()); LongNameArguments = new Dictionary <string, ILongNameArgument>( #if NET35 StringComparer.InvariantCultureIgnoreCase); #else StringComparer.OrdinalIgnoreCase); #endif } else { ShortNameArguments = new Dictionary <char, IShortNameArgument>(); LongNameArguments = new Dictionary <string, ILongNameArgument>(); } PositionalArguments = new List <IPositionalArgument>(); Verbs = new Dictionary <string, IVerbParserConfig>(); PostParseMethods = new List <MethodInfo>(); RequiredMutuallyExclusiveArguments = new HashSet <string>(); RequiredNamedArguments = new HashSet <string>(); InitializeTriggers(triggers); VerbFactory = factory; }
private static Exception VerbMustHaveFactoryDefined(PropertyInfo verbProp, IVerbFactory factory) { if (!factory.CanCreateVerb(verbProp.PropertyType)) { return(new ArgumentIntegrityException(String.Format( "Verb '{0}' has no default constructor or factory defined for its type. Use a custom IVerbFactory for this parser.", verbProp.Name))); } return(null); }
internal void EnsureVerbIntegrity <T>(IVerbFactory factory) { var integrityExceptions = new List <Exception>(); var properties = typeof(T).GetTypeInfo().GetProperties().Where( p => p.GetCustomAttributes <VerbAttribute>().Any()); foreach (var prop in properties) { integrityExceptions.Add(VerbMustHaveFactoryDefined(prop, factory)); } integrityExceptions.Add(CannotDefineDuplicateVerbs <T>()); integrityExceptions = integrityExceptions .Where(e => e != null).ToList(); if (integrityExceptions.Any()) { throw new Utils.AggregateException(integrityExceptions); } }
public AttributeParserConfig(ParserOptions options, IEnumerable <ITerminatingTrigger> triggers, IVerbFactory factory) : base(options, triggers, factory) { InitializeVerbs(); InitializeNamedArguments(); InitializePostParseMethods(); InitializePositionalArguments(); InitializeRequiredNamedArguments(); InitializeRequiredMutuallyExclusiveArguments(); }
public FluentParserConfig(ParserOptions options, IEnumerable <ITerminatingTrigger> triggers, IVerbFactory factory) : base(options, triggers, factory) { PendingNamedArguments = new List <NamedArgument>(); /* * CliParser<Config> * .HasNamedOption(c => c.Verbose) * .WithLongName("verb") * .WithShortName() // lower case v by defaults * .And * .HasPositionalOption(c => c.OutputFile) * .HasMetaVar("out") * .HasDescription("Some text.") * .IsInMutuallyExclusiveGroup("grp") * .Consumes.AtMost(10) // .AtLeast .Exactly * .StoresValue(new object()) * .AppendsValue() * .AppendsValue("something") * .CountsInvocations() * .StoresTrue() * .StoresFalse() * .And * .HasVerb("add", c => c.AddInfo) * */ }
public VerbParserConfig(IParserConfig internalParserConfig, IValueStoreDefinition store, ParserOptions options, IVerbFactory factory, string[] precursorVerbs) : base(options, null, factory) { InternalParserConfig = internalParserConfig; Store = store; LongNameArguments = InternalParserConfig.LongNameArguments; ShortNameArguments = InternalParserConfig.ShortNameArguments; PositionalArguments = InternalParserConfig.PositionalArguments; Verbs = InternalParserConfig.Verbs; PostParseMethods = InternalParserConfig.PostParseMethods; RequiredMutuallyExclusiveArguments = InternalParserConfig.RequiredMutuallyExclusiveArguments; RequiredNamedArguments = InternalParserConfig.RequiredNamedArguments; PrecursorVerbs = precursorVerbs; }
/// <summary> /// Configure a custom IOC container for resolving verbs. /// </summary> /// <param name="factory"></param> /// <returns></returns> public CliParserBuilder <TConf> HasVerbFactory(IVerbFactory factory) { FluentConfig.VerbFactory = factory; return(this); }