winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a3bb538760d2e8d29828557e235d73c801a52d30
parent 8e82bfe7fea0326ff22d6c87beab06edb7340175
Author: Kaleb Luedtke <jluedtk@jci.com>
Date:   Fri, 22 Mar 2024 18:21:48 -0500

Remove duplicates from MultiQuery (#4286)


Diffstat:
Msrc/AppInstallerCLICore/Command.cpp | 1+
Msrc/AppInstallerCLICore/ExecutionArgs.h | 20+++++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/AppInstallerCLICore/Command.cpp b/src/AppInstallerCLICore/Command.cpp @@ -613,6 +613,7 @@ namespace AppInstaller::CLI } // Special handling for multi-query arguments: + execArgs.MakeMultiQueryContainUniqueValues(); execArgs.MoveMultiQueryToSingleQueryIfNeeded(); } diff --git a/src/AppInstallerCLICore/ExecutionArgs.h b/src/AppInstallerCLICore/ExecutionArgs.h @@ -220,10 +220,28 @@ namespace AppInstaller::CLI::Execution return types; } + // If the user passes the same value multiple times inside a MultiQuery, operations will be repeated + // Since there currently is not a way to include search options within a MultiQuery, processing duplicates + // does not make sense within a single invocation + void MakeMultiQueryContainUniqueValues() + { + auto itr = m_parsedArgs.find(Type::MultiQuery); + + // If there is not a value in MultiQuery, or there is only one value, it is presumed to be unique + if (itr == m_parsedArgs.end() || itr->second.size() == 1) + { + return; + } + + std::set<std::string> querySet; + std::vector<std::string>& queryStrings = itr->second; + + queryStrings.erase(std::remove_if(queryStrings.begin(), queryStrings.end(), [&](const std::string value) { return !querySet.insert(value).second; }), queryStrings.end()); + } + // If we get a single value for multi-query, we remove the argument and add it back as a single query. // This way the rest of the code can assume that if there is a MultiQuery we will always have multiple values, // and if there is a single one it will be in the Query type. - // This is the only case where we modify the parsed args from user input. void MoveMultiQueryToSingleQueryIfNeeded() { auto itr = m_parsedArgs.find(Type::MultiQuery);