Exemplo n.º 1
0
            public void PrintHelp()
            {
                PrintInformation();
                Console.WriteLine();

                if (Commands.Any())
                {
                    var groups = Commands.GroupBy(c => c.Category).ToArray();

                    foreach (var group in groups)
                    {
                        ConsoleEx.WriteLine(ConsoleColor.Cyan, "{0}Commands:", group.Key.IsNullOrWhiteSpace() ? "" : group.Key + " ");

                        foreach (var command in group)
                        {
                            command.PrintSummary("    ");
                        }

                        Console.WriteLine();
                    }
                }

                if (Examples.Any())
                {
                    ConsoleEx.WriteLine(ConsoleColor.Cyan, "Examples:");
                    foreach (var example in Examples)
                    {
                        example.PrintHelp("    ");
                        Console.WriteLine();
                    }
                }
            }
Exemplo n.º 2
0
        /// <summary>Prints a help message describing the effects of all available options.</summary>
        /// <param name="errorMessage">Optional error message to display.</param>
        public void PrintHelp(string errorMessage = null)
        {
            string argList = string.Join(" ", Arguments.OrderBy(k => k.Key).Select(a => ArgumentToArgList(a.Key, a.Value)));

            OutputWriter.WriteLine(ApplicationInfo);
            OutputWriter.WriteLine();
            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                OutputWriter.WriteLine(errorMessage);
                OutputWriter.WriteLine();
            }
            OutputWriter.WriteLine("Usage:");
            OutputWriter.WriteLine("{0} {1}", ExecuteableName, argList);

            foreach (KeyValuePair <string, Argument> kvp in Arguments.OrderBy(k => k.Key))
            {
                OutputWriter.WriteLine();
                OutputWriter.WriteLine("{0,-10}{1}", kvp.Key, kvp.Value.HelpMessage);
                OutputWriter.WriteLine("{0,-10}{1}", "", GetArgumentInfo(kvp.Value));
            }

            if (Examples.Any())
            {
                OutputWriter.WriteLine();
                OutputWriter.WriteLine("Examples:");

                foreach (KeyValuePair <string, string> kvp in Examples.OrderBy(k => k.Key))
                {
                    OutputWriter.WriteLine();
                    OutputWriter.WriteLine(kvp.Key);
                    OutputWriter.WriteLine(kvp.Value);
                }
            }
        }
Exemplo n.º 3
0
        public void ShowHelp(TextWriter tw)
        {
            if (!string.IsNullOrEmpty(Description))
            {
                tw.WriteLine(Description);
                tw.WriteLine();
            }

            ShowHelp(tw, Parameters, 0);

            if (Examples.Any())
            {
                tw.WriteLine("Examples:");

                foreach (var example in Examples)
                {
                    tw.WriteLine();

                    if (!string.IsNullOrEmpty(ProgramName))
                    {
                        tw.Write("{0} ", ProgramName);
                    }

                    tw.WriteLine(string.Join(" ", example.Parameters.Select(parameter => ToString(parameter))));
                    tw.WriteLine("\t{0}", example.Description);
                }
            }
        }
Exemplo n.º 4
0
        bool AnyUnfilteredExampleInSubTree(nspec nspec)
        {
            Func <ExampleBase, bool> shouldNotSkip = e => e.ShouldNotSkip(nspec.tagsFilter);

            bool anyExampleOrSubExample = Examples.Any(shouldNotSkip) || Contexts.Examples().Any(shouldNotSkip);

            return(anyExampleOrSubExample);
        }
Exemplo n.º 5
0
            public void PrintHelp()
            {
                PrintSummary("");
                Console.WriteLine();

                if (Description.IsNotNullOrWhiteSpace())
                {
                    ConsoleEx.WriteLine(ConsoleColor.DarkGray, Description ?? "");
                    Console.WriteLine();
                }

                if (Examples.Any())
                {
                    ConsoleEx.WriteLine(ConsoleColor.Cyan, "Examples:");
                    foreach (var example in Examples)
                    {
                        example.PrintHelp("    ");
                        Console.WriteLine();
                    }
                }
            }
Exemplo n.º 6
0
            public void PrintHelp()
            {
                // TODO: HelpFlags with ShowExamples, FullHelp, etc.
                ConsoleEx.Write(ConsoleColor.White, "{0,-20}\t", AllNames);
                ConsoleEx.WriteLine(ConsoleColor.Gray, Caption ?? "");
                Console.WriteLine();

                ConsoleEx.Write(ConsoleColor.Cyan, "Usage: ");
                ConsoleEx.Write(ConsoleColor.White, Names[0]);

                foreach (var param in Parameters)
                {
                    Console.Write(" ");

                    Console.Write(param.IsRequired ? "(" : "[");

                    switch (param.ParameterType)
                    {
                    case ReplParameterType.Flag:
                    case ReplParameterType.Option:
                        ConsoleEx.Write(ConsoleColor.White, AsOptionName(param.Names[0]));
                        break;
                    }

                    switch (param.ParameterType)
                    {
                    case ReplParameterType.Option:
                        Console.Write(" {0}", param.TypeName ?? "value");
                        break;

                    case ReplParameterType.Positional:
                        Console.Write("{0}", param.TypeName ?? "value");
                        break;
                    }

                    Console.Write(param.IsRequired ? ")" : "]");
                    Console.Write(param.IsRepeated ? "*" : "");
                }

                Console.WriteLine();
                Console.WriteLine();

                if (Description.IsNotNullOrWhiteSpace())
                {
                    ConsoleEx.WriteLine(ConsoleColor.DarkGray, Description ?? "");
                    Console.WriteLine();
                }

                if (Parameters.Any())
                {
                    ConsoleEx.WriteLine(ConsoleColor.Cyan, "Options:");

                    foreach (var param in Parameters)
                    {
                        param.PrintSummary("    ");
                    }

                    Console.WriteLine();
                }

                if (Examples.Any())
                {
                    ConsoleEx.WriteLine(ConsoleColor.Cyan, "Examples:");
                    foreach (var example in Examples)
                    {
                        example.PrintHelp("    ");
                        Console.WriteLine();
                    }
                }
            }