diff --git a/src/BuiltInTools/dotnet-watch/Program.cs b/src/BuiltInTools/dotnet-watch/Program.cs index 9a72e6744da4..7ec40e095791 100644 --- a/src/BuiltInTools/dotnet-watch/Program.cs +++ b/src/BuiltInTools/dotnet-watch/Program.cs @@ -105,11 +105,11 @@ public static async Task Main(string[] args) internal async Task RunAsync(string[] args) { - var rootCommand = CreateRootCommand(HandleWatch); + var rootCommand = CreateRootCommand(HandleWatch, _reporter); return await rootCommand.InvokeAsync(args); } - internal static RootCommand CreateRootCommand(Func> handler) + internal static RootCommand CreateRootCommand(Func> handler, IReporter reporter) { var quiet = new Option( new[] { "--quiet", "-q" }, @@ -137,8 +137,11 @@ internal static RootCommand CreateRootCommand(Func new[] { "--no-hot-reload" }, "Suppress hot reload for supported apps."), new Option( - new[] { "--project", "-p" }, + "--project", "The project to watch"), + new Option( + "-p", + "The project to watch") { IsHidden = true }, new Option( "--list", "Lists all discovered files without starting the watcher"), @@ -147,6 +150,16 @@ internal static RootCommand CreateRootCommand(Func root.TreatUnmatchedTokensAsErrors = false; root.Handler = CommandHandler.Create((CommandLineOptions options, ParseResult parseResults) => { + if (string.IsNullOrEmpty(options.Project)) + { + var projectOptionShort = parseResults.ValueForOption("-p"); + if (!string.IsNullOrEmpty(projectOptionShort)) + { + reporter.Warn(Resources.Warning_ProjectAbbreviationDeprecated); + options.Project = projectOptionShort; + } + } + string[] remainingArguments; if (parseResults.UnparsedTokens.Any() && parseResults.UnmatchedTokens.Any()) { diff --git a/src/BuiltInTools/dotnet-watch/Resources.resx b/src/BuiltInTools/dotnet-watch/Resources.resx index 40d7b9cdf729..30a8cd6c1ec8 100644 --- a/src/BuiltInTools/dotnet-watch/Resources.resx +++ b/src/BuiltInTools/dotnet-watch/Resources.resx @@ -129,4 +129,7 @@ Cannot specify both '--quiet' and '--verbose' options. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.cs.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.cs.xlf index 59d5f98e5b77..43f860f58ef0 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.cs.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.cs.xlf @@ -22,6 +22,11 @@ Možnosti --quiet a --verbose se nedají zadat spolu. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.de.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.de.xlf index b772a5351792..dc9dcdd089cf 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.de.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.de.xlf @@ -22,6 +22,11 @@ Die Optionen "--quiet" und "--verbose" können nicht gleichzeitig angegeben werden. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.es.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.es.xlf index 9a01f59deae5..7b92c1b8987c 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.es.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.es.xlf @@ -22,6 +22,11 @@ No se pueden especificar ambas opciones, "--quiet" y "--verbose". + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.fr.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.fr.xlf index d06ee87bd3e9..c3e3202db59a 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.fr.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.fr.xlf @@ -22,6 +22,11 @@ Impossible de spécifier les options '--quiet' et '--verbose'. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.it.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.it.xlf index ced7af187f3f..83b5c6351028 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.it.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.it.xlf @@ -22,6 +22,11 @@ Non è possibile specificare entrambe le opzioni '--quiet' e '--verbose'. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.ja.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.ja.xlf index 34e19a784b9d..2e4c1202b35f 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.ja.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.ja.xlf @@ -22,6 +22,11 @@ '--quiet' と '--verbose' の両方のオプションを指定することはできません。 + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.ko.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.ko.xlf index 130b666b6f04..7c20a39fdc9d 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.ko.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.ko.xlf @@ -22,6 +22,11 @@ '--quiet' 옵션과 '--verbose' 옵션을 둘 다 지정할 수는 없습니다. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.pl.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.pl.xlf index b31b93d70753..b28408e463aa 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.pl.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.pl.xlf @@ -22,6 +22,11 @@ Nie można jednocześnie określić opcji „--quiet” i „--verbose”. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.pt-BR.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.pt-BR.xlf index e7a1e5088eda..c5c484e3f462 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.pt-BR.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.pt-BR.xlf @@ -22,6 +22,11 @@ Não é possível especificar as opções '--quiet' e '--verbose'. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.ru.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.ru.xlf index 0230037ff9be..656d3c554793 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.ru.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.ru.xlf @@ -22,6 +22,11 @@ Невозможно одновременно указать параметры "--quiet" и "--verbose". + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.tr.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.tr.xlf index fe0b1cd8c3f0..70ccc020fa8c 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.tr.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.tr.xlf @@ -22,6 +22,11 @@ Hem '--quiet' hem de '--verbose' seçenekleri belirtilemez. + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hans.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hans.xlf index f25a47e35b39..92902902fd1c 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hans.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hans.xlf @@ -22,6 +22,11 @@ 不能同时指定 "--quiet" 和 "--verbose" 选项。 + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hant.xlf b/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hant.xlf index 69667a91d1a1..4762234ba060 100644 --- a/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hant.xlf +++ b/src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hant.xlf @@ -22,6 +22,11 @@ 無法同時指定 '--quiet' 和 '--verbose' 選項。 + + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project. + + \ No newline at end of file diff --git a/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs b/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs index e35be5a939e9..0e38505461bd 100644 --- a/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs +++ b/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs @@ -5,6 +5,7 @@ using System.CommandLine.IO; using System.CommandLine.Parsing; using System.Threading.Tasks; +using Moq; using Xunit; using Xunit.Abstractions; @@ -12,11 +13,13 @@ namespace Microsoft.DotNet.Watcher.Tools { public class CommandLineOptionsTests { + private readonly Extensions.Tools.Internal.TestReporter _testReporter; private readonly TestConsole _console; public CommandLineOptionsTests(ITestOutputHelper output) { _console = new(); + _testReporter = new(output); } [Theory] @@ -26,7 +29,7 @@ public CommandLineOptionsTests(ITestOutputHelper output) [InlineData(new object[] { new[] { "--help", "--bogus" } })] public async Task HelpArgs(string[] args) { - var rootCommand = Program.CreateRootCommand(c => Task.FromResult(0)); + var rootCommand = Program.CreateRootCommand(c => Task.FromResult(0), _testReporter); await rootCommand.InvokeAsync(args, _console); @@ -46,7 +49,7 @@ public async Task ParsesRemainingArgs(string[] args, string[] expected) { options = c; return Task.FromResult(0); - }); + }, _testReporter); await rootCommand.InvokeAsync(args, _console); @@ -59,11 +62,40 @@ public async Task ParsesRemainingArgs(string[] args, string[] expected) [Fact] public async Task CannotHaveQuietAndVerbose() { - var rootCommand = Program.CreateRootCommand(c => Task.FromResult(0)); + var rootCommand = Program.CreateRootCommand(c => Task.FromResult(0), _testReporter); await rootCommand.InvokeAsync(new[] { "--quiet", "--verbose" }, _console); Assert.Contains(Resources.Error_QuietAndVerboseSpecified, _console.Error.ToString()); } + + [Fact] + public async Task ShortFormForProjectArgumentPrintsWarning() + { + var reporter = new Mock(); + reporter.Setup(r => r.Warn(Resources.Warning_ProjectAbbreviationDeprecated)).Verifiable(); + CommandLineOptions options = null; + var rootCommand = Program.CreateRootCommand(c => { options = c; return Task.FromResult(0); }, reporter.Object); + + await rootCommand.InvokeAsync(new[] { "-p", "MyProject.csproj" }, _console); + + reporter.Verify(); + Assert.NotNull(options); + Assert.Equal("MyProject.csproj", options.Project); + } + + [Fact] + public async Task LongFormForProjectArgumentWorks() + { + var reporter = new Mock(); + CommandLineOptions options = null; + var rootCommand = Program.CreateRootCommand(c => { options = c; return Task.FromResult(0); }, reporter.Object); + + await rootCommand.InvokeAsync(new[] { "--project", "MyProject.csproj" }, _console); + + reporter.Verify(r => r.Warn(It.IsAny()), Times.Never()); + Assert.NotNull(options); + Assert.Equal("MyProject.csproj", options.Project); + } } }