public static void Customize(this HelpBuilder helpBuilder,
                              IOption option,
                              string?descriptor   = null,
                              string?defaultValue = null)
 {
     helpBuilder.Customize(option, () => descriptor, () => defaultValue);
 }
 public static void Customize(this HelpBuilder helpBuilder,
                              IArgument argument,
                              string?descriptor   = null,
                              string?defaultValue = null)
 {
     helpBuilder.Customize(argument, () => descriptor, () => defaultValue);
 }
 public static void Customize(
     this HelpBuilder helpBuilder,
     ICommand command,
     string?descriptor = null
     )
 {
     helpBuilder.Customize(command, () => descriptor);
 }
Esempio n. 4
0
 private static void SetHelpCustomizations(HelpBuilder builder)
 {
     foreach (var option in HelpDescriptionCustomizations.Keys)
     {
         Func <ParseResult, string> descriptionCallback = (ParseResult parseResult) =>
         {
             foreach (var(command, helpText) in HelpDescriptionCustomizations[option])
             {
                 if (parseResult.CommandResult.Command.Equals(command))
                 {
                     return(helpText);
                 }
             }
             return(null);
         };
         builder.Customize(option, secondColumnText: descriptionCallback);
     }
            public void Option_can_customize_left_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.Customize(option, secondColumnText: parseResult =>
                                      parseResult.CommandResult.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}");
            }