Skip to content

Nonfunctional code #48076

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
36 changes: 36 additions & 0 deletions src/Cli/dotnet/IDeprecated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Deployment.DotNet.Releases;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli.Utils.Extensions;
namespace Microsoft.DotNet.Cli;

public interface IDeprecated
{
public static Dictionary<CliOption, (string messageToShow, ReleaseVersion errorLevel)> DeprecatedOptions { get; } = new()
{
{ PackageListCommandParser.DeprecatedOption, ("old versions are old", new ReleaseVersion(10, 0, 100)) }
};

public static Dictionary<CliArgument, (string messageToShow, ReleaseVersion errorLevel)> DeprecatedArguments { get; } = new()
{
{ PackageAddCommandParser.CmdPackageArgument, ("argument bad; use option", new ReleaseVersion(10, 0, 100)) }
};

public bool IsDeprecated { get; set; }

public static void WarnIfNecessary(IReporter reporter, string messageToShow, ReleaseVersion errorLevel)
{
if (new ReleaseVersion(Utils.Product.Version) < errorLevel)
{
reporter.WriteLine(messageToShow);
}
else
{
reporter.WriteLine(messageToShow.Yellow());
}
}
}
35 changes: 35 additions & 0 deletions src/Cli/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry
}
PerformanceLogEventSource.Log.BuiltInCommandParserStop();

DeprecatedCheck(parseResult);

using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel =
new FirstTimeUseNoticeSentinel())
{
Expand Down Expand Up @@ -306,6 +308,39 @@ private static int AdjustExitCode(ParseResult parseResult, int exitCode)
return exitCode;
}

private static void DeprecatedCheck(ParseResult parseResult)
{
if (parseResult.Errors.Any())
{
// There are errors anyway; don't worry about deprecation
return;
}

var command = parseResult.CommandResult;
if (command.Command is IDeprecated)
{
// Doesn't work because what we want is for the Command's Action's output to be deprecated (or not)
// And what about parents?
}

foreach (var entry in IDeprecated.DeprecatedArguments)
{
if (parseResult.GetArguments().Any(a => entry.Key.Name.Equals(a)))
{
// Doesn't work because this is the value, not the key, of the argument
}
}

foreach (var entry in IDeprecated.DeprecatedOptions)
{
if (parseResult.HasOption(entry.Key))
{
// Finally works!
IDeprecated.WarnIfNecessary(Reporter.ConsoleOutReporter, entry.Value.messageToShow, entry.Value.errorLevel);
}
}
}

private static void ReportDotnetHomeUsage(IEnvironmentProvider provider)
{
var home = provider.GetEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName);
Expand Down
9 changes: 8 additions & 1 deletion src/Cli/dotnet/commands/dotnet-package/remove/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.Deployment.DotNet.Releases;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Extensions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.NuGet;

namespace Microsoft.DotNet.Tools.Package.Remove;

internal class RemovePackageReferenceCommand : CommandBase
internal class RemovePackageReferenceCommand : CommandBase, IDeprecated
{
private readonly string _fileOrDirectory;
private readonly IReadOnlyCollection<string> _arguments;
public bool IsDeprecated { get; set; } = false;

public RemovePackageReferenceCommand(
ParseResult parseResult) : base(parseResult)
Expand All @@ -33,6 +35,11 @@ public RemovePackageReferenceCommand(

public override int Execute()
{
if (IsDeprecated)
{
IDeprecated.WarnIfNecessary(Reporter.ConsoleOutReporter, "wrong verb order", new ReleaseVersion(10, 0, 100));
}

var projectFilePath = string.Empty;

if (!File.Exists(_fileOrDirectory))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static CliCommand ConstructCommand()
command.Arguments.Add(PackageRemoveCommandParser.CmdPackageArgument);
command.Options.Add(PackageRemoveCommandParser.InteractiveOption);

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

return command;
}
Expand Down