mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-01 01:25:27 +08:00 
			
		
		
		
	Pipe character for listing options - Fully implemented and tested.
This commit is contained in:
		 Frank Ray
					Frank Ray
				
			
				
					committed by
					
						 Patrik Svensson
						Patrik Svensson
					
				
			
			
				
	
			
			
			 Patrik Svensson
						Patrik Svensson
					
				
			
						parent
						
							e66d3aab2e
						
					
				
				
					commit
					43f9ae92ad
				
			| @@ -124,7 +124,7 @@ internal static class TemplateParser | ||||
|                 foreach (var character in token.Value) | ||||
|                 { | ||||
|                     if (!char.IsLetterOrDigit(character) && | ||||
|                         character != '=' && character != '-' && character != '_') | ||||
|                         character != '=' && character != '-' && character != '_' && character != '|') | ||||
|                     { | ||||
|                         throw CommandTemplateException.InvalidCharacterInValueName(template, token, character); | ||||
|                     } | ||||
|   | ||||
| @@ -4,7 +4,7 @@ namespace Spectre.Console.Tests.Data; | ||||
|  | ||||
| public class HorseSettings : MammalSettings | ||||
| { | ||||
|     [CommandOption("-d|--day")] | ||||
|     [CommandOption("-d|--day <Mon|Tue>")] | ||||
|     public DayOfWeek Day { get; set; } | ||||
|  | ||||
|     [CommandOption("--file")] | ||||
|   | ||||
| @@ -0,0 +1,18 @@ | ||||
| DESCRIPTION: | ||||
| The horse command. | ||||
|  | ||||
| USAGE: | ||||
|     myapp horse [LEGS] [OPTIONS] | ||||
|  | ||||
| ARGUMENTS: | ||||
|     [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> | ||||
|     -d, --day <MON|TUE> | ||||
|         --file             food.txt | ||||
|         --directory | ||||
| @@ -1,4 +1,4 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <Model> | ||||
|   <!--ANIMAL--> | ||||
|   <Command Name="animal" IsBranch="true" Settings="Spectre.Console.Tests.Data.AnimalSettings"> | ||||
| @@ -29,7 +29,7 @@ | ||||
|       <!--HORSE--> | ||||
|       <Command Name="horse" IsBranch="false" ClrType="Spectre.Console.Tests.Data.HorseCommand" Settings="Spectre.Console.Tests.Data.HorseSettings"> | ||||
|         <Parameters> | ||||
|           <Option Short="d" Long="day" Value="NULL" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|           <Option Short="d" Long="day" Value="MON|TUE" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|           <Option Short="" Long="directory" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.DirectoryInfo" /> | ||||
|           <Option Short="" Long="file" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.FileInfo" /> | ||||
|         </Parameters> | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <Model> | ||||
|   <!--ANIMAL--> | ||||
|   <Command Name="animal" IsBranch="true" Settings="Spectre.Console.Tests.Data.AnimalSettings"> | ||||
| @@ -25,7 +25,7 @@ | ||||
|     <!--HORSE--> | ||||
|     <Command Name="horse" IsBranch="false" ClrType="Spectre.Console.Tests.Data.HorseCommand" Settings="Spectre.Console.Tests.Data.HorseSettings"> | ||||
|       <Parameters> | ||||
|         <Option Short="d" Long="day" Value="NULL" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|         <Option Short="d" Long="day" Value="MON|TUE" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|         <Option Short="" Long="directory" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.DirectoryInfo" /> | ||||
|         <Option Short="" Long="file" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.FileInfo" /> | ||||
|         <Option Short="n,p" Long="name,pet-name" Value="VALUE" Required="false" Kind="scalar" ClrType="System.String" /> | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <Model> | ||||
|   <!--DEFAULT COMMAND--> | ||||
|   <Command Name="__default_command" IsBranch="false" IsDefault="true" ClrType="Spectre.Console.Tests.Data.DogCommand" Settings="Spectre.Console.Tests.Data.DogSettings"> | ||||
| @@ -31,7 +31,7 @@ | ||||
|       <Option Short="a" Long="alive,not-dead" Value="NULL" Required="false" Kind="flag" ClrType="System.Boolean"> | ||||
|         <Description>Indicates whether or not the animal is alive.</Description> | ||||
|       </Option> | ||||
|       <Option Short="d" Long="day" Value="NULL" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|       <Option Short="d" Long="day" Value="MON|TUE" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|       <Option Short="" Long="directory" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.DirectoryInfo" /> | ||||
|       <Option Short="" Long="file" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.FileInfo" /> | ||||
|       <Option Short="n,p" Long="name,pet-name" Value="VALUE" Required="false" Kind="scalar" ClrType="System.String" /> | ||||
|   | ||||
| @@ -22,7 +22,7 @@ | ||||
|       <!--__DEFAULT_COMMAND--> | ||||
|       <Command Name="__default_command" IsBranch="false" ClrType="Spectre.Console.Tests.Data.HorseCommand" Settings="Spectre.Console.Tests.Data.HorseSettings"> | ||||
|         <Parameters> | ||||
|           <Option Short="d" Long="day" Value="NULL" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|           <Option Short="d" Long="day" Value="MON|TUE" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|           <Option Short="" Long="directory" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.DirectoryInfo" /> | ||||
|           <Option Short="" Long="file" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.FileInfo" /> | ||||
|         </Parameters> | ||||
|   | ||||
| @@ -25,7 +25,7 @@ | ||||
|     <!--__DEFAULT_COMMAND--> | ||||
|     <Command Name="__default_command" IsBranch="false" ClrType="Spectre.Console.Tests.Data.HorseCommand" Settings="Spectre.Console.Tests.Data.HorseSettings"> | ||||
|       <Parameters> | ||||
|         <Option Short="d" Long="day" Value="NULL" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|         <Option Short="d" Long="day" Value="MON|TUE" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|         <Option Short="" Long="directory" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.DirectoryInfo" /> | ||||
|         <Option Short="" Long="file" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.FileInfo" /> | ||||
|         <Option Short="n,p" Long="name,pet-name" Value="VALUE" Required="false" Kind="scalar" ClrType="System.String" /> | ||||
|   | ||||
| @@ -27,7 +27,7 @@ | ||||
|     <!--__DEFAULT_COMMAND--> | ||||
|     <Command Name="__default_command" IsBranch="false" ClrType="Spectre.Console.Tests.Data.HorseCommand" Settings="Spectre.Console.Tests.Data.HorseSettings"> | ||||
|       <Parameters> | ||||
|         <Option Short="d" Long="day" Value="NULL" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|         <Option Short="d" Long="day" Value="MON|TUE" Required="false" Kind="scalar" ClrType="System.DayOfWeek" /> | ||||
|         <Option Short="" Long="directory" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.DirectoryInfo" /> | ||||
|         <Option Short="" Long="file" Value="NULL" Required="false" Kind="scalar" ClrType="System.IO.FileInfo" /> | ||||
|         <Option Short="n,p" Long="name,pet-name" Value="VALUE" Required="false" Kind="scalar" ClrType="System.String" /> | ||||
|   | ||||
| @@ -23,14 +23,16 @@ public sealed partial class CommandOptionAttributeTests | ||||
|     } | ||||
|  | ||||
|     [Theory] | ||||
|     [InlineData("<VALUE>")] | ||||
|     public void Should_Parse_Value_Correctly(string value) | ||||
|     [InlineData("<VALUE>", "VALUE")] | ||||
|     [InlineData("<VALUE1>", "VALUE1")] | ||||
|     [InlineData("<VALUE1|VALUE2>", "VALUE1|VALUE2")] | ||||
|     public void Should_Parse_Value_Correctly(string value, string expected) | ||||
|     { | ||||
|         // Given, When | ||||
|         var option = new CommandOptionAttribute($"-o|--option {value}"); | ||||
|  | ||||
|         // Then | ||||
|         option.ValueName.ShouldBe("VALUE"); | ||||
|         option.ValueName.ShouldBe(expected); | ||||
|     } | ||||
|  | ||||
|     [Fact] | ||||
|   | ||||
| @@ -28,6 +28,27 @@ public sealed partial class CommandAppTests | ||||
|             return Verifier.Verify(result.Output); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         [Expectation("Root_Command")] | ||||
|         public Task Should_Output_Root_Command_Correctly() | ||||
|         { | ||||
|             // Given | ||||
|             var fixture = new CommandAppTester(); | ||||
|             fixture.Configure(configurator => | ||||
|             { | ||||
|                 configurator.SetApplicationName("myapp"); | ||||
|                 configurator.AddCommand<DogCommand>("dog"); | ||||
|                 configurator.AddCommand<HorseCommand>("horse"); | ||||
|                 configurator.AddCommand<GiraffeCommand>("giraffe"); | ||||
|             }); | ||||
|  | ||||
|             // When | ||||
|             var result = fixture.Run("horse", "--help"); | ||||
|  | ||||
|             // Then | ||||
|             return Verifier.Verify(result.Output); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         [Expectation("Hidden_Commands")] | ||||
|         public Task Should_Skip_Hidden_Commands() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user