예제 #1
0
 private void CheckCategory(Option p, string f, string n)
 {
     if (currentCategory == OptionCategory.None)
     {
         currentCategory = p.Category;
     }
     else if (p.Category.HasFlag(currentCategory) || currentCategory.HasFlag(p.Category) || p.Category == OptionCategory.None)
     {
         currentCategory |= p.Category;
     }
     else
     {
         var category = currentCategory;
         category &= ~OptionCategory.None;
         throw new InvalidOperationException(string.Format("Cannot use options from different category. Current category: '{0}'. Invalid option: '{1}' from category '{2}'.", category, f + n, p.Category));
     }
 }
예제 #2
0
        private void CheckCategory(Option p, string f, string n)
        {
            if (currentCategory == OptionCategory.None)
            {
                currentCategory = p.Category;
            }
            else if (p.Category.HasFlag(currentCategory) || currentCategory.HasFlag(p.Category) || p.Category == OptionCategory.None)
            {
                currentCategory |= p.Category;
            }
            else
            {
                var category = currentCategory;
                category &= ~OptionCategory.None;

                OnWarning(string.Format("Cannot use options from different category. Current category: '{0}'. Invalid option: '{1}' from category '{2}'. Using option from different category might cause unpredictable actions.", category, f + n, p.Category));
            }
        }
예제 #3
0
        public void WriteOptionDescriptions(TextWriter o)
        {
            var allCategories = Enum.GetValues(typeof(OptionCategory));
            var results       = new Dictionary <OptionCategory, List <Option> >();

            foreach (OptionCategory category in allCategories)
            {
                foreach (Option p in this)
                {
                    if (!p.Category.HasFlag(category))
                    {
                        continue;
                    }

                    if (results.ContainsKey(category) == false)
                    {
                        results[category] = new List <Option>();
                    }

                    results[category].Add(p);
                }
            }

            foreach (var key in results.Keys)
            {
                if (currentCategory.HasFlag(key) == false && currentCategory != OptionCategory.None && currentCategory != OptionCategory.Help && key != OptionCategory.Help && key != OptionCategory.None)
                {
                    continue;
                }

                var options = results[key];
                if (options.Count == 0)
                {
                    continue;
                }

                o.WriteLine();
                o.WriteLine("----------------------------------------------");
                o.WriteLine(GetDescription(key));
                o.WriteLine("----------------------------------------------");
                o.WriteLine();

                foreach (Option p in options)
                {
                    int written = 0;
                    if (!WriteOptionPrototype(o, p, ref written))
                    {
                        continue;
                    }

                    if (written < OptionWidth)
                    {
                        o.Write(new string(' ', OptionWidth - written));
                    }
                    else
                    {
                        o.WriteLine();
                        o.Write(new string(' ', OptionWidth));
                    }

                    List <string> lines = GetLines(localizer(GetDescription(p.Description)));
                    o.WriteLine(lines[0]);
                    string prefix = new string(' ', OptionWidth + 2);
                    for (int i = 1; i < lines.Count; ++i)
                    {
                        o.Write(prefix);
                        o.WriteLine(lines[i]);
                    }
                }
            }
        }