Ejemplo n.º 1
0
        public void Show(HelpFormatting formatting = HelpFormatting.Default)
        {
            if (!string.IsNullOrEmpty(Title))
            {
                Console.WriteLine(Title);
                if (formatting.HasFlag(HelpFormatting.TitleUnderlines))
                {
                    for (int i = 0; i < Title.Length; i++)
                    {
                        Console.Write('¨');
                    }
                    Console.Write(Environment.NewLine);
                }
            }

            bool   indent  = !string.IsNullOrEmpty(Title);
            string indents = "  ";

            for (int i = 0; i < Body.Length; i++)
            {
                if (indent)
                {
                    Console.Write(indents);
                }
                string[] words = Body[i].Split(' ');
                for (int j = 0; j < words.Length; j++)
                {
                    if (words[j].Length > Console.BufferWidth - Console.CursorLeft)
                    {
                        Console.Write(Environment.NewLine);
                        Console.Write(indents);
                    }

                    Console.Write(words[j]);
                    if (j != words.Length - 1)
                    {
                        Console.Write(' ');
                    }
                }
                if (i != Body.Length - 1)
                {
                    Console.Write(Environment.NewLine + Environment.NewLine);
                }
            }
        }
Ejemplo n.º 2
0
        public void ShowManual(HelpFormatting formatting = HelpFormatting.Default)
        {
            // Title
            Console.Write($"{appName} Command Line");
            if (formatting.HasFlag(HelpFormatting.ShowVersion))
            {
                Console.Write($" {assemblyVersion}");
            }
            Console.Write(Environment.NewLine + Environment.NewLine);

            // Usage
            Console.Write($"Usage: {assemblyName} ");
            if (options != null)
            {
                Console.Write(!optionRequired ? "(options) " : "[options] ");
            }
            if (commands != null)
            {
                Console.Write(!commandRequired ? "(commands)" : "[commands]");
            }
            Console.Write(Environment.NewLine + Environment.NewLine);

            // Options
            if (options != null)
            {
                int indention = GetNeededIndent(options);

                Console.WriteLine($"Options:");
                if (formatting.HasFlag(HelpFormatting.TitleUnderlines))
                {
                    Console.WriteLine("¨¨¨¨¨¨¨¨");
                }
                for (int i = 0; i < options.Count; i++)
                {
                    string usage = options[i].GetManualUsage(keyChar);
                    Console.Write($"  {usage}");

                    for (int j = 0; j < indention - GetOptionSize(options[i]); j++)
                    {
                        Console.Write(' ');
                    }

                    if (options[i].Description != null)
                    {
                        Console.Write(options[i].Description);
                    }
                    Console.Write(Environment.NewLine);
                }
                Console.Write(Environment.NewLine);
            }

            // Commands
            if (commands != null)
            {
                int indention = GetNeededIndent(commands) + 2;

                Console.WriteLine($"Commands:");
                if (formatting.HasFlag(HelpFormatting.TitleUnderlines))
                {
                    Console.WriteLine("¨¨¨¨¨¨¨¨¨");
                }
                for (int i = 0; i < commands.Count; i++)
                {
                    string usage = $"{commands[i].Name}";
                    Console.Write($"  {usage}");

                    for (int j = 0; j < indention - GetCommandSize(commands[i]); j++)
                    {
                        Console.Write(' ');
                    }

                    if (commands[i].Description != null)
                    {
                        Console.Write(commands[i].Description);
                    }
                    Console.Write(Environment.NewLine);
                }
            }

            if (texts != null)
            {
                for (int i = 0; i < texts.Count; i++)
                {
                    Console.WriteLine();
                    texts[i].Show(formatting);
                }
            }
        }