Exemplo n.º 1
0
            public void Argument_can_fallback_to_default_when_customizing(
                bool conditionA,
                bool conditionB,
                bool conditionC,
                string expected)
            {
                var command  = new Command("test");
                var argument = new Argument <string>("arg", "description");

                argument.SetDefaultValue("default");

                command.AddArgument(argument);

                var helpBuilder = new HelpBuilder(LocalizationResources.Instance, LargeMaxWidth);

                helpBuilder.CustomizeSymbol(argument,
                                            firstColumnText: ctx => conditionA ? "custom 1st" : HelpBuilder.Default.GetArgumentUsageLabel(argument),
                                            secondColumnText: ctx => conditionB ? "custom 2nd" : HelpBuilder.Default.GetArgumentDescription(argument),
                                            defaultValue: ctx => conditionC ? "custom def" : HelpBuilder.Default.GetArgumentDefaultValue(argument));


                var parser = new CommandLineBuilder(command)
                             .UseDefaults()
                             .UseHelpBuilder(_ => helpBuilder)
                             .Build();

                var console = new TestConsole();

                parser.Invoke("test -h", console);
                console.Out.ToString().Should().MatchRegex(expected);
            }
Exemplo n.º 2
0
Arquivo: Parser.cs Projeto: nohwnd/sdk
 private static void SetHelpCustomizations(HelpBuilder builder)
 {
     foreach (var option in HelpDescriptionCustomizations.Keys)
     {
         Func <HelpContext, string> descriptionCallback = (HelpContext context) =>
         {
             foreach (var(command, helpText) in HelpDescriptionCustomizations[option])
             {
                 if (context.ParseResult.CommandResult.Command.Equals(command))
                 {
                     return(helpText);
                 }
             }
             return(null);
         };
         builder.CustomizeSymbol(option, secondColumnText: descriptionCallback);
     }
Exemplo n.º 3
0
            public void Option_can_customize_second_column_text_based_on_parse_result()
            {
                var option   = new Option <bool>("option");
                var commandA = new Command("a", "a command help")
                {
                    option
                };
                var commandB = new Command("b", "b command help")
                {
                    option
                };
                var command = new Command("root", "root command help")
                {
                    commandA, commandB
                };
                var optionADescription = "option a help";
                var optionBDescription = "option b help";

                var helpBuilder = new HelpBuilder(LocalizationResources.Instance, LargeMaxWidth);

                helpBuilder.CustomizeSymbol(option, secondColumnText: ctx =>
                                            ctx.Command.Equals(commandA)
                                              ? optionADescription
                                              : optionBDescription);

                var parser = new CommandLineBuilder(command)
                             .UseDefaults()
                             .UseHelpBuilder(_ => helpBuilder)
                             .Build();

                var console = new TestConsole();

                parser.Invoke("root a -h", console);
                console.Out.ToString().Should().Contain($"option          {optionADescription}");

                console = new TestConsole();
                parser.Invoke("root b -h", console);
                console.Out.ToString().Should().Contain($"option          {optionBDescription}");
            }
Exemplo n.º 4
0
            public void Option_can_fallback_to_default_when_customizing(bool conditionA, bool conditionB, string expected)
            {
                var command = new Command("test");
                var option  = new Option <string>("--option", "description");

                command.AddOption(option);

                var helpBuilder = new HelpBuilder(LocalizationResources.Instance, LargeMaxWidth);

                helpBuilder.CustomizeSymbol(option,
                                            firstColumnText: ctx => conditionA ? "custom 1st" : HelpBuilder.Default.GetIdentifierSymbolUsageLabel(option, ctx),
                                            secondColumnText: ctx => conditionB ? "custom 2nd" : HelpBuilder.Default.GetIdentifierSymbolDescription(option));


                var parser = new CommandLineBuilder(command)
                             .UseDefaults()
                             .UseHelpBuilder(_ => helpBuilder)
                             .Build();

                var console = new TestConsole();

                parser.Invoke("test -h", console);
                console.Out.ToString().Should().MatchRegex(expected);
            }