From b8b1ab5f0327c3d7a0417df5cab380161e3d7b76 Mon Sep 17 00:00:00 2001 From: Ryan Fu <69221034+ryfu-msft@users.noreply.github.com> Date: Tue, 2 Aug 2022 15:51:34 -0700 Subject: [PATCH] always prompt for packageId (#288) --- src/WingetCreateCLI/Commands/NewCommand.cs | 39 ++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/WingetCreateCLI/Commands/NewCommand.cs b/src/WingetCreateCLI/Commands/NewCommand.cs index 205ac951..8200c3df 100644 --- a/src/WingetCreateCLI/Commands/NewCommand.cs +++ b/src/WingetCreateCLI/Commands/NewCommand.cs @@ -4,7 +4,6 @@ namespace Microsoft.WingetCreateCLI.Commands { using System; - using System.Collections; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; @@ -149,10 +148,11 @@ public override async Task Execute() do { - if (this.WingetRepoOwner == DefaultWingetRepoOwner && - this.WingetRepo == DefaultWingetRepo) + this.PromptPackageIdentifier(manifests); + + if (this.WingetRepoOwner == DefaultWingetRepoOwner && this.WingetRepo == DefaultWingetRepo) { - if (!await this.PromptPackageIdentifierAndCheckDuplicates(manifests)) + if (await this.IsDuplicatePackageIdentifier(manifests.VersionManifest.PackageIdentifier)) { Console.WriteLine(); Logger.ErrorLocalized(nameof(Resources.PackageIdAlreadyExists_Error)); @@ -340,37 +340,34 @@ private static void PromptInstallerSwitchesForExe(T manifest) } /// - /// Prompts for the package identifier and checks if the package identifier already exists. - /// If the package identifier is valid, the value is applied to the other manifests. + /// Prompts for the package identifier and applies the value to all manifests. /// /// Manifests object model. - /// Boolean value indicating whether the package identifier is valid. - private async Task PromptPackageIdentifierAndCheckDuplicates(Manifests manifests) + private void PromptPackageIdentifier(Manifests manifests) { VersionManifest versionManifest = manifests.VersionManifest; PromptHelper.PromptPropertyAndSetValue(versionManifest, nameof(versionManifest.PackageIdentifier), versionManifest.PackageIdentifier); + manifests.InstallerManifest.PackageIdentifier = versionManifest.PackageIdentifier; + manifests.DefaultLocaleManifest.PackageIdentifier = versionManifest.PackageIdentifier; + } - string exactMatch; + /// + /// Checks if the package identifier already exists in the default winget-pkgs repository. + /// + /// Package identifier string. + /// Boolean value indicating whether the package identifier is a duplicate and already exists. + private async Task IsDuplicatePackageIdentifier(string packageIdentifier) + { try { - exactMatch = await this.GitHubClient.FindPackageId(versionManifest.PackageIdentifier); + string exactMatch = await this.GitHubClient.FindPackageId(packageIdentifier); + return !string.IsNullOrEmpty(exactMatch); } catch (Octokit.RateLimitExceededException) { Logger.ErrorLocalized(nameof(Resources.RateLimitExceeded_Message)); return false; } - - if (!string.IsNullOrEmpty(exactMatch)) - { - return false; - } - else - { - manifests.InstallerManifest.PackageIdentifier = versionManifest.PackageIdentifier; - manifests.DefaultLocaleManifest.PackageIdentifier = versionManifest.PackageIdentifier; - return true; - } } } }