public async Task <int> InvokeAsync(InvocationContext context) { var apiKey = context.ParseResult.ValueForOption(CommonOptions.ApiKeyOption); var packageId = context.ParseResult.ValueForOption(CommonOptions.PackageIdOption); var hasPreRelease = context.ParseResult.Tokens.Any(t => CommonOptions.PreReleaseOption.Aliases.Contains(t.Value)); var preRelease = hasPreRelease ? context.ParseResult.ValueForOption(CommonOptions.PreReleaseOption) : (bool?)null; var skipLatestPreRelease = context.ParseResult.ValueForOption(CommonOptions.SkipLatestPreReleaseOption); var skipLatestStable = context.ParseResult.ValueForOption(CommonOptions.SkipLatestStableOption); var confirm = context.ParseResult.ValueForOption(CommonOptions.ConfirmOption); var searchResult = await this.nugetClient.SearchAsync(packageId, preRelease, skipLatestStable, skipLatestPreRelease); var count = searchResult.Data.Sum(d => d.Versions.Count); if (count > 0) { if (!confirm) { var searchResultLogMessage = new StringBuilder(); foreach (var data in searchResult.Data) { foreach (var version in data.Versions) { searchResultLogMessage.AppendLine($"{data.Title} {version.Version}"); } } this.logger.LogInformation(searchResultLogMessage.ToString()); } if (confirm || await Interactive.Confirmation($"Do you want to unlist {count} package{(count > 1 ? "s" : "")}?", "yes", "no")) { foreach (var data in searchResult.Data) { foreach (var version in data.Versions) { try { await this.nugetClient.DeletePackageAsync(apiKey, packageId, version.Version); } catch (Exception ex) { this.logger.LogError($"Failed to delete package: {ex.Message}"); } } } } } else { this.logger.LogWarning($"No packages found for {CommonOptions.PackageIdOption.Aliases.First()}={packageId}, {CommonOptions.PreReleaseOption.Aliases.First()}={preRelease}"); } return(0); }
public async Task <int> InvokeAsync(InvocationContext context) { var apiKey = context.ParseResult.ValueForOption(CommonOptions.ApiKeyOption); var packageId = context.ParseResult.ValueForOption(CommonOptions.PackageIdOption); var versionsString = context.ParseResult.ValueForOption(CommonOptions.VersionsOption); var versions = versionsString?.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? new string[0] { }; var confirm = context.ParseResult.ValueForOption(CommonOptions.ConfirmOption); var count = versions.Length; if (count > 0) { if (!confirm) { var searchResultLogMessage = new StringBuilder(); foreach (var version in versions) { searchResultLogMessage.AppendLine($"{packageId} {version}"); } this.logger.LogInformation(searchResultLogMessage.ToString()); } if (confirm || await Interactive.Confirmation($"Do you want to relist {count} package{(count > 1 ? "s" : "")}?", "yes", "no")) { foreach (var version in versions) { try { await this.nugetClient.RelistPackageAsync(apiKey, packageId, version); } catch (Exception ex) { this.logger.LogError($"Failed to relist package: {ex.Message}"); } } } } else { this.logger.LogWarning($"No packages found in parameter {CommonOptions.VersionsOption.Aliases.First()}."); } return(0); }