コード例 #1
0
        private static OptionsCollection ParseDefault(string text)
        {
            var result = new OptionsCollection();
            var lines  = text.SplitToLines();

            if (lines.Length == 0)
            {
                return(result);
            }
            var splitColumn = lines.GetSplitColumn();

            OptionsCollectionValue value = null;

            foreach (var line in lines)
            {
                var optionNames = line.Substring(0, splitColumn).Trim();
                var description = line.Substring(splitColumn).Trim();
                if (string.IsNullOrEmpty(optionNames))
                {
                    if (value is null)
                    {
                        throw new Exception("Description without command");
                    }
                    value.Description = value.Description.AppendText(description);
                    continue;
                }

                value = new OptionsCollectionValue
                {
                    Description = description
                };
                var commaSeparatedParts = optionNames.Split(',');
                foreach (var option in commaSeparatedParts)
                {
                    value.UpdateFromParsedOption(option, ParserKind.Default);
                }

                result.Values.Add(value);
            }

            {
                var optionToItem = result.GetMap();
                foreach (var option1 in result.Values)
                {
                    var enumerable = IncompatibleOptions.Parse(option1.Description);
                    foreach (var option2 in enumerable)
                    {
                        var q = optionToItem[option2];
                        result.AddConflict(option1.AnyWithMinus, q.AnyWithMinus);
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        private static OptionsCollection ParseStyle1(string text)
        {
            var result = new OptionsCollection();
            var lines  = text.SplitToLines();

            if (lines.Length == 0)
            {
                return(result);
            }

            OptionsCollectionValue value = null;

            foreach (var line in lines)
            {
                var n = line.Trim();
                if (!n.StartsWith('-'))
                {
                    if (value is null)
                    {
                        throw new Exception("Description without command");
                    }
                    value.Description = value.Description.AppendText(n);
                    continue;
                }

                value = new OptionsCollectionValue();
                var slashSeparatedParts = n.Split('/');
                foreach (var option in slashSeparatedParts)
                {
                    value.UpdateFromParsedOption(option, ParserKind.Style1);
                }

                result.Values.Add(value);
            }

            {
                var optionToItem = result.GetMap();
                foreach (var option1 in result.Values)
                {
                    var enumerable = IncompatibleOptions.Parse(option1.Description);
                    foreach (var option2 in enumerable)
                    {
                        var q = optionToItem[option2];
                        result.AddConflict(option1.AnyWithMinus, q.AnyWithMinus);
                    }
                }
            }

            return(result);
        }