From 947f38d411647a43a9c3f4565f80fdc3bbd7b3b2 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Wed, 6 Jul 2022 17:57:29 -0500 Subject: [PATCH 1/6] Move Release Notes to new line and indent --- src/AppInstallerCLICore/Workflows/ShowFlow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp index 4ca39caca9..54bbd3ac28 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -83,7 +83,8 @@ namespace AppInstaller::CLI::Workflow auto releaseNotes = manifest.CurrentLocalization.Get(); if (!releaseNotes.empty()) { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotes << ' ' << releaseNotes << std::endl; + info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotes << std::endl; + info << " " << std::regex_replace(releaseNotes, std::regex("\n"), "\n ") << std::endl; } auto releaseNotesUrl = manifest.CurrentLocalization.Get(); if (!releaseNotesUrl.empty()) From bf7fbe81d399e4b25b13b69f8bffb25791a8e668 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Jul 2022 13:06:51 -0500 Subject: [PATCH 2/6] Add Function for Regex Replace --- src/AppInstallerCommonCore/AppInstallerStrings.cpp | 9 +++++++++ src/AppInstallerCommonCore/Public/AppInstallerStrings.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/AppInstallerCommonCore/AppInstallerStrings.cpp b/src/AppInstallerCommonCore/AppInstallerStrings.cpp index d09fc0e03c..9098fd61bd 100644 --- a/src/AppInstallerCommonCore/AppInstallerStrings.cpp +++ b/src/AppInstallerCommonCore/AppInstallerStrings.cpp @@ -6,6 +6,8 @@ #include "Public/AppInstallerLogging.h" #include "Public/AppInstallerSHA256.h" +#include + namespace AppInstaller::Utility { // Same as std::isspace(char) @@ -442,6 +444,13 @@ namespace AppInstaller::Utility return result; } + bool RegexFindAndReplace(std::string& inputStr, std::regex pattern, const char* value) + { + bool result = std::regex_search(inputStr, pattern); + inputStr = std::regex_replace(inputStr, pattern, value); + return result; + } + std::wstring ReplaceWhileCopying(std::wstring_view input, std::wstring_view token, std::wstring_view value) { if (token.empty()) diff --git a/src/AppInstallerCommonCore/Public/AppInstallerStrings.h b/src/AppInstallerCommonCore/Public/AppInstallerStrings.h index 140c5b6800..b53c177343 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerStrings.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerStrings.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace AppInstaller::Utility { @@ -149,6 +150,10 @@ namespace AppInstaller::Utility // Returns a value indicating whether a replacement occurred. bool FindAndReplace(std::string& inputStr, std::string_view token, std::string_view value); + // Find pattern in the input string and replace with value. + // Returns a value indicating whether a replacement occurred. + bool RegexFindAndReplace(std::string& inputStr, std::regex pattern, const char* value); + // Replaces the token in the input string with value while copying to a new result. std::wstring ReplaceWhileCopying(std::wstring_view input, std::wstring_view token, std::wstring_view value); From e141a2d331c5b93b424ea522ccb7d7aba50ab835 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Jul 2022 13:07:40 -0500 Subject: [PATCH 3/6] * Check if string multi-line before indenting * Handle other multi-line fields --- .../Workflows/ShowFlow.cpp | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp index 54bbd3ac28..c8a1e59d24 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -8,6 +8,7 @@ using namespace AppInstaller::Repository; using namespace AppInstaller::CLI; +using namespace AppInstaller::Utility; using namespace AppInstaller::Utility::literals; namespace AppInstaller::CLI::Workflow @@ -52,7 +53,16 @@ namespace AppInstaller::CLI::Workflow } if (!description.empty()) { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelDescription << ' ' << description << std::endl; + bool isMultiLine = RegexFindAndReplace(description, std::regex("\n"), "\n "); + info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelDescription; + if (isMultiLine) + { + info << std::endl << " " << description << std::endl; + } + else + { + info << ' ' << description << std::endl; + } } auto homepage = manifest.CurrentLocalization.Get(); if (!homepage.empty()) @@ -83,8 +93,16 @@ namespace AppInstaller::CLI::Workflow auto releaseNotes = manifest.CurrentLocalization.Get(); if (!releaseNotes.empty()) { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotes << std::endl; - info << " " << std::regex_replace(releaseNotes, std::regex("\n"), "\n ") << std::endl; + bool isMultiLine = RegexFindAndReplace(releaseNotes, std::regex("\n"), "\n "); + info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotes; + if (isMultiLine) + { + info << std::endl << " " << releaseNotes << std::endl; + } + else + { + info << ' ' << releaseNotes << std::endl; + } } auto releaseNotesUrl = manifest.CurrentLocalization.Get(); if (!releaseNotesUrl.empty()) @@ -94,7 +112,16 @@ namespace AppInstaller::CLI::Workflow auto installationNotes = manifest.CurrentLocalization.Get(); if (!installationNotes.empty()) { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallationNotes << ' ' << installationNotes << std::endl; + bool isMultiLine = RegexFindAndReplace(installationNotes, std::regex("\n"), "\n "); + info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallationNotes; + if (isMultiLine) + { + info << std::endl << " " << installationNotes << std::endl; + } + else + { + info << ' ' << installationNotes << std::endl; + } } const auto& documentations = manifest.CurrentLocalization.Get(); if (!documentations.empty()) From d6959dbbbb55cd3dd7613042ab70c03c914b10fc Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Jul 2022 13:52:40 -0500 Subject: [PATCH 4/6] Address PR feedback --- .../Workflows/ShowFlow.cpp | 47 +++++++------------ src/AppInstallerCLICore/Workflows/ShowFlow.h | 6 +++ .../AppInstallerStrings.cpp | 9 ---- .../Public/AppInstallerStrings.h | 5 -- 4 files changed, 23 insertions(+), 44 deletions(-) diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp index c8a1e59d24..4f37634c25 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -53,16 +53,7 @@ namespace AppInstaller::CLI::Workflow } if (!description.empty()) { - bool isMultiLine = RegexFindAndReplace(description, std::regex("\n"), "\n "); - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelDescription; - if (isMultiLine) - { - info << std::endl << " " << description << std::endl; - } - else - { - info << ' ' << description << std::endl; - } + ShowMultiLineField(info, Resource::String::ShowLabelDescription, description); } auto homepage = manifest.CurrentLocalization.Get(); if (!homepage.empty()) @@ -93,16 +84,7 @@ namespace AppInstaller::CLI::Workflow auto releaseNotes = manifest.CurrentLocalization.Get(); if (!releaseNotes.empty()) { - bool isMultiLine = RegexFindAndReplace(releaseNotes, std::regex("\n"), "\n "); - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotes; - if (isMultiLine) - { - info << std::endl << " " << releaseNotes << std::endl; - } - else - { - info << ' ' << releaseNotes << std::endl; - } + ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, releaseNotes); } auto releaseNotesUrl = manifest.CurrentLocalization.Get(); if (!releaseNotesUrl.empty()) @@ -112,16 +94,7 @@ namespace AppInstaller::CLI::Workflow auto installationNotes = manifest.CurrentLocalization.Get(); if (!installationNotes.empty()) { - bool isMultiLine = RegexFindAndReplace(installationNotes, std::regex("\n"), "\n "); - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallationNotes; - if (isMultiLine) - { - info << std::endl << " " << installationNotes << std::endl; - } - else - { - info << ' ' << installationNotes << std::endl; - } + ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, installationNotes); } const auto& documentations = manifest.CurrentLocalization.Get(); if (!documentations.empty()) @@ -273,4 +246,18 @@ namespace AppInstaller::CLI::Workflow } table.Complete(); } + + void ShowMultiLineField(AppInstaller::CLI::Execution::OutputStream& outputStream, AppInstaller::StringResource::StringId label, std::string& value) + { + bool isMultiLine = FindAndReplace(value, "\n", "\n "); + outputStream << Execution::ManifestInfoEmphasis << label; + if (isMultiLine) + { + outputStream << std::endl << " "_liv << value << std::endl; + } + else + { + outputStream << ' ' << value << std::endl; + } + } } \ No newline at end of file diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.h b/src/AppInstallerCLICore/Workflows/ShowFlow.h index 58515e6796..ffc8d3e129 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.h +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.h @@ -34,4 +34,10 @@ namespace AppInstaller::CLI::Workflow // Inputs: SearchResult [only operates on first match] // Outputs: None void ShowAppVersions(Execution::Context& context); + + // Shows a manifest field, indenting if the field-value contains multiple lines + // Required Args: None + // Inputs: Label, Field Value + // Outputs: None + void ShowMultiLineField(AppInstaller::CLI::Execution::OutputStream& outputStream, AppInstaller::StringResource::StringId label, std::string& value); } \ No newline at end of file diff --git a/src/AppInstallerCommonCore/AppInstallerStrings.cpp b/src/AppInstallerCommonCore/AppInstallerStrings.cpp index 9098fd61bd..d09fc0e03c 100644 --- a/src/AppInstallerCommonCore/AppInstallerStrings.cpp +++ b/src/AppInstallerCommonCore/AppInstallerStrings.cpp @@ -6,8 +6,6 @@ #include "Public/AppInstallerLogging.h" #include "Public/AppInstallerSHA256.h" -#include - namespace AppInstaller::Utility { // Same as std::isspace(char) @@ -444,13 +442,6 @@ namespace AppInstaller::Utility return result; } - bool RegexFindAndReplace(std::string& inputStr, std::regex pattern, const char* value) - { - bool result = std::regex_search(inputStr, pattern); - inputStr = std::regex_replace(inputStr, pattern, value); - return result; - } - std::wstring ReplaceWhileCopying(std::wstring_view input, std::wstring_view token, std::wstring_view value) { if (token.empty()) diff --git a/src/AppInstallerCommonCore/Public/AppInstallerStrings.h b/src/AppInstallerCommonCore/Public/AppInstallerStrings.h index b53c177343..140c5b6800 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerStrings.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerStrings.h @@ -6,7 +6,6 @@ #include #include #include -#include namespace AppInstaller::Utility { @@ -150,10 +149,6 @@ namespace AppInstaller::Utility // Returns a value indicating whether a replacement occurred. bool FindAndReplace(std::string& inputStr, std::string_view token, std::string_view value); - // Find pattern in the input string and replace with value. - // Returns a value indicating whether a replacement occurred. - bool RegexFindAndReplace(std::string& inputStr, std::regex pattern, const char* value); - // Replaces the token in the input string with value while copying to a new result. std::wstring ReplaceWhileCopying(std::wstring_view input, std::wstring_view token, std::wstring_view value); From 25f797b059c14ad0cd1541f702c6061654f7af3f Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Jul 2022 14:02:13 -0500 Subject: [PATCH 5/6] Cleanup --- src/AppInstallerCLICore/Workflows/ShowFlow.cpp | 2 +- src/AppInstallerCLICore/Workflows/ShowFlow.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp index 4f37634c25..457113d751 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -247,7 +247,7 @@ namespace AppInstaller::CLI::Workflow table.Complete(); } - void ShowMultiLineField(AppInstaller::CLI::Execution::OutputStream& outputStream, AppInstaller::StringResource::StringId label, std::string& value) + void ShowMultiLineField(Execution::OutputStream& outputStream, StringResource::StringId label, std::string& value) { bool isMultiLine = FindAndReplace(value, "\n", "\n "); outputStream << Execution::ManifestInfoEmphasis << label; diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.h b/src/AppInstallerCLICore/Workflows/ShowFlow.h index ffc8d3e129..2611081c00 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.h +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.h @@ -39,5 +39,5 @@ namespace AppInstaller::CLI::Workflow // Required Args: None // Inputs: Label, Field Value // Outputs: None - void ShowMultiLineField(AppInstaller::CLI::Execution::OutputStream& outputStream, AppInstaller::StringResource::StringId label, std::string& value); + void ShowMultiLineField(Execution::OutputStream& outputStream, StringResource::StringId label, std::string& value); } \ No newline at end of file From 7c527f123184be741d26094c8d8dab17367c29cd Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Jul 2022 18:50:10 -0500 Subject: [PATCH 6/6] Move function to anonymous namespace + remove from header --- .../Workflows/ShowFlow.cpp | 30 ++++++++++--------- src/AppInstallerCLICore/Workflows/ShowFlow.h | 6 ---- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp index 457113d751..4127834a0f 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -11,6 +11,22 @@ using namespace AppInstaller::CLI; using namespace AppInstaller::Utility; using namespace AppInstaller::Utility::literals; +namespace { + void ShowMultiLineField(Execution::OutputStream& outputStream, AppInstaller::StringResource::StringId label, std::string& value) + { + bool isMultiLine = FindAndReplace(value, "\n", "\n "); + outputStream << Execution::ManifestInfoEmphasis << label; + if (isMultiLine) + { + outputStream << std::endl << " "_liv << value << std::endl; + } + else + { + outputStream << ' ' << value << std::endl; + } + } +} + namespace AppInstaller::CLI::Workflow { void ShowManifestInfo(Execution::Context& context) @@ -246,18 +262,4 @@ namespace AppInstaller::CLI::Workflow } table.Complete(); } - - void ShowMultiLineField(Execution::OutputStream& outputStream, StringResource::StringId label, std::string& value) - { - bool isMultiLine = FindAndReplace(value, "\n", "\n "); - outputStream << Execution::ManifestInfoEmphasis << label; - if (isMultiLine) - { - outputStream << std::endl << " "_liv << value << std::endl; - } - else - { - outputStream << ' ' << value << std::endl; - } - } } \ No newline at end of file diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.h b/src/AppInstallerCLICore/Workflows/ShowFlow.h index 2611081c00..58515e6796 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.h +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.h @@ -34,10 +34,4 @@ namespace AppInstaller::CLI::Workflow // Inputs: SearchResult [only operates on first match] // Outputs: None void ShowAppVersions(Execution::Context& context); - - // Shows a manifest field, indenting if the field-value contains multiple lines - // Required Args: None - // Inputs: Label, Field Value - // Outputs: None - void ShowMultiLineField(Execution::OutputStream& outputStream, StringResource::StringId label, std::string& value); } \ No newline at end of file