public OptionSet Add(string prototype, string description, Action <string> action, bool hidden) { if (action == null) { throw new ArgumentNullException(nameof(action)); } string[] names = prototype.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); int? mainId = null; foreach (var name in names) { int id = nextOptionId++; if (name.EndsWith("=")) { builder.AddJoined(id, "-", name, helpText: description, aliasId: mainId); } else { builder.AddFlag(id, "-", name, helpText: description, aliasId: mainId); } mainId = mainId ?? id; actions.Add(id, Tuple.Create(action)); } return(this); }
public void AddFlag(int id, string prefix, string name, string helpText) { var opt = builder.AddFlag(id, prefix, name, helpText).CreateTable().GetOption(1); Assert.Equal(id, opt.Id); Assert.Equal(prefix, opt.Prefix); Assert.Equal(name, opt.Name); Assert.Equal(prefix + name, opt.PrefixedName); Assert.Null(opt.Alias); //Assert.Equal(helpText, opt.HelpText); }
private static IEnumerable <Option> GetOptions() { var builder = new OptTableBuilder(); EmcOptTable.AddOptions(builder); builder .AddFlag(ExtOpt.cuse_prefix, "-", "cuse-prefix", "Use a prefix for generated logging functions", groupId: Opt.G_group) .AddJoined(ExtOpt.cprefix_eq, "-", "cprefix:", "Prefix for generated logging functions", groupId: Opt.G_group) .AddJoined(ExtOpt.clog_ns_eq, "-", "clog-ns:", "Namespace where generated code is placed. Use '.' as separator (e.g. Company.Product.Tracing)", groupId: Opt.G_group) .AddJoined(ExtOpt.cetw_ns_eq, "-", "cetw-ns:", "Namespace where common ETW code is placed. Use '.' as separator (e.g. Company.Product.ETW)", groupId: Opt.G_group) .AddFlag(ExtOpt.cdefines, "-", "cdefines", "Generate code definitions for non-essential resources", groupId: Opt.G_group) .AddFlag(ExtOpt.cno_defines, "-", "cno-defines", "Do not generate definitions", groupId: Opt.G_group); return(builder.GetList()); }
private OptTable ReflectOptTable(Type optionType) { if (optionType is null) { return(null); } int optIdx = 0; var groupId = Opt.custom + optIdx++; var builder = new OptTableBuilder() .AddUnknown(Opt.Unknown) .AddGroup(groupId, name, helpText: $"CodeGen Options (Generator {name})"); foreach (var property in optionType.GetTypeInfo().DeclaredProperties) { var optionAttribute = property.GetCustomAttributes <OptionAttribute>().FirstOrDefault(); if (optionAttribute is null) { continue; } var helpText = optionAttribute.HelpText ?? optionAttribute.Name; var optionId = Opt.custom + optIdx++; switch (optionAttribute) { case JoinedOptionAttribute x: builder.AddJoined(optionId, "-", $"c{optionAttribute.Name}:", helpText: helpText, groupId: groupId); infos.Add(new JoinedOptionInfo(x, optionId, property)); break; case FlagOptionAttribute x: builder.AddFlag(optionId, "-", $"c{optionAttribute.Name}", helpText: helpText, groupId: groupId); infos.Add(new FlagOptionInfo(x, optionId, property)); break; } } return(builder.CreateTable()); }