Skip to content

Commit 7df2e57

Browse files
committed
Nonfunctional code
1 parent 572a0e8 commit 7df2e57

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

src/Cli/dotnet/IDeprecated.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.CommandLine;
5+
using Microsoft.DotNet.Cli.Utils;
6+
namespace Microsoft.DotNet.Cli;
7+
8+
public interface IDeprecated
9+
{
10+
public static Dictionary<CliOption, (string messageToShow, Version errorLevel)> DeprecatedOptions { get; } = new()
11+
{
12+
{ PackageListCommandParser.DeprecatedOption, ("old versions are old", new Version(10, 0, 100)) }
13+
};
14+
15+
public static Dictionary<CliArgument, (string messageToShow, Version errorLevel)> DeprecatedArguments { get; } = new()
16+
{
17+
{ PackageAddCommandParser.CmdPackageArgument, ("argument bad; use option", new Version(10, 0, 100)) }
18+
};
19+
20+
public bool IsDeprecated { get; set; }
21+
22+
public static void WarnIfNecessary(IReporter reporter, string messageToShow, Version errorLevel)
23+
{
24+
reporter.WriteLine(messageToShow);
25+
}
26+
}

src/Cli/dotnet/Program.cs

+35
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry
134134
}
135135
PerformanceLogEventSource.Log.BuiltInCommandParserStop();
136136

137+
DeprecatedCheck(parseResult);
138+
137139
using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel =
138140
new FirstTimeUseNoticeSentinel())
139141
{
@@ -306,6 +308,39 @@ private static int AdjustExitCode(ParseResult parseResult, int exitCode)
306308
return exitCode;
307309
}
308310

311+
private static void DeprecatedCheck(ParseResult parseResult)
312+
{
313+
if (parseResult.Errors.Any())
314+
{
315+
// There are errors anyway; don't worry about deprecation
316+
return;
317+
}
318+
319+
var command = parseResult.CommandResult;
320+
if (command.Command is IDeprecated)
321+
{
322+
// Doesn't work because what we want is for the Command's Action's output to be deprecated (or not)
323+
// And what about parents?
324+
}
325+
326+
foreach (var entry in IDeprecated.DeprecatedArguments)
327+
{
328+
if (parseResult.GetArguments().Any(a => entry.Key.Name.Equals(a)))
329+
{
330+
// Doesn't work because this is the value, not the key, of the argument
331+
}
332+
}
333+
334+
foreach (var entry in IDeprecated.DeprecatedOptions)
335+
{
336+
if (parseResult.HasOption(entry.Key))
337+
{
338+
// Finally works!
339+
IDeprecated.WarnIfNecessary(Reporter.ConsoleOutReporter, entry.Value.messageToShow, entry.Value.errorLevel);
340+
}
341+
}
342+
}
343+
309344
private static void ReportDotnetHomeUsage(IEnvironmentProvider provider)
310345
{
311346
var home = provider.GetEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName);

src/Cli/dotnet/commands/dotnet-package/remove/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
namespace Microsoft.DotNet.Tools.Package.Remove;
1111

12-
internal class RemovePackageReferenceCommand : CommandBase
12+
internal class RemovePackageReferenceCommand : CommandBase, IDeprecated
1313
{
1414
private readonly string _fileOrDirectory;
1515
private readonly IReadOnlyCollection<string> _arguments;
16+
public bool IsDeprecated { get; set; } = false;
1617

1718
public RemovePackageReferenceCommand(
1819
ParseResult parseResult) : base(parseResult)

src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private static CliCommand ConstructCommand()
2323
command.Arguments.Add(PackageRemoveCommandParser.CmdPackageArgument);
2424
command.Options.Add(PackageRemoveCommandParser.InteractiveOption);
2525

26-
command.SetAction((parseResult) => new RemovePackageReferenceCommand(parseResult).Execute());
26+
command.SetAction((parseResult) => new RemovePackageReferenceCommand(parseResult) { IsDeprecated = true }.Execute());
2727

2828
return command;
2929
}

0 commit comments

Comments
 (0)