Esempio n. 1
0
        public void WriteUsageOptions(TextWriter output)
        {
            var anyShortOptions     = AllOptions.OfType <Option>().Any(o => o.ShortNameForUsage.Length > 0);
            var maxOptionNameLength = AllOptions.OfType <Option>().Max(o => o.NameForUsage.Length);

            var             formatter   = new FixedWidthFormatProvider();
            Action <Option> writeOption = o => {
                output.Write("  ");
                if (anyShortOptions)
                {
                    output.Write(string.Format(formatter, "{0:2}", o.ShortNameForUsage));
                    if (o.NameForUsage.Length > 0)
                    {
                        output.Write(o.ShortNameForUsage.Length > 0 ? "," : " ");
                    }
                }
                output.WriteLine(string.Format(formatter, " {0:" + maxOptionNameLength + "} {1}", o.NameForUsage, o.DescriptionForUsage));
            };

            var describedArguments = AllOptions
                                     .OfType <Argument>()
                                     .Where(a => a.DescriptionForUsage.Length > 0)
                                     .Select(a => a.DescriptionForUsage);

            if (describedArguments.Any())
            {
                output.WriteLine();
                describedArguments.Each(output.WriteLine);
            }

            if (Options.OfType <Option>().Any())
            {
                output.WriteLine();
                Options.OfType <Option>().Each(writeOption);
            }

            groups
            .Each(g => {
                output.WriteLine();
                output.WriteLine("{0}:", g.Key);
                g.Value.Options.OfType <Option>().Each(writeOption);
            });
        }
Esempio n. 2
0
        public void WriteUsageHeader(TextWriter output)
        {
            var applicationName = Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName);

            output.Write("Usage: {0} [OPTION]...", applicationName);
            output.Write(
                AllOptions
                .OfType <Argument>()
                .OrderByDescending(a => a.Required)
                .Select(a => a.Required ? a.Name : string.Format("[{0}]", a.Name) + (a.SupportsMultipleValues ? " ..." : ""))
                .Aggregate("", (acc, a) => acc + " " + a)
                );
            output.WriteLine();

            if (string.IsNullOrEmpty(Header))
            {
                return;
            }
            output.WriteLine();
            output.WriteLine(Header);
        }