winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit f66b390b92ca2b2203c1f9c3f28def8a8e4a8634
parent 45a3867c7c2425edc1805265a6e29371170a3e45
Author: Kaleb Luedtke <jluedtk@jci.com>
Date:   Tue, 23 Aug 2022 15:31:54 -0500

Show PurchaseUrl if present in manifest (#2416)


Diffstat:
Msrc/AppInstallerCLICore/Resources.h | 1+
Msrc/AppInstallerCLICore/Workflows/ShowFlow.cpp | 189++++++++++++++++++++++++++++++++-----------------------------------------------
Msrc/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw | 3+++
3 files changed, 80 insertions(+), 113 deletions(-)

diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h @@ -299,6 +299,7 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPublisher); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPublisherSupportUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPublisherUrl); + WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPurchaseUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelReleaseNotes); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelReleaseNotesUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelTags); diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -12,17 +12,57 @@ using namespace AppInstaller::Utility; using namespace AppInstaller::Utility::literals; namespace { - void ShowMultiLineField(Execution::OutputStream& outputStream, AppInstaller::StringResource::StringId label, std::string& value) + + template <typename String> + void ShowSingleLineField(Execution::OutputStream outputStream, AppInstaller::StringResource::StringId label, const String& value, bool indent = false) + { + if (value.empty()) + { + return; + } + if (indent) + { + outputStream << " "_liv; + } + outputStream << Execution::ManifestInfoEmphasis << label << ' ' << value << std::endl; + } + + template <typename String> + void ShowMultiLineField(Execution::OutputStream outputStream, AppInstaller::StringResource::StringId label, const String& value) { - bool isMultiLine = FindAndReplace(value, "\n", "\n "); + if (value.empty()) + { + return; + } + /* + We need to be able to find and replace within the string.However, we don't want to own the original string + Therefore, a copy is created here so we can manipulate it. The memory should be freed again once this method + returns and the string is no longer in scope. + */ + std::string shownValue = value; + bool isMultiLine = FindAndReplace(shownValue, "\n", "\n "); outputStream << Execution::ManifestInfoEmphasis << label; if (isMultiLine) { - outputStream << std::endl << " "_liv << value << std::endl; + outputStream << std::endl << " "_liv << shownValue << std::endl; } else { - outputStream << ' ' << value << std::endl; + outputStream << ' ' << shownValue << std::endl; + } + } + + template <typename Enumerable> + void ShowMultiValueField(Execution::OutputStream outputStream, AppInstaller::StringResource::StringId label, const Enumerable& values) + { + if (values.empty()) + { + return; + } + outputStream << Execution::ManifestInfoEmphasis << label << std::endl; + for (const auto& value : values) + { + outputStream << " "_liv << value << std::endl; } } } @@ -38,80 +78,27 @@ namespace AppInstaller::CLI::Workflow { const auto& manifest = context.Get<Execution::Data::Manifest>(); auto info = context.Reporter.Info(); + // Get description from manifest so we can see if it is empty later + auto description = manifest.CurrentLocalization.Get<Manifest::Localization::Description>(); // TODO: Come up with a prettier format - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelVersion << ' ' << manifest.Version << std::endl; - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisher << ' ' << manifest.CurrentLocalization.Get<Manifest::Localization::Publisher>() << std::endl; - auto publisherUrl = manifest.CurrentLocalization.Get<Manifest::Localization::PublisherUrl>(); - if (!publisherUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisherUrl << ' ' << publisherUrl << std::endl; - } - auto publisherSupportUrl = manifest.CurrentLocalization.Get<Manifest::Localization::PublisherSupportUrl>(); - if (!publisherSupportUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisherSupportUrl << ' ' << publisherSupportUrl << std::endl; - } - auto author = manifest.CurrentLocalization.Get<Manifest::Localization::Author>(); - if (!author.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelAuthor << ' ' << author << std::endl; - } - if (!manifest.Moniker.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelMoniker << ' ' << manifest.Moniker << std::endl; - } - auto description = manifest.CurrentLocalization.Get<Manifest::Localization::Description>(); - if (description.empty()) - { - // Fall back to short description - description = manifest.CurrentLocalization.Get<Manifest::Localization::ShortDescription>(); - } - if (!description.empty()) - { - ShowMultiLineField(info, Resource::String::ShowLabelDescription, description); - } - auto homepage = manifest.CurrentLocalization.Get<Manifest::Localization::PackageUrl>(); - if (!homepage.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPackageUrl << ' ' << homepage << std::endl; - } - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelLicense << ' ' << manifest.CurrentLocalization.Get<Manifest::Localization::License>() << std::endl; - auto licenseUrl = manifest.CurrentLocalization.Get<Manifest::Localization::LicenseUrl>(); - if (!licenseUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelLicenseUrl << ' ' << licenseUrl << std::endl; - } - auto privacyUrl = manifest.CurrentLocalization.Get<Manifest::Localization::PrivacyUrl>(); - if (!privacyUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPrivacyUrl << ' ' << privacyUrl << std::endl; - } - auto copyright = manifest.CurrentLocalization.Get<Manifest::Localization::Copyright>(); - if (!copyright.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelCopyright << ' ' << copyright << std::endl; - } - auto copyrightUrl = manifest.CurrentLocalization.Get<Manifest::Localization::CopyrightUrl>(); - if (!copyrightUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelCopyrightUrl << ' ' << copyrightUrl << std::endl; - } - auto releaseNotes = manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotes>(); - if (!releaseNotes.empty()) - { - ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, releaseNotes); - } - auto releaseNotesUrl = manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotesUrl>(); - if (!releaseNotesUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotesUrl << ' ' << releaseNotesUrl << std::endl; - } - auto installationNotes = manifest.CurrentLocalization.Get<Manifest::Localization::InstallationNotes>(); - if (!installationNotes.empty()) - { - ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, installationNotes); - } + ShowSingleLineField(info, Resource::String::ShowLabelVersion, manifest.Version); + ShowSingleLineField(info, Resource::String::ShowLabelPublisher, manifest.CurrentLocalization.Get<Manifest::Localization::Publisher>()); + ShowSingleLineField(info, Resource::String::ShowLabelPublisherUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherUrl>()); + ShowSingleLineField(info, Resource::String::ShowLabelPublisherSupportUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherSupportUrl>()); + ShowSingleLineField(info, Resource::String::ShowLabelAuthor, manifest.CurrentLocalization.Get<Manifest::Localization::Author>()); + ShowSingleLineField(info, Resource::String::ShowLabelMoniker, manifest.Moniker); + ShowMultiLineField(info, Resource::String::ShowLabelDescription, description.empty() ? manifest.CurrentLocalization.Get<Manifest::Localization::ShortDescription>() : description); + ShowSingleLineField(info, Resource::String::ShowLabelPackageUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PackageUrl>()); + ShowSingleLineField(info, Resource::String::ShowLabelLicense, manifest.CurrentLocalization.Get<Manifest::Localization::License>()); + ShowSingleLineField(info, Resource::String::ShowLabelLicenseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::LicenseUrl>()); + ShowSingleLineField(info, Resource::String::ShowLabelPrivacyUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PrivacyUrl>()); + ShowSingleLineField(info, Resource::String::ShowLabelCopyright, manifest.CurrentLocalization.Get<Manifest::Localization::Copyright>()); + ShowSingleLineField(info, Resource::String::ShowLabelCopyrightUrl, manifest.CurrentLocalization.Get<Manifest::Localization::CopyrightUrl>()); + ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotes>()); + ShowSingleLineField(info, Resource::String::ShowLabelReleaseNotesUrl, manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotesUrl>()); + ShowSingleLineField(info, Resource::String::ShowLabelPurchaseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PurchaseUrl>()); + ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, manifest.CurrentLocalization.Get<Manifest::Localization::InstallationNotes>()); const auto& documentations = manifest.CurrentLocalization.Get<Manifest::Localization::Documentations>(); if (!documentations.empty()) { @@ -130,15 +117,7 @@ namespace AppInstaller::CLI::Workflow } } } - const auto& tags = manifest.CurrentLocalization.Get<Manifest::Localization::Tags>(); - if (!tags.empty()) - { - context.Reporter.Info() << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelTags << std::endl; - for (const auto& tag : tags) - { - info << " "_liv << tag << std::endl; - } - } + ShowMultiValueField(info, Resource::String::ShowLabelTags, manifest.CurrentLocalization.Get<Manifest::Localization::Tags>()); const auto& agreements = manifest.CurrentLocalization.Get<Manifest::Localization::Agreements>(); if (!agreements.empty()) { @@ -175,36 +154,20 @@ namespace AppInstaller::CLI::Workflow { Manifest::InstallerTypeEnum effectiveInstallerType = installer->EffectiveInstallerType(); Manifest::InstallerTypeEnum baseInstallerType = installer->BaseInstallerType; - if (effectiveInstallerType == baseInstallerType) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerType << ' ' << Manifest::InstallerTypeToString(effectiveInstallerType) << std::endl; - } - else - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerType << ' ' << Manifest::InstallerTypeToString(effectiveInstallerType) << " (" << - Manifest::InstallerTypeToString(baseInstallerType) << ')' << std::endl; - } - - if (!installer->Locale.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerLocale << ' ' << installer->Locale << std::endl; - } - if (!installer->Url.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerUrl << ' ' << installer->Url << std::endl; - } - if (!installer->Sha256.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerSha256 << ' ' << Utility::SHA256::ConvertToString(installer->Sha256) << std::endl; - } - if (!installer->ProductId.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerProductId << ' ' << installer->ProductId << std::endl; - } - if (!installer->ReleaseDate.empty()) + std::string shownInstallerType; + shownInstallerType = Manifest::InstallerTypeToString(effectiveInstallerType); + if (effectiveInstallerType != baseInstallerType) { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerReleaseDate << ' ' << installer->ReleaseDate << std::endl; + shownInstallerType += " ("_liv; + shownInstallerType += Manifest::InstallerTypeToString(baseInstallerType); + shownInstallerType += ')'; } + ShowSingleLineField(info, Resource::String::ShowLabelInstallerType, shownInstallerType, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerLocale, installer->Locale, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerUrl, installer->Url, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerSha256, (installer->Sha256.empty()) ? "" : Utility::SHA256::ConvertToString(installer->Sha256), true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerProductId, installer->ProductId, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerReleaseDate, installer->ReleaseDate, true); if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies)) { diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -1127,6 +1127,9 @@ Do you agree to the terms?</value> <data name="ShowLabelPublisherUrl" xml:space="preserve"> <value>Publisher Url:</value> </data> + <data name="ShowLabelPurchaseUrl" xml:space="preserve"> + <value>Purchase Url:</value> + </data> <data name="ShowLabelPublisherSupportUrl" xml:space="preserve"> <value>Publisher Support Url:</value> </data>