mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Make HelpProvider colors configurable (#1408)
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
namespace Spectre.Console.Cli.Tests.Data.Help;
|
||||
|
||||
internal class RenderMarkupHelpProvider : HelpProvider
|
||||
{
|
||||
protected override bool RenderMarkupInline { get; } = true;
|
||||
|
||||
public RenderMarkupHelpProvider(ICommandAppSettings settings)
|
||||
: base(settings)
|
||||
{
|
||||
}
|
||||
}
|
@ -14,4 +14,8 @@ public class LionSettings : CatSettings
|
||||
[Description("The days the lion goes hunting.")]
|
||||
[DefaultValue(new[] { DayOfWeek.Monday, DayOfWeek.Thursday })]
|
||||
public DayOfWeek[] HuntDays { get; set; }
|
||||
|
||||
[CommandOption("-w|--weight [WEIGHT]")]
|
||||
[Description("The weight of the lion, in kgs.")]
|
||||
public FlagValue<int?> Weight { get; set; }
|
||||
}
|
||||
|
@ -16,4 +16,5 @@ OPTIONS:
|
||||
-n, --name <VALUE>
|
||||
--agility <VALUE> 10 The agility between 0 and 100
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-w, --weight [WEIGHT] The weight of the lion, in kgs
|
@ -16,4 +16,5 @@ OPTIONS:
|
||||
-n, --name <VALUE>
|
||||
--agility <VALUE> 10 The agility between 0 and 100
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-w, --weight [WEIGHT] The weight of the lion, in kgs
|
@ -20,6 +20,7 @@ OPTIONEN:
|
||||
--agility <VALUE> 10 The agility between 0 and 100
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-w, --weight [WEIGHT] The weight of the lion, in kgs
|
||||
|
||||
KOMMANDOS:
|
||||
giraffe <LENGTH> The giraffe command
|
@ -20,6 +20,7 @@ OPTIONS:
|
||||
--agility <VALUE> 10 The agility between 0 and 100
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-w, --weight [WEIGHT] The weight of the lion, in kgs
|
||||
|
||||
COMMANDS:
|
||||
giraffe <LENGTH> The giraffe command
|
@ -20,6 +20,7 @@ OPTIONS:
|
||||
--agility <VALUE> 10 The agility between 0 and 100
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-w, --weight [WEIGHT] The weight of the lion, in kgs
|
||||
|
||||
COMMANDES:
|
||||
giraffe <LENGTH> The giraffe command
|
@ -20,6 +20,7 @@ VAL:
|
||||
--agility <VALUE> 10 The agility between 0 and 100
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-w, --weight [WEIGHT] The weight of the lion, in kgs
|
||||
|
||||
KOMMANDON:
|
||||
giraffe <LENGTH> The giraffe command
|
@ -0,0 +1,26 @@
|
||||
[bold]DESCRIPTION:[/]
|
||||
The lion command.
|
||||
|
||||
[bold]USAGE:[/]
|
||||
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]
|
||||
|
||||
[bold]EXAMPLES:[/]
|
||||
myapp []20 --alive[/]
|
||||
|
||||
[bold]ARGUMENTS:[/]
|
||||
[]<TEETH>[/] The number of teeth the lion has
|
||||
[][[LEGS]][/] The number of legs
|
||||
|
||||
[]OPTIONS:[/]
|
||||
[]DEFAULT[/]
|
||||
-h, --help Prints help information
|
||||
-v, --version Prints version information
|
||||
-a, --alive Indicates whether or not the animal is alive
|
||||
-n, --name []<VALUE>[/]
|
||||
--agility []<VALUE>[/] []10[/] The agility between 0 and 100
|
||||
-c []<CHILDREN>[/] The number of children the lion has
|
||||
-d []<DAY>[/] []Monday[/], []Thursday[/] The days the lion goes hunting
|
||||
-w, --weight [][[WEIGHT]][/] The weight of the lion, in kgs
|
||||
|
||||
[bold]COMMANDS:[/]
|
||||
[]giraffe[/] []<LENGTH>[/] The giraffe command
|
@ -0,0 +1,26 @@
|
||||
[yellow]DESCRIPTION:[/]
|
||||
The lion command.
|
||||
|
||||
[yellow]USAGE:[/]
|
||||
myapp [aqua]<TEETH>[/] [silver][[LEGS]][/] [grey][[OPTIONS]][/] [aqua][[COMMAND]][/]
|
||||
|
||||
[yellow]EXAMPLES:[/]
|
||||
myapp [grey]20 --alive[/]
|
||||
|
||||
[yellow]ARGUMENTS:[/]
|
||||
[silver]<TEETH>[/] The number of teeth the lion has
|
||||
[silver][[LEGS]][/] The number of legs
|
||||
|
||||
[yellow]OPTIONS:[/]
|
||||
[lime]DEFAULT[/]
|
||||
-h, --help Prints help information
|
||||
-v, --version Prints version information
|
||||
-a, --alive Indicates whether or not the animal is alive
|
||||
-n, --name [silver]<VALUE>[/]
|
||||
--agility [silver]<VALUE>[/] [bold]10[/] The agility between 0 and 100
|
||||
-c [silver]<CHILDREN>[/] The number of children the lion has
|
||||
-d [silver]<DAY>[/] [bold]Monday[/], [bold]Thursday[/] The days the lion goes hunting
|
||||
-w, --weight [grey][[WEIGHT]][/] The weight of the lion, in kgs
|
||||
|
||||
[yellow]COMMANDS:[/]
|
||||
[silver]giraffe[/] [silver]<LENGTH>[/] The giraffe command
|
@ -0,0 +1,26 @@
|
||||
[]DESCRIPTION:[/]
|
||||
The lion command.
|
||||
|
||||
[]USAGE:[/]
|
||||
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]
|
||||
|
||||
[]EXAMPLES:[/]
|
||||
myapp []20 --alive[/]
|
||||
|
||||
[]ARGUMENTS:[/]
|
||||
[]<TEETH>[/] The number of teeth the lion has
|
||||
[][[LEGS]][/] The number of legs
|
||||
|
||||
[]OPTIONS:[/]
|
||||
[]DEFAULT[/]
|
||||
-h, --help Prints help information
|
||||
-v, --version Prints version information
|
||||
-a, --alive Indicates whether or not the animal is alive
|
||||
-n, --name []<VALUE>[/]
|
||||
--agility []<VALUE>[/] []10[/] The agility between 0 and 100
|
||||
-c []<CHILDREN>[/] The number of children the lion has
|
||||
-d []<DAY>[/] []Monday[/], []Thursday[/] The days the lion goes hunting
|
||||
-w, --weight [][[WEIGHT]][/] The weight of the lion, in kgs
|
||||
|
||||
[]COMMANDS:[/]
|
||||
[]giraffe[/] []<LENGTH>[/] The giraffe command
|
@ -1,4 +1,4 @@
|
||||
DESCRIPTION:
|
||||
DESCRIPTION:
|
||||
The lion command.
|
||||
|
||||
USAGE:
|
||||
@ -8,7 +8,8 @@ ARGUMENTS:
|
||||
<TEETH> The number of teeth the lion has
|
||||
|
||||
OPTIONS:
|
||||
DEFAULT
|
||||
-h, --help Prints help information
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
DEFAULT
|
||||
-h, --help Prints help information
|
||||
-c <CHILDREN> The number of children the lion has
|
||||
-d <DAY> Monday, Thursday The days the lion goes hunting
|
||||
-w, --weight [WEIGHT] The weight of the lion, in kgs
|
@ -264,6 +264,101 @@ public sealed partial class CommandAppTests
|
||||
return Verifier.Verify(result.Output, settings).UseTextForParameters(expectationPrefix);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Default_Without_Args_Additional_Style_Default")]
|
||||
public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_Command_Has_Required_Parameters_And_Is_Called_Without_Args_Style_Default()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.SetDefaultCommand<LionCommand>();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
configurator.AddExample("20", "--alive");
|
||||
configurator.AddCommand<GiraffeCommand>("giraffe");
|
||||
configurator.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings));
|
||||
});
|
||||
|
||||
// When
|
||||
var result = fixture.Run();
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Default_Without_Args_Additional_Style_BoldHeadings")]
|
||||
public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_Command_Has_Required_Parameters_And_Is_Called_Without_Args_Style_BoldHeadings()
|
||||
{
|
||||
// Bold headings in the help text
|
||||
var styles = new HelpProviderStyle()
|
||||
{
|
||||
Description = new DescriptionStyle()
|
||||
{
|
||||
Header = "bold",
|
||||
},
|
||||
Usage = new UsageStyle()
|
||||
{
|
||||
Header = "bold",
|
||||
},
|
||||
Examples = new ExampleStyle()
|
||||
{
|
||||
Header = "bold",
|
||||
},
|
||||
Arguments = new ArgumentStyle()
|
||||
{
|
||||
Header = "bold",
|
||||
},
|
||||
Commands = new CommandStyle()
|
||||
{
|
||||
Header = "bold",
|
||||
},
|
||||
|
||||
// Omit OptionStyle to ensure coverage of at least one null style class
|
||||
};
|
||||
|
||||
// Given
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.SetDefaultCommand<LionCommand>();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
configurator.AddExample("20", "--alive");
|
||||
configurator.AddCommand<GiraffeCommand>("giraffe");
|
||||
configurator.Settings.HelpProviderStyles = styles;
|
||||
configurator.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings));
|
||||
});
|
||||
|
||||
// When
|
||||
var result = fixture.Run();
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Default_Without_Args_Additional_Style_None")]
|
||||
public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_Command_Has_Required_Parameters_And_Is_Called_Without_Args_Style_None()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.SetDefaultCommand<LionCommand>();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
configurator.AddExample("20", "--alive");
|
||||
configurator.AddCommand<GiraffeCommand>("giraffe");
|
||||
configurator.Settings.HelpProviderStyles = null;
|
||||
configurator.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings));
|
||||
});
|
||||
|
||||
// When
|
||||
var result = fixture.Run();
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Default_Greeter")]
|
||||
public Task Should_Not_Output_Default_Command_When_Command_Has_No_Required_Parameters_And_Is_Called_Without_Args()
|
||||
|
Reference in New Issue
Block a user