Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate -p option (in short form) to dotnet watch #18336

Merged
merged 3 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/BuiltInTools/dotnet-watch/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public static async Task<int> Main(string[] args)

internal async Task<int> RunAsync(string[] args)
{
var rootCommand = CreateRootCommand(HandleWatch);
var rootCommand = CreateRootCommand(HandleWatch, _reporter);
return await rootCommand.InvokeAsync(args);
}

internal static RootCommand CreateRootCommand(Func<CommandLineOptions, Task<int>> handler)
internal static RootCommand CreateRootCommand(Func<CommandLineOptions, Task<int>> handler, IReporter reporter)
{
var quiet = new Option<bool>(
new[] { "--quiet", "-q" },
Expand Down Expand Up @@ -137,8 +137,11 @@ internal static RootCommand CreateRootCommand(Func<CommandLineOptions, Task<int>
new[] { "--no-hot-reload" },
"Suppress hot reload for supported apps."),
new Option<string>(
new[] { "--project", "-p" },
"--project",
"The project to watch"),
new Option<string>(
"-p",
"The project to watch") { IsHidden = true },
new Option<bool>(
"--list",
"Lists all discovered files without starting the watcher"),
Expand All @@ -147,6 +150,16 @@ internal static RootCommand CreateRootCommand(Func<CommandLineOptions, Task<int>
root.TreatUnmatchedTokensAsErrors = false;
root.Handler = CommandHandler.Create((CommandLineOptions options, ParseResult parseResults) =>
{
if (string.IsNullOrEmpty(options.Project))
{
var projectOptionShort = parseResults.ValueForOption<string>("-p");
if (!string.IsNullOrEmpty(projectOptionShort))
{
reporter.Warn(Resources.Warning_ProjectAbbreviationDeprecated);
options.Project = projectOptionShort;
}
}

string[] remainingArguments;
if (parseResults.UnparsedTokens.Any() && parseResults.UnmatchedTokens.Any())
{
Expand Down
3 changes: 3 additions & 0 deletions src/BuiltInTools/dotnet-watch/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@
<data name="Error_QuietAndVerboseSpecified" xml:space="preserve">
<value>Cannot specify both '--quiet' and '--verbose' options.</value>
</data>
<data name="Warning_ProjectAbbreviationDeprecated" xml:space="preserve">
<value>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Možnosti --quiet a --verbose se nedají zadat spolu.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Die Optionen "--quiet" und "--verbose" können nicht gleichzeitig angegeben werden.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">No se pueden especificar ambas opciones, "--quiet" y "--verbose".</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Impossible de spécifier les options '--quiet' et '--verbose'.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Non è possibile specificare entrambe le opzioni '--quiet' e '--verbose'.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">'--quiet' と '--verbose' の両方のオプションを指定することはできません。</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">'--quiet' 옵션과 '--verbose' 옵션을 둘 다 지정할 수는 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Nie można jednocześnie określić opcji „--quiet” i „--verbose”.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Não é possível especificar as opções '--quiet' e '--verbose'.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Невозможно одновременно указать параметры "--quiet" и "--verbose".</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">Hem '--quiet' hem de '--verbose' seçenekleri belirtilemez.</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">不能同时指定 "--quiet" 和 "--verbose" 选项。</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/xlf/Resources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<target state="translated">無法同時指定 '--quiet' 和 '--verbose' 選項。</target>
<note />
</trans-unit>
<trans-unit id="Warning_ProjectAbbreviationDeprecated">
<source>Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</source>
<target state="new">Warning NETSDK1174: The abbreviation of -p for --project is deprecated. Please use --project.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
38 changes: 35 additions & 3 deletions src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
using System.CommandLine.IO;
using System.CommandLine.Parsing;
using System.Threading.Tasks;
using Moq;
using Xunit;
using Xunit.Abstractions;

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]
Expand All @@ -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);

Expand All @@ -46,7 +49,7 @@ public async Task ParsesRemainingArgs(string[] args, string[] expected)
{
options = c;
return Task.FromResult(0);
});
}, _testReporter);

await rootCommand.InvokeAsync(args, _console);

Expand All @@ -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<Extensions.Tools.Internal.IReporter>();
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<Extensions.Tools.Internal.IReporter>();
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<string>()), Times.Never());
Assert.NotNull(options);
Assert.Equal("MyProject.csproj", options.Project);
}
}
}