diff --git a/src/VisualStudio.Tests/CommandFactoryTests.cs b/src/VisualStudio.Tests/CommandFactoryTests.cs index 666c29f..52cbec1 100644 --- a/src/VisualStudio.Tests/CommandFactoryTests.cs +++ b/src/VisualStudio.Tests/CommandFactoryTests.cs @@ -29,6 +29,14 @@ public async Task when_creating_command_with_help_argument_then_throws_show_usag await Assert.ThrowsAsync(async () => await commandFactory.CreateCommandAsync("test", ImmutableArray.Create("/h"))); } + [Fact] + public async Task when_creating_builtin_command_with_help_argument_then_throws_show_usage() + { + var commandFactory = new CommandFactory(); + + await Assert.ThrowsAsync(async () => await commandFactory.CreateCommandAsync("modify", ImmutableArray.Create("-?"))); + } + [Theory] [InlineData(Commands.Install, typeof(InstallCommand))] [InlineData(Commands.Run, typeof(RunCommand))] diff --git a/src/VisualStudio/CommandFactory.cs b/src/VisualStudio/CommandFactory.cs index e927a25..2a2e126 100644 --- a/src/VisualStudio/CommandFactory.cs +++ b/src/VisualStudio/CommandFactory.cs @@ -115,8 +115,14 @@ public Task CreateCommandAsync(string command, ImmutableArray a // Create the descriptor var commandDescriptor = factory.CreateDescriptor(); + // Parse out help arg up-front to avoid unnecessary extra parsing for args. + var help = new HelpOption(); + var finalArgs = help.Parse(args); + if (help.Value) + throw new ShowUsageException(commandDescriptor); + // Parse the arguments - commandDescriptor.Parse(args); + commandDescriptor.Parse(finalArgs); // And create the command return Task.FromResult(factory.CreateCommand(commandDescriptor));