Skip to content

Commit a7c35a4

Browse files
committed
(maint) Add optional warning control to GetSortOrder method
Modify GetSortOrder to accept an outputWarnings parameter that controls whether client-side ordering warnings are logged. This prevents unwanted warnings when output is suppressed, improving user experience during quiet or non-regular output scenarios. Update all callers accordingly.
1 parent d0e413f commit a7c35a4

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/chocolatey.tests/infrastructure.app/services/NugetListSpecs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ protected IOrderedEnumerable<IPackageSearchMetadata> SortPackages(
5858
new object[] { packages, orderBy });
5959
}
6060

61-
protected SearchOrderBy? GetSortOrder(PackageOrder orderBy, bool useMultiVersionOrdering)
61+
protected SearchOrderBy? GetSortOrder(PackageOrder orderBy, bool useMultiVersionOrdering, bool outputWarnings = true)
6262
{
6363
return InvokeStaticMethod<SearchOrderBy?>(
6464
typeof(NugetList),
6565
"GetSortOrder",
66-
new object[] { orderBy, useMultiVersionOrdering });
66+
new object[] { orderBy, useMultiVersionOrdering, outputWarnings });
6767
}
6868
}
6969

src/chocolatey/infrastructure.app/nuget/NugetList.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static int GetCount(ChocolateyConfiguration configuration, ILogger nugetL
5555
var searchFilter = new SearchFilter(configuration.Prerelease)
5656
{
5757
IncludeDelisted = configuration.ListCommand.LocalOnly,
58-
OrderBy = GetSortOrder(configuration.ListCommand.OrderBy, configuration.AllVersions)
58+
OrderBy = GetSortOrder(configuration.ListCommand.OrderBy, configuration.AllVersions, configuration.RegularOutput && !configuration.QuietOutput)
5959
};
6060

6161
var totalCount = 0;
@@ -81,7 +81,7 @@ private async static Task<IQueryable<IPackageSearchMetadata>> SearchPackagesAsyn
8181
var searchFilter = new SearchFilter(configuration.Prerelease)
8282
{
8383
IncludeDelisted = configuration.ListCommand.LocalOnly,
84-
OrderBy = GetSortOrder(configuration.ListCommand.OrderBy, configuration.AllVersions || !(version is null))
84+
OrderBy = GetSortOrder(configuration.ListCommand.OrderBy, configuration.AllVersions || !(version is null), configuration.RegularOutput && !configuration.QuietOutput)
8585
};
8686

8787
if (configuration.ListCommand.ByIdOnly)
@@ -492,7 +492,7 @@ private static IOrderedEnumerable<IPackageSearchMetadata> ApplyPackageSort(IEnum
492492
}
493493
}
494494

495-
private static SearchOrderBy? GetSortOrder(domain.PackageOrder orderBy, bool useMultiVersionOrdering)
495+
private static SearchOrderBy? GetSortOrder(domain.PackageOrder orderBy, bool useMultiVersionOrdering, bool outputWarnings)
496496
{
497497
switch (orderBy)
498498
{
@@ -536,11 +536,13 @@ private static IOrderedEnumerable<IPackageSearchMetadata> ApplyPackageSort(IEnum
536536
// Ideally, server-side ordering would be supported, but the current
537537
// NuGet client libraries do not yet provide this capability.
538538

539-
540-
"chocolatey".Log().Warn(
541-
@"OrderBy '{0}' is applied on the client side. Because results are paged by the
539+
if (outputWarnings)
540+
{
541+
"chocolatey".Log().Warn(
542+
@"OrderBy '{0}' is applied on the client side. Because results are paged by the
542543
server, this may lead to inconsistent ordering.",
543-
orderBy);
544+
orderBy);
545+
}
544546

545547
if (useMultiVersionOrdering)
546548
{

0 commit comments

Comments
 (0)