Skip to content

Commit

Permalink
Remove duplicates from MultiQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenly committed Mar 19, 2024
1 parent 256c385 commit a1c2468
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ namespace AppInstaller::CLI
}

// Special handling for multi-query arguments:
execArgs.MakeMultiQueryContainUniqueValues();
execArgs.MoveMultiQueryToSingleQueryIfNeeded();
}

Expand Down
23 changes: 22 additions & 1 deletion src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <string_view>
#include <map>
#include <unordered_set>
#include <vector>

namespace AppInstaller::CLI::Execution
Expand Down Expand Up @@ -218,10 +219,30 @@ 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 already presumed to be unique
if (itr == m_parsedArgs.end() || itr->second.size() == 1)
{
return;
}

std::unordered_set<std::string> queryStrings;
for (auto query : itr->second)
{
queryStrings.insert(query);
}
m_parsedArgs[Type::MultiQuery].assign(queryStrings.begin(), 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);
Expand Down

0 comments on commit a1c2468

Please sign in to comment.