[Settings] Add sort field and direction types for output ordering#6176
[Settings] Add sort field and direction types for output ordering#6176Madhusudhan-MSFT wants to merge 4 commits intomicrosoft:masterfrom
Conversation
…gs infrastructure ## Summary Introduce configurable output sorting for `winget list` as part of issue the sorting feature request. This is part 1 of a 3-PR stack that lays the type system and settings foundation without changing any runtime behavior. ## Changes - **SortField and SortDirection enums**: Add `SortField` (Relevance, Name, Id, Version, Source, Available) and `SortDirection` (Ascending, Descending) to the settings type system. Relevance is internal-only and not exposed as a valid settings value. - **Settings entries**: Register `OutputSortOrder` and `OutputSortDirection` with typed validation that maps JSON string values to enums using case-insensitive comparison. Default sort order is `[Name]` ascending. Invalid field names reject the entire setting and fall back to default. - **JSON schema**: Extend `settings.schema.0.2.json` with an `output` section containing `sortOrder` (string array) and `sortDirection` (string enum with ascending default). - **Unit tests**: Add 16 test sections covering default values, single and multi-field configurations, case insensitivity, empty array (disables sorting), invalid fields, mixed valid/invalid, and wrong JSON types. ## Impact - No behavioral change ╬ô├ç├╢ settings are defined but not yet consumed by any command or workflow. Existing `winget list` output remains unchanged. - Users who edit `settings.json` to add `output.sortOrder` or `output.sortDirection` will have their values validated and stored, but the values will not take effect until PR3 wires the sort logic. ## How Validated - Unit tests added (16 test sections across SettingOutputSortOrder and SettingOutputSortDirection test cases) - Compilation verified via msbuild for AppInstallerCommonCore and AppInstallerCLITests (compile-only)
…dators Follow established codebase pattern (NetworkDownloader, LoggingLevel) of declaring static constexpr std::string_view variables for string comparisons instead of inline string literals.
Is there a reason not to expose this? It feels like some users may specifically want this like if they want to sort by Source then by Relevance |
| REQUIRE(sortOrder[0] == SortField::Name); | ||
| REQUIRE(userSettingTest.GetWarnings().size() == 1); | ||
| } | ||
| SECTION("Wrong type - number in array") |
There was a problem hiding this comment.
I'd also appreciate a test case for duplicate values, something like ["name", "id", "Name"]
Add test case verifying behavior when duplicate field names appear in sortOrder settings (e.g., ["name", "id", "Name"]). Duplicates are accepted and preserved — case-insensitive matching maps both "name" and "Name" to SortField::Name. Addresses reviewer feedback from PR microsoft#6176.
This comment has been minimized.
This comment has been minimized.
Add test case verifying behavior when duplicate field names appear in sortOrder settings (e.g., ["name", "id", "Name"]). Duplicates are accepted and preserved — case-insensitive matching maps both "name" and "Name" to SortField::Name. Addresses reviewer feedback from PR microsoft#6176.
ec489c4 to
184cacd
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
|
Sorry, misclick... |
|
Good question @Trenly —
If we were to expose it, it would only make sense as the sole value (e.g., @denelon — would you like us to expose |
|
I like the idea of exposing "relevance" since someone might want to have that documented and be able to put it in their settings. |
… relevance, lowercase-once - Change OutputSortOrder default from [Name] to empty vector (sentinel for context-aware defaults: relevance when query, Name when no query) - Make Relevance a publicly visible sort field in settings and schema - Refactor OutputSortOrder validator to ToLower once then compare with == - Update tests for new default, add relevance field test section
I suppose it depends on the use case? The 'Source -> Relevance' one makes sense to me, since you may want that as opposed to Take, for example, the case where I do
|
|
Closing in favor of #6177 which now includes all changes from this PR plus the CLI argument registration. Reviewer feedback to consolidate into a single PR. |
|
This PR has been closed. All changes have been consolidated into PR #6177. |
Summary
Add settings infrastructure for configurable output sorting in
winget list. This ispart 1 of a 3-part stack that lays the type system and settings foundation without
changing any runtime behavior.
Part of #4238
Changes
SortField(Relevance, Name, Id, Version,Source, Available) and
SortDirection(Ascending, Descending) to the settings typesystem. Relevance is internal-only and not exposed as a valid settings value.
OutputSortOrderandOutputSortDirectionwith typedvalidation that maps JSON string values to enums using case-insensitive comparison.
Default sort order is
[Name]ascending. Invalid field names reject the entiresetting and fall back to default.
settings.schema.0.2.jsonwith anoutputsection containingsortOrder(string array) andsortDirection(string enum with ascending default).follow the established
static constexpr std::string_viewpattern used byNetworkDownloader,LoggingLevelPreference, and other existing validators.Impact
workflow. Existing
winget listoutput remains unchanged.settings.jsonto addoutput.sortOrderoroutput.sortDirectionwill have their values validated and stored, but the values will not take effect
until the sort logic is wired in a follow-up PR.
How Validated
SettingOutputSortOrderandSettingOutputSortDirectiontest cases covering default values, single and multi-fieldconfigurations, case insensitivity, empty array, invalid fields, mixed valid/invalid,
and wrong JSON types (62 assertions total).
Follow-up
This PR is part 1 of a 3-PR stack:
--sort,--ascending,--descending)ConvertToSortFieldshared parser, and comprehensive testsMicrosoft Reviewers: Open in CodeFlow