Skip to content

Commit

Permalink
Add table with pinned packages when doing upgrade --include-pinned (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
florelis committed Apr 25, 2023
1 parent a46ef6c commit 9d5cf1c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(UpdateNoPackagesFound);
WINGET_DEFINE_RESOURCE_STRINGID(UpdateNoPackagesFoundReason);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeAvailableForPinned);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockingPinCount);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockedByPinCount);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeDifferentInstallTechnology);
Expand Down
36 changes: 33 additions & 3 deletions src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,16 @@ namespace AppInstaller::CLI::Workflow

std::vector<InstalledPackagesTableLine> lines;
std::vector<InstalledPackagesTableLine> linesForExplicitUpgrade;
std::vector<InstalledPackagesTableLine> linesForPins;

int availableUpgradesCount = 0;

// We will show a line with a summary for skipped and pinned packages at the end.
// The strings suggest using a --include-unknown/pinned argument, so we should
// ensure that the count is 0 when using the arguments.
int packagesWithUnknownVersionSkipped = 0;
int packagesWithUserPinsSkipped = 0;

auto &source = context.Get<Execution::Data::Source>();
bool shouldShowSource = source.IsComposite() && source.GetAvailableSources().size() > 1;

Expand All @@ -755,6 +761,7 @@ namespace AppInstaller::CLI::Workflow
{
auto latestVersion = match.Package->GetLatestAvailableVersion(pinBehavior);
bool updateAvailable = match.Package->IsUpdateAvailable(pinBehavior);
bool updateIsPinned = false;

if (m_onlyShowUpgrades && !context.Args.Contains(Execution::Args::Type::IncludeUnknown) && Utility::Version(installedVersion->GetProperty(PackageVersionProperty::Version)).IsUnknown() && updateAvailable)
{
Expand All @@ -768,8 +775,21 @@ namespace AppInstaller::CLI::Workflow
bool updateAvailableWithoutPins = match.Package->IsUpdateAvailable(PinBehavior::IgnorePins);
if (updateAvailableWithoutPins)
{
++packagesWithUserPinsSkipped;
continue;
// When given the --include-pinned argument, report blocking and gating pins in a separate table.
// Otherwise, simply show a count of them
if (context.Args.Contains(Execution::Args::Type::IncludePinned))
{
updateIsPinned = true;

// Override these so we generate the table line below.
latestVersion = match.Package->GetLatestAvailableVersion(PinBehavior::IgnorePins);
updateAvailable = true;
}
else
{
++packagesWithUserPinsSkipped;
continue;
}
}
}

Expand Down Expand Up @@ -802,7 +822,11 @@ namespace AppInstaller::CLI::Workflow
);

auto pinnedState = ConvertToPinTypeEnum(installedVersion->GetMetadata()[PackageVersionMetadata::PinnedState]);
if (m_onlyShowUpgrades && pinnedState == PinType::PinnedByManifest)
if (updateIsPinned)
{
linesForPins.push_back(std::move(line));
}
else if (m_onlyShowUpgrades && pinnedState == PinType::PinnedByManifest)
{
linesForExplicitUpgrade.push_back(std::move(line));
}
Expand Down Expand Up @@ -839,6 +863,12 @@ namespace AppInstaller::CLI::Workflow
OutputInstalledPackagesTable(context, linesForExplicitUpgrade);
}

if (!linesForPins.empty())
{
context.Reporter.Info() << std::endl << Resource::String::UpgradeBlockedByPinCount(linesForPins.size()) << std::endl;
OutputInstalledPackagesTable(context, linesForPins);
}

if (m_onlyShowUpgrades)
{
if (packagesWithUnknownVersionSkipped > 0)
Expand Down
6 changes: 3 additions & 3 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1684,9 +1684,9 @@ Please specify one of them using the --source option to proceed.</value>
<value>Search failed for: {0}</value>
<comment>{Locked="{0}"} Error message displayed when the user attempts to search for multiple application packages and one of the searches fails. This message is for generic failures, we have more specific messages for when the search returns no results, or when it returns more than one result. {0} is a placeholder replaced by the package name or query.</comment>
</data>
<data name="UpgradeBlockingPinCount" xml:space="preserve">
<value>{0} package(s) have a blocking pin that needs to be removed before upgrade</value>
<comment>{Locked="{0}"} {0} is a placeholder that is replaced by an integer number of packages with blocking pins</comment>
<data name="UpgradeBlockedByPinCount" xml:space="preserve">
<value>{0} package(s) have a pin that needs to be removed before upgrade</value>
<comment>{Locked="{0}"} {0} is a placeholder that is replaced by an integer number of packages with pins that prevent upgrade</comment>
</data>
<data name="IncludePinnedArgumentDescription" xml:space="preserve">
<value>Upgrade packages even if they have a non-blocking pin</value>
Expand Down

0 comments on commit 9d5cf1c

Please sign in to comment.