示例#1
0
        public void WriteHelp(ConsoleColor emphasisColor = ConsoleColor.White)
        {
            var doc       = new CommandLineDocumentation();
            var processor = GetCommandLineProcessor();

            processor.WriteDocumentation(doc);

            WriteHelp(doc, emphasisColor);
        }
示例#2
0
        public void WriteHelp([NotNull] CommandLineDocumentation documentation, ConsoleColor emphasisColor = ConsoleColor.White)
        {
            if (documentation == null)
            {
                throw new ArgumentNullException(nameof(documentation));
            }

            var writer = new ConsoleWriter {
                IncludeScope = false
            };

            var names             = documentation.GetSortedTokens().OfType <CommandLineNamedTokenDocumentation>().ToArray();
            var shortDescriptions = names.Where(x => !string.IsNullOrWhiteSpace(x.ShortDescription)).ToArray();

            using (WithColor(emphasisColor))
            {
                Console.WriteLine("Usage");
            }

            var bufferWidth = GetAvailableBufferWidth();

            Console.WriteLine($"   {Metadata.ModuleName} {documentation}".WordWrap(bufferWidth, new string(' ', 3), ""));

            if (shortDescriptions.Any())
            {
                using (WithColor(emphasisColor))
                {
                    Console.WriteLine();
                    Console.WriteLine("Available command line parameters");
                    Console.WriteLine();
                }

                var padWidth = shortDescriptions.Max(x => GetTokenLabel(x).Length) + 2;

                foreach (var token in shortDescriptions)
                {
                    var label = GetTokenLabel(token).PadRight(padWidth);
                    writer.WriteInformation($"   {label}{token.ShortDescription}".WordWrap(bufferWidth, new string(' ', padWidth + 3), ""));
                }
            }

            var descriptions = names.Where(x => !string.IsNullOrWhiteSpace(x.Description)).ToArray();

            if (descriptions.Any())
            {
                using (WithColor(emphasisColor))
                {
                    Console.WriteLine();
                    Console.WriteLine("Parameter descriptions");
                    Console.WriteLine();
                }

                foreach (var token in descriptions)
                {
                    var label = token.Name;

                    using (WithColor(emphasisColor))
                    {
                        Console.WriteLine($"   {label}");
                    }

                    writer.WriteInformation(token.Description.WordWrap(bufferWidth, "      "));
                    Console.WriteLine();
                }
            }
        }