예제 #1
0
        private void SealOptTable()
        {
            if (IsSealed)
            {
                return;
            }

            optTable = builder.CreateTable();
            IsSealed = true;
        }
예제 #2
0
        public List <string> Parse(IReadOnlyList <string> arguments)
        {
            var optTable = builder.CreateTable();

            IArgumentList al = optTable.ParseArgs(arguments, out _);

            foreach (var arg in al)
            {
                if (!actions.TryGetValue(arg.Option.Id, out var tuple))
                {
                    continue;
                }

                tuple.Item1(arg.Value);
            }

            return(al.Matching(UnknownId).Select(a => a.Value).ToList());
        }
예제 #3
0
            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());
            }