Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Release Notes to new line and indent #2312

Merged
merged 6 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 31 additions & 3 deletions src/AppInstallerCLICore/Workflows/ShowFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Trenly marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
info << ' ' << description << std::endl;
}
Trenly marked this conversation as resolved.
Show resolved Hide resolved
}
auto homepage = manifest.CurrentLocalization.Get<Manifest::Localization::PackageUrl>();
if (!homepage.empty())
Expand Down Expand Up @@ -83,7 +93,16 @@ namespace AppInstaller::CLI::Workflow
auto releaseNotes = manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotes>();
if (!releaseNotes.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotes << ' ' << releaseNotes << 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<Manifest::Localization::ReleaseNotesUrl>();
if (!releaseNotesUrl.empty())
Expand All @@ -93,7 +112,16 @@ namespace AppInstaller::CLI::Workflow
auto installationNotes = manifest.CurrentLocalization.Get<Manifest::Localization::InstallationNotes>();
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<Manifest::Localization::Documentations>();
if (!documentations.empty())
Expand Down
9 changes: 9 additions & 0 deletions src/AppInstallerCommonCore/AppInstallerStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "Public/AppInstallerLogging.h"
#include "Public/AppInstallerSHA256.h"

#include <regex>
Trenly marked this conversation as resolved.
Show resolved Hide resolved

namespace AppInstaller::Utility
{
// Same as std::isspace(char)
Expand Down Expand Up @@ -442,6 +444,13 @@ namespace AppInstaller::Utility
return result;
}

bool RegexFindAndReplace(std::string& inputStr, std::regex pattern, const char* value)
Trenly marked this conversation as resolved.
Show resolved Hide resolved
{
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())
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <string_view>
#include <vector>
#include <regex>

namespace AppInstaller::Utility
{
Expand Down Expand Up @@ -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);

Expand Down