Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
2 changes: 0 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<PackageVersion Include="Microsoft.DotNet.Maestro.Tasks" Version="1.1.0-beta.24415.2" />
<PackageVersion Include="Microsoft.DotNet.XliffTasks" Version="$(MicrosoftDotNetXliffTasksVersion)" />
<PackageVersion Include="Microsoft.DotNet.SignTool" Version="10.0.0-beta.25367.5" />
<PackageVersion Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="3.0.0-preview6.19253.5" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Abstractions" Version="$(MicrosoftExtensionsFileProvidersAbstractionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(MicrosoftExtensionsFileSystemGlobbingPackageVersion)" />
<PackageVersion Include="Microsoft.Internal.VisualStudio.Shell.Framework" Version="17.10.40173" />
Expand Down Expand Up @@ -179,7 +178,6 @@
<_allowBuildFromSourcePackage Include="Microsoft.CSharp" />
<_allowBuildFromSourcePackage Include="Microsoft.DotNet.Build.Tasks.Feed" />
<_allowBuildFromSourcePackage Include="Microsoft.DotNet.XliffTasks" />
<_allowBuildFromSourcePackage Include="Microsoft.Extensions.CommandLineUtils.Sources" />
<_allowBuildFromSourcePackage Include="Microsoft.Extensions.FileProviders.Abstractions" />
<_allowBuildFromSourcePackage Include="Microsoft.Extensions.FileSystemGlobbing" />
<_allowBuildFromSourcePackage Include="Microsoft.Web.Xdt" />
Expand Down
4 changes: 0 additions & 4 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="dotnet-libraries" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json" />
<add key="myget-legacy@Local" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/myget-legacy%40Local/nuget/v3/index.json" />
<add key="nuget-build" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/nuget-build/nuget/v3/index.json" />
<add key="vside" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/msft_consumption%40Local/nuget/v3/index.json" />
</packageSources>
Expand Down Expand Up @@ -90,9 +89,6 @@
<package pattern="vslangproj90" />
<package pattern="vswebsite.interop" />
</packageSource>
<packageSource key="myget-legacy@Local">
<package pattern="Microsoft.Extensions.CommandLineUtils.Sources" />
</packageSource>
<packageSource key="VS">
<package pattern="Microsoft.DevDiv.Validation.TestPlatform.Settings.Tasks" />
</packageSource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#nullable enable

namespace NuGet.CommandLine.XPlat
namespace NuGet.CommandLine.XPlat.Commands
{
internal static class CommandConstants
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.CommandLine;
using System.CommandLine.Help;
using System.Threading.Tasks;
using Microsoft.Extensions.CommandLineUtils;
using NuGet.CommandLine.XPlat.Commands;
using NuGet.Common;

Expand Down Expand Up @@ -78,15 +77,7 @@ internal static void LogException(Exception e, ILogger log)
log.LogVerbose(e.ToString());
}

internal static void Register(CommandLineApplication app)
{
app.Command("config", configCmd =>
{
configCmd.Description = Strings.Config_Description;
});
}

internal static Command Register(Command app, Func<ILogger> getLogger)
internal static Command Register(Command app, Func<ILoggerWithColor> getLogger)
{
var ConfigCmd = new DocumentedCommand(name: "config", description: Strings.Config_Description, "https://aka.ms/dotnet/nuget/config");
ConfigCmd.Options.Add(HelpOption);
Expand Down
154 changes: 81 additions & 73 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/DeleteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,102 @@
#nullable disable

using System;
using System.CommandLine;
using System.Globalization;
using Microsoft.Extensions.CommandLineUtils;
using NuGet.Commands;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Credentials;

namespace NuGet.CommandLine.XPlat
{
internal static class DeleteCommand
{
public static void Register(CommandLineApplication app, Func<ILogger> getLogger)
private static readonly Option<string> SourceOption = new Option<string>("--source", "-s")
{
app.Command("delete", delete =>
Arity = ArgumentArity.ZeroOrOne,
Description = Strings.Source_Description,
};

private static readonly Option<bool> NonInteractiveOption = new Option<bool>("--non-interactive")
Comment thread
nkolev92 marked this conversation as resolved.
Outdated
{
Arity = ArgumentArity.Zero,
Description = Strings.NonInteractive_Description,
};

private static readonly Option<string> ApiKeyOption = new Option<string>("--api-key", "-k")
{
Arity = ArgumentArity.ZeroOrOne,
Description = Strings.ApiKey_Description,
};

private static readonly Option<bool> NoServiceEndpointOption = new Option<bool>("--no-service-endpoint")
{
Arity = ArgumentArity.Zero,
Description = Strings.NoServiceEndpoint_Description,
};

private static readonly Option<bool> InteractiveOption = new Option<bool>("--interactive")
{
Arity = ArgumentArity.Zero,
Description = Strings.NuGetXplatCommand_Interactive,
};

private static readonly Argument<string> PackageIdArgument = new Argument<string>("PackageId")
{
Arity = ArgumentArity.ExactlyOne,
Description = Strings.Delete_PackageIdAndVersion_Description,
};

private static readonly Argument<string> PackageVersionArgument = new Argument<string>("PackageVersion")
{
Arity = ArgumentArity.ExactlyOne,
Description = Strings.Delete_PackageIdAndVersion_Description,
};

internal static void Register(Command parent, Func<ILoggerWithColor> getLogger)
{
var deleteCmd = new Command("delete", Strings.Delete_Description);

deleteCmd.Options.Add(SourceOption);
deleteCmd.Options.Add(NonInteractiveOption);
deleteCmd.Options.Add(ApiKeyOption);
deleteCmd.Options.Add(NoServiceEndpointOption);
deleteCmd.Options.Add(InteractiveOption);
deleteCmd.Arguments.Add(PackageIdArgument);
deleteCmd.Arguments.Add(PackageVersionArgument);

deleteCmd.SetAction(async (parseResult, cancellationToken) =>
{
delete.Description = Strings.Delete_Description;
delete.HelpOption(XPlatUtility.HelpOption);

delete.Option(
CommandConstants.ForceEnglishOutputOption,
Strings.ForceEnglishOutput_Description,
CommandOptionType.NoValue);

var source = delete.Option(
"-s|--source <source>",
Strings.Source_Description,
CommandOptionType.SingleValue);

var nonInteractive = delete.Option(
"--non-interactive",
Strings.NonInteractive_Description,
CommandOptionType.NoValue);

var apikey = delete.Option(
"-k|--api-key <apiKey>",
Strings.ApiKey_Description,
CommandOptionType.SingleValue);

var arguments = delete.Argument(
"[root]",
Strings.Delete_PackageIdAndVersion_Description,
multipleValues: true);

var noServiceEndpointDescription = delete.Option(
"--no-service-endpoint",
Strings.NoServiceEndpoint_Description,
CommandOptionType.NoValue);

var interactive = delete.Option(
"--interactive",
Strings.NuGetXplatCommand_Interactive,
CommandOptionType.NoValue);

delete.OnExecute(async () =>
{
if (arguments.Values.Count < 2)
{
throw new ArgumentException(Strings.Delete_MissingArguments);
}

string packageId = arguments.Values[0];
string packageVersion = arguments.Values[1];
string sourcePath = source.Value();
string apiKeyValue = apikey.Value();
bool nonInteractiveValue = nonInteractive.HasValue();
bool noServiceEndpoint = noServiceEndpointDescription.HasValue();

DefaultCredentialServiceUtility.SetupDefaultCredentialService(getLogger(), !interactive.HasValue());
string packageId = parseResult.GetValue(PackageIdArgument);
string packageVersion = parseResult.GetValue(PackageVersionArgument);
string sourcePath = parseResult.GetValue(SourceOption);
string apiKeyValue = parseResult.GetValue(ApiKeyOption);
bool nonInteractiveValue = parseResult.GetValue(NonInteractiveOption);
bool noServiceEndpoint = parseResult.GetValue(NoServiceEndpointOption);
bool interactiveValue = parseResult.GetValue(InteractiveOption);

DefaultCredentialServiceUtility.SetupDefaultCredentialService(getLogger(), !interactiveValue);

#pragma warning disable CS0618 // Type or member is obsolete
PackageSourceProvider sourceProvider = new PackageSourceProvider(XPlatUtility.GetSettingsForCurrentWorkingDirectory(), enablePackageSourcesChangedEvent: false);
PackageSourceProvider sourceProvider = new PackageSourceProvider(XPlatUtility.GetSettingsForCurrentWorkingDirectory(), enablePackageSourcesChangedEvent: false);
#pragma warning restore CS0618 // Type or member is obsolete

await DeleteRunner.Run(
sourceProvider.Settings,
sourceProvider,
packageId,
packageVersion,
sourcePath,
apiKeyValue,
nonInteractiveValue,
noServiceEndpoint,
Confirm,
getLogger());

return 0;
});
await DeleteRunner.Run(
sourceProvider.Settings,
sourceProvider,
packageId,
packageVersion,
sourcePath,
apiKeyValue,
nonInteractiveValue,
noServiceEndpoint,
Confirm,
getLogger());

return 0;
});

parent.Subcommands.Add(deleteCmd);
}

private static bool Confirm(string description)
Expand All @@ -103,7 +111,7 @@ private static bool Confirm(string description)
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.ConsoleConfirmMessage, description));
var result = Console.ReadLine();
return result.StartsWith(Strings.ConsoleConfirmMessageAccept, StringComparison.OrdinalIgnoreCase);
return result != null && result.StartsWith(Strings.ConsoleConfirmMessageAccept, StringComparison.OrdinalIgnoreCase);
}
finally
{
Expand Down
Loading