mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-01 01:25:27 +08:00 
			
		
		
		
	Make -v|--version opt-in
				
					
				
			We added an automatic version option in 0.49. We did this with good intentions, but forgot that people might already use --version as an option for a root command. This commit makes -v|--version completely opt-in.
This commit is contained in:
		 Patrik Svensson
					Patrik Svensson
				
			
				
					committed by
					
						 Patrik Svensson
						Patrik Svensson
					
				
			
			
				
	
			
			
			 Patrik Svensson
						Patrik Svensson
					
				
			
						parent
						
							88515b7d7f
						
					
				
				
					commit
					3acc90e47c
				
			| @@ -1,4 +1,4 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp <FOO> <BAR> <BAZ> <CORGI> [QUX] [OPTIONS] | ||||
|  | ||||
| ARGUMENTS: | ||||
| @@ -9,5 +9,4 @@ ARGUMENTS: | ||||
|     [QUX] | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
| @@ -1,15 +1,14 @@ | ||||
| -------------------------------------- | ||||
| ---      CUSTOM HELP PROVIDER      --- | ||||
| -------------------------------------- | ||||
|  | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|  | ||||
| -------------------------------------- | ||||
| ---      CUSTOM HELP PROVIDER      --- | ||||
| -------------------------------------- | ||||
|  | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|  | ||||
| Version 1.0 | ||||
| @@ -1,4 +1,4 @@ | ||||
| -------------------------------------- | ||||
| -------------------------------------- | ||||
| ---      CUSTOM HELP PROVIDER      --- | ||||
| -------------------------------------- | ||||
|  | ||||
| @@ -6,8 +6,7 @@ USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| DESCRIPTION: | ||||
| DESCRIPTION: | ||||
| The lion command. | ||||
|  | ||||
| USAGE: | ||||
| @@ -10,8 +10,7 @@ ARGUMENTS: | ||||
|  | ||||
| OPTIONS: | ||||
|                              DEFAULT | ||||
|     -h, --help                                   Prints help information | ||||
|     -v, --version                                Prints version information | ||||
|     -h, --help                                   Prints help information | ||||
|     -a, --alive                                  Indicates whether or not the animal is alive | ||||
|     -n, --name <VALUE> | ||||
|         --agility <VALUE>    10                  The agility between 0 and 100 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| DESCRIPTION: | ||||
| DESCRIPTION: | ||||
| The dog command. | ||||
|  | ||||
| USAGE: | ||||
| @@ -18,7 +18,6 @@ ARGUMENTS: | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help            Prints help information | ||||
|     -v, --version         Prints version information | ||||
|     -a, --alive           Indicates whether or not the animal is alive | ||||
|     -n, --name <VALUE> | ||||
|     -g, --good-boy | ||||
| @@ -1,4 +1,4 @@ | ||||
| DESCRIPTION: | ||||
| DESCRIPTION: | ||||
| The lion command. | ||||
|  | ||||
| USAGE: | ||||
| @@ -10,8 +10,7 @@ ARGUMENTS: | ||||
|  | ||||
| OPTIONS: | ||||
|                              DEFAULT | ||||
|     -h, --help                                   Prints help information | ||||
|     -v, --version                                Prints version information | ||||
|     -h, --help                                   Prints help information | ||||
|     -a, --alive                                  Indicates whether or not the animal is alive | ||||
|     -n, --name <VALUE> | ||||
|         --agility <VALUE>    10                  The agility between 0 and 100 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| BESCHREIBUNG: | ||||
| BESCHREIBUNG: | ||||
| The lion command. | ||||
|  | ||||
| VERWENDUNG: | ||||
| @@ -14,7 +14,6 @@ ARGUMENTE: | ||||
| OPTIONEN: | ||||
|                              STANDARDWERT | ||||
|     -h, --help                                   Zeigt Hilfe an | ||||
|     -v, --version                                Zeigt Versionsinformationen an | ||||
|     -a, --alive                                  Indicates whether or not the animal is alive | ||||
|     -n, --name <VALUE> | ||||
|         --agility <VALUE>    10                  The agility between 0 and 100 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| DESCRIPTION: | ||||
| DESCRIPTION: | ||||
| The lion command. | ||||
|  | ||||
| USAGE: | ||||
| @@ -13,8 +13,7 @@ ARGUMENTS: | ||||
|  | ||||
| OPTIONS: | ||||
|                              DEFAULT | ||||
|     -h, --help                                   Prints help information | ||||
|     -v, --version                                Prints version information | ||||
|     -h, --help                                   Prints help information | ||||
|     -a, --alive                                  Indicates whether or not the animal is alive | ||||
|     -n, --name <VALUE> | ||||
|         --agility <VALUE>    10                  The agility between 0 and 100 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| DESCRIPTION: | ||||
| DESCRIPTION: | ||||
| The lion command. | ||||
|  | ||||
| UTILISATION: | ||||
| @@ -13,8 +13,7 @@ ARGUMENTS: | ||||
|  | ||||
| OPTIONS: | ||||
|                              DÉFAUT | ||||
|     -h, --help                                   Affiche l'aide | ||||
|     -v, --version                                Affiche la version | ||||
|     -h, --help                                   Affiche l'aide | ||||
|     -a, --alive                                  Indicates whether or not the animal is alive | ||||
|     -n, --name <VALUE> | ||||
|         --agility <VALUE>    10                  The agility between 0 and 100 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| BESKRIVNING: | ||||
| BESKRIVNING: | ||||
| The lion command. | ||||
|  | ||||
| ANVÄNDING: | ||||
| @@ -14,7 +14,6 @@ ARGUMENT: | ||||
| VAL: | ||||
|                              STANDARD | ||||
|     -h, --help                                   Skriver ut hjälpinformation | ||||
|     -v, --version                                Skriver ut versionsnummer | ||||
|     -a, --alive                                  Indicates whether or not the animal is alive | ||||
|     -n, --name <VALUE> | ||||
|         --agility <VALUE>    10                  The agility between 0 and 100 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| [bold]DESCRIPTION:[/] | ||||
| [bold]DESCRIPTION:[/] | ||||
| The lion command. | ||||
|  | ||||
| [bold]USAGE:[/] | ||||
| @@ -14,7 +14,6 @@ The lion command. | ||||
| []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 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| [yellow]DESCRIPTION:[/] | ||||
| [yellow]DESCRIPTION:[/] | ||||
| The lion command. | ||||
|  | ||||
| [yellow]USAGE:[/] | ||||
| @@ -14,7 +14,6 @@ The lion command. | ||||
| [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 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| []DESCRIPTION:[/] | ||||
| []DESCRIPTION:[/] | ||||
| The lion command. | ||||
|  | ||||
| []USAGE:[/] | ||||
| @@ -14,7 +14,6 @@ The lion command. | ||||
| []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 | ||||
|   | ||||
| @@ -1,9 +1,8 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command. | ||||
|   | ||||
| @@ -1,10 +1,9 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp <FOO> [OPTIONS] | ||||
|  | ||||
| ARGUMENTS: | ||||
|     <FOO>    Dummy argument FOO | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|         --baz        Dummy option BAZ | ||||
|     -h, --help    Prints help information | ||||
|         --baz     Dummy option BAZ | ||||
| @@ -1,9 +1,8 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|   | ||||
| @@ -1,9 +1,8 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     bar | ||||
| @@ -0,0 +1,12 @@ | ||||
| USAGE: | ||||
|     myapp <FOO> <BAR> <BAZ> <CORGI> [QUX] [OPTIONS] | ||||
|  | ||||
| ARGUMENTS: | ||||
|     <FOO> | ||||
|     <BAR> | ||||
|     <BAZ> | ||||
|     <CORGI> | ||||
|     [QUX] | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help    Prints help information | ||||
| @@ -1,9 +1,8 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>           The dog command | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| DESCRIPTION: | ||||
| DESCRIPTION: | ||||
| The horse command. | ||||
|  | ||||
| USAGE: | ||||
| @@ -10,7 +10,6 @@ ARGUMENTS: | ||||
| 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> | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| EXAMPLES: | ||||
| @@ -16,8 +16,7 @@ EXAMPLES: | ||||
|     myapp horse --name Spirit | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| EXAMPLES: | ||||
| @@ -9,8 +9,7 @@ EXAMPLES: | ||||
|     myapp dog --name Daisy | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|   | ||||
| @@ -1,20 +1,19 @@ | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| EXAMPLES: | ||||
|     myapp dog --name Rufus --age 12 --good-boy | ||||
|     myapp dog --name Luna | ||||
|     myapp dog --name Charlie | ||||
|     myapp dog --name Bella | ||||
|     myapp dog --name Daisy | ||||
|     myapp dog --name Milo | ||||
|     myapp horse --name Brutus | ||||
|     myapp horse --name Sugar --IsAlive false | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| EXAMPLES: | ||||
|     myapp dog --name Rufus --age 12 --good-boy | ||||
|     myapp dog --name Luna | ||||
|     myapp dog --name Charlie | ||||
|     myapp dog --name Bella | ||||
|     myapp dog --name Daisy | ||||
|     myapp dog --name Milo | ||||
|     myapp horse --name Brutus | ||||
|     myapp horse --name Sugar --IsAlive false | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|     horse        The horse command | ||||
| @@ -1,10 +1,9 @@ | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|     horse        The horse command | ||||
| @@ -1,24 +1,23 @@ | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| EXAMPLES: | ||||
|     myapp dog --name Rufus --age 12 --good-boy | ||||
|     myapp dog --name Luna | ||||
|     myapp dog --name Charlie | ||||
|     myapp dog --name Bella | ||||
|     myapp dog --name Daisy | ||||
|     myapp dog --name Milo | ||||
|     myapp horse --name Brutus | ||||
|     myapp horse --name Sugar --IsAlive false | ||||
|     myapp horse --name Cash | ||||
|     myapp horse --name Dakota | ||||
|     myapp horse --name Cisco | ||||
|     myapp horse --name Spirit | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| EXAMPLES: | ||||
|     myapp dog --name Rufus --age 12 --good-boy | ||||
|     myapp dog --name Luna | ||||
|     myapp dog --name Charlie | ||||
|     myapp dog --name Bella | ||||
|     myapp dog --name Daisy | ||||
|     myapp dog --name Milo | ||||
|     myapp horse --name Brutus | ||||
|     myapp horse --name Sugar --IsAlive false | ||||
|     myapp horse --name Cash | ||||
|     myapp horse --name Dakota | ||||
|     myapp horse --name Cisco | ||||
|     myapp horse --name Spirit | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     dog <AGE>    The dog command | ||||
|     horse        The horse command | ||||
| @@ -1,4 +1,4 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| EXAMPLES: | ||||
| @@ -9,8 +9,7 @@ EXAMPLES: | ||||
|     myapp animal dog --name Daisy | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     animal    The animal command | ||||
| @@ -12,8 +12,7 @@ EXAMPLES: | ||||
|     myapp animal horse --name Sugar --IsAlive false | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     animal    The animal command | ||||
| @@ -1,9 +1,8 @@ | ||||
| USAGE: | ||||
| USAGE: | ||||
|     myapp [OPTIONS] <COMMAND> | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     animal    The animal command | ||||
| @@ -16,8 +16,7 @@ EXAMPLES: | ||||
|     myapp animal horse --name Spirit | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
|     -h, --help    Prints help information | ||||
|  | ||||
| COMMANDS: | ||||
|     animal    The animal command | ||||
| @@ -0,0 +1,13 @@ | ||||
| USAGE: | ||||
|     myapp <FOO> <BAR> <BAZ> <CORGI> [QUX] [OPTIONS] | ||||
|  | ||||
| ARGUMENTS: | ||||
|     <FOO> | ||||
|     <BAR> | ||||
|     <BAZ> | ||||
|     <CORGI> | ||||
|     [QUX] | ||||
|  | ||||
| OPTIONS: | ||||
|     -h, --help       Prints help information | ||||
|     -v, --version    Prints version information | ||||
| @@ -950,6 +950,45 @@ public sealed partial class CommandAppTests | ||||
|             return Verifier.Verify(result.Output); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         [Expectation("NoVersion")] | ||||
|         public Task Should_Not_Include_Application_Version_If_Not_Set() | ||||
|         { | ||||
|             // Given | ||||
|             var fixture = new CommandAppTester(); | ||||
|             fixture.SetDefaultCommand<GenericCommand<ArgumentOrderSettings>>(); | ||||
|             fixture.Configure(config => | ||||
|             { | ||||
|                 config.SetApplicationName("myapp"); | ||||
|             }); | ||||
|  | ||||
|             // When | ||||
|             var result = fixture.Run("--help"); | ||||
|  | ||||
|             // Then | ||||
|             return Verifier.Verify(result.Output); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         [Expectation("Version")] | ||||
|         public Task Should_Include_Application_Version_If_Set() | ||||
|         { | ||||
|             // Given | ||||
|             var fixture = new CommandAppTester(); | ||||
|             fixture.SetDefaultCommand<GenericCommand<ArgumentOrderSettings>>(); | ||||
|             fixture.Configure(config => | ||||
|             { | ||||
|                 config.SetApplicationName("myapp"); | ||||
|                 config.SetApplicationVersion("0.49.1"); | ||||
|             }); | ||||
|  | ||||
|             // When | ||||
|             var result = fixture.Run("--help"); | ||||
|  | ||||
|             // Then | ||||
|             return Verifier.Verify(result.Output); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         [Expectation("Hidden_Command_Options")] | ||||
|         public Task Should_Not_Show_Hidden_Command_Options() | ||||
|   | ||||
| @@ -34,6 +34,24 @@ public sealed partial class CommandAppTests | ||||
|             result.Output.ShouldBe("1.0"); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void Should_Not_Display_Version_If_Not_Specified() | ||||
|         { | ||||
|             // Given | ||||
|             var fixture = new CommandAppTester(); | ||||
|             fixture.Configure(configurator => | ||||
|             { | ||||
|                 configurator.AddCommand<EmptyCommand>("empty"); | ||||
|             }); | ||||
|  | ||||
|             // When | ||||
|             var result = fixture.Run("--version"); | ||||
|  | ||||
|             // Then | ||||
|             result.ExitCode.ShouldNotBe(0); | ||||
|             result.Output.ShouldStartWith("Error: Unexpected option 'version'"); | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|         public void Should_Execute_Command_Not_Output_Application_Version_To_The_Console() | ||||
|         { | ||||
| @@ -42,7 +60,6 @@ public sealed partial class CommandAppTests | ||||
|             fixture.Configure(configurator => | ||||
|             { | ||||
|                 configurator.SetApplicationVersion("1.0"); | ||||
|  | ||||
|                 configurator.AddCommand<EmptyCommand>("empty"); | ||||
|             }); | ||||
|  | ||||
| @@ -81,7 +98,6 @@ public sealed partial class CommandAppTests | ||||
|             fixture.Configure(configurator => | ||||
|             { | ||||
|                 configurator.SetApplicationVersion("1.0"); | ||||
|  | ||||
|                 configurator.AddBranch<EmptyCommandSettings>("branch", branch => | ||||
|                 { | ||||
|                     branch.SetDefaultCommand<EmptyCommand>(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user