From f972cf80a9c78538c95e1be1ba62e6d013e722c4 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Thu, 12 Jan 2017 23:24:12 -1000 Subject: [PATCH] Treat /? the same as --help (#5285) * Fixes issue 4539 * Support -? --- src/dotnet/CommandLine/CommandLineApplication.cs | 7 ++++++- src/dotnet/Program.cs | 4 +++- .../GivenThatIWantToShowHelpForDotnetCommand.cs | 2 ++ test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/dotnet/CommandLine/CommandLineApplication.cs b/src/dotnet/CommandLine/CommandLineApplication.cs index 24c1a61b0..a7db54bce 100644 --- a/src/dotnet/CommandLine/CommandLineApplication.cs +++ b/src/dotnet/CommandLine/CommandLineApplication.cs @@ -148,7 +148,12 @@ namespace Microsoft.DotNet.Cli.CommandLine var arg = args[index]; bool isLongOption = arg.StartsWith("--"); - if (isLongOption || arg.StartsWith("-")) + if (arg == "-?" || arg == "/?") + { + command.ShowHelp(); + return 0; + } + else if (isLongOption || arg.StartsWith("-")) { CommandOption option; var result = ParseOption(isLongOption, command, args, ref index, out option); diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index faefe0a31..e95d56aa4 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -118,7 +118,9 @@ namespace Microsoft.DotNet.Cli PrintInfo(); return 0; } - else if (IsArg(args[lastArg], "h", "help")) + else if (IsArg(args[lastArg], "h", "help") || + args[lastArg] == "-?" || + args[lastArg] == "/?") { HelpCommand.PrintHelp(); return 0; diff --git a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs index 5b487e9cf..e98fb85e5 100644 --- a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs +++ b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs @@ -56,6 +56,8 @@ Advanced Commands: [Theory] [InlineData("--help")] [InlineData("-h")] + [InlineData("-?")] + [InlineData("/?")] public void WhenHelpOptionIsPassedToDotnetItPrintsUsage(string helpArg) { var cmd = new DotnetCommand() diff --git a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs index c6fdfdf08..4a0d87381 100644 --- a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs @@ -182,6 +182,8 @@ EndGlobal [Theory] [InlineData("--help")] [InlineData("-h")] + [InlineData("-?")] + [InlineData("/?")] public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg) { var cmd = new DotnetCommand()