コード例 #1
0
        private IReadOnlyList <Section> GenerateSections(ArgumentSetUsageInfo info)
        {
            var sections = new List <Section>();

            if (Options.HasFlag(UsageInfoOptions.IncludeLogo) &&
                info.Logo != null && !info.Logo.IsEmpty())
            {
                sections.Add(new Section(null, info.Logo)
                {
                    BodyIndentWidth = 0
                });
            }

            // Append basic usage info.
            if (Options.HasFlag(UsageInfoOptions.IncludeBasicSyntax))
            {
                var basicSyntax = new ColoredString[]
                {
                    new ColoredString(info.Name, NameForegroundColor),
                    " ",
                    info.GetBasicSyntax(includeOptionalParameters: true)
                };

                sections.Add(new Section(Strings.UsageInfoUsageHeader + ":", new[] { new ColoredMultistring(basicSyntax) })
                {
                    BodyIndentWidth    = Section.DefaultIndent * 3 / 2,
                    HangingIndentWidth = Section.DefaultIndent / 2
                });
            }

            if (Options.HasFlag(UsageInfoOptions.IncludeDescription) && !string.IsNullOrEmpty(info.Description))
            {
                sections.Add(new Section(null, info.Description));
            }

            // If needed, get help info for enum values.
            IReadOnlyDictionary <ArgumentUsageInfo, List <IEnumArgumentType> > inlineDocumented = null;
            IEnumerable <IEnumArgumentType> separatelyDocumented = null;

            if (Options.HasFlag(UsageInfoOptions.IncludeEnumValues))
            {
                GetEnumsToDocument(info, out inlineDocumented, out separatelyDocumented);
            }

            // If desired (and present), append "REQUIRED PARAMETERS" section.
            if (Options.HasFlag(UsageInfoOptions.IncludeRequiredParameterDescriptions) &&
                info.RequiredParameters.Any())
            {
                var entries = GetParameterEntries(info.RequiredParameters, info, inlineDocumented).ToList();
                if (entries.Count > 0)
                {
                    sections.Add(new Section(Strings.UsageInfoRequiredParametersHeader + ":", entries)
                    {
                        BodyIndentWidth    = Section.DefaultIndent * 3 / 2,
                        HangingIndentWidth = Section.DefaultIndent / 2
                    });
                }
            }

            // If desired (and present), append "OPTIONAL PARAMETERS" section.
            if (Options.HasFlag(UsageInfoOptions.IncludeOptionalParameterDescriptions) &&
                info.OptionalParameters.Any())
            {
                var entries = GetParameterEntries(info.OptionalParameters, info, inlineDocumented).ToList();
                if (entries.Count > 0)
                {
                    sections.Add(new Section(Strings.UsageInfoOptionalParametersHeader + ":", entries)
                    {
                        BodyIndentWidth    = Section.DefaultIndent * 3 / 2,
                        HangingIndentWidth = Section.DefaultIndent / 2
                    });
                }
            }

            // If needed, provide help for shared enum values.
            if (separatelyDocumented != null)
            {
                foreach (var enumType in separatelyDocumented)
                {
                    sections.Add(new Section(
                                     string.Format(Strings.UsageInfoEnumValueHeaderFormat, enumType.DisplayName),
                                     GetEnumValueEntries(enumType))
                    {
                        BodyIndentWidth    = Section.DefaultIndent * 3 / 2,
                        HangingIndentWidth = Section.DefaultIndent / 2
                    });
                }
            }

            // If present, append "EXAMPLES" section.
            if (Options.HasFlag(UsageInfoOptions.IncludeExamples) && info.Examples.Any())
            {
                sections.Add(new Section(Strings.UsageInfoExamplesHeader + ":", info.Examples));
            }

            // If requested, display remarks
            if (Options.HasFlag(UsageInfoOptions.IncludeRemarks) && !string.IsNullOrEmpty(info.Remarks))
            {
                sections.Add(new Section(Strings.UsageInfoRemarksHeader + ":", info.Remarks));
            }

            return(sections);
        }
コード例 #2
0
        private IReadOnlyList <Section> GenerateSections(ArgumentSetUsageInfo info)
        {
            var sections = new List <Section>();

            // If requested, add a "logo" for the program.
            if (Options.HasFlag(UsageInfoOptions.IncludeLogo) &&
                info.Logo != null && !info.Logo.IsEmpty())
            {
                sections.Add(new Section(null, info.Logo));
            }

            // Append the "NAME" section: lists the program name.
            if (Options.HasFlag(UsageInfoOptions.IncludeName))
            {
                sections.Add(new Section(Strings.UsageInfoNameHeader.ToUpper(), info.Name));
            }

            // Append the "SYNTAX" section: describes the basic syntax.
            if (Options.HasFlag(UsageInfoOptions.IncludeBasicSyntax))
            {
                sections.Add(new Section(Strings.UsageInfoSyntaxHeader.ToUpper(), info.Name + " " + info.GetBasicSyntax()));
            }

            // If present (and if requested), display the "DESCRIPTION" for the
            // program here.
            if (Options.HasFlag(UsageInfoOptions.IncludeDescription) && !string.IsNullOrEmpty(info.Description))
            {
                sections.Add(new Section(Strings.UsageInfoDescriptionHeader.ToUpper(), info.Description));
            }

            // If desired (and present), append "REQUIRED PARAMETERS" section.
            if (Options.HasFlag(UsageInfoOptions.IncludeRequiredParameterDescriptions) &&
                info.RequiredParameters.Any())
            {
                var entries = GetParameterEntries(info.RequiredParameters, info);
                sections.Add(new Section(Strings.UsageInfoRequiredParametersHeader.ToUpper(), entries));
            }

            // If desired (and present), append "OPTIONAL PARAMETERS" section.
            if (Options.HasFlag(UsageInfoOptions.IncludeOptionalParameterDescriptions) &&
                info.OptionalParameters.Any())
            {
                var entries = GetParameterEntries(info.OptionalParameters, info);
                sections.Add(new Section(Strings.UsageInfoOptionalParametersHeader.ToUpper(), entries));
            }

            // If present, append "EXAMPLES" section.
            if (Options.HasFlag(UsageInfoOptions.IncludeExamples) && info.Examples.Any())
            {
                sections.Add(new Section(Strings.UsageInfoExamplesHeader.ToUpper(), info.Examples));
            }

            // If requested, display remarks
            if (Options.HasFlag(UsageInfoOptions.IncludeRemarks) && !string.IsNullOrEmpty(info.Remarks))
            {
                sections.Add(new Section(Strings.UsageInfoRemarksHeader.ToUpper(), info.Remarks));
            }

            return(sections);
        }