in src/vswhere.lib/CommandArgs.cpp [47:216]
void CommandArgs::Parse(_In_ vector<CommandParser::Token> args)
{
bool hasSelection = false;
for (auto it = args.begin(); it != args.end(); ++it)
{
auto& arg = *it;
// No unspecified arguments supported.
if (CommandParser::Token::eParameter != arg.Type)
{
auto message = ResourceManager::GetString(IDS_E_ARGEXPECTED);
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
if (ArgumentEquals(arg.Value, L"all"))
{
m_all = true;
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"products"))
{
ParseArgumentArray(it, args.end(), arg, m_products);
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"requires"))
{
ParseArgumentArray(it, args.end(), arg, m_requires);
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"requiresAny"))
{
m_requiresAny = true;
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"version"))
{
m_version = ParseArgument(it, args.end(), arg);
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"latest"))
{
m_latest = true;
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"sort"))
{
m_sort = true;
}
else if (ArgumentEquals(arg.Value, L"legacy"))
{
m_legacy = true;
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"path"))
{
m_path = ParseArgument(it, args.end(), arg);
}
else if (ArgumentEquals(arg.Value, L"prerelease"))
{
m_prerelease = true;
hasSelection = true;
}
else if (ArgumentEquals(arg.Value, L"format"))
{
auto format = ParseArgument(it, args.end(), arg);
auto formatterIt = Formatter::Formatters.find(format);
if (formatterIt != Formatter::Formatters.end())
{
m_format = format;
}
else
{
auto message = ResourceManager::FormatString(IDS_E_INVALIDFORMAT, format.c_str());
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
}
else if (ArgumentEquals(arg.Value, L"property"))
{
if (m_find.length())
{
auto message = ResourceManager::FormatString(IDS_E_ARGINCOMPAT, L"property", L"find");
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
m_property = ParseArgument(it, args.end(), arg);
}
else if (ArgumentEquals(arg.Value, L"include"))
{
vector<wstring> include;
ParseArgumentArray(it, args.end(), arg, include);
for (const auto& value : include)
{
if (ArgumentEquals(value, L"packages"))
{
m_includePackages = true;
}
else
{
auto message = ResourceManager::FormatString(IDS_E_UNSUPPORTEDARG, value.c_str(), L"include");
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
}
}
else if (ArgumentEquals(arg.Value, L"find"))
{
if (m_property.length())
{
auto message = ResourceManager::FormatString(IDS_E_ARGINCOMPAT, L"find", L"property");
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
m_find = ParseArgument(it, args.end(), arg);
}
else if (ArgumentEquals(arg.Value, L"nocolor"))
{
m_nocolor = true;
}
else if (ArgumentEquals(arg.Value, L"nologo"))
{
m_nologo = true;
}
else if (ArgumentEquals(arg.Value, L"utf8"))
{
m_utf8 = true;
}
else if (ArgumentEquals(arg.Value, L"?")
|| ArgumentEquals(arg.Value, L"h")
|| ArgumentEquals(arg.Value, L"help"))
{
m_help = true;
}
else
{
auto message = ResourceManager::FormatString(IDS_E_UNKNOWNPARAM, arg.Value.c_str());
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
}
// Clear the products array with asterisk to find any product.
auto it = find(m_products.begin(), m_products.end(), wstring(L"*"));
if (it != m_products.end())
{
m_productsAll = true;
m_products.clear();
}
if (m_legacy)
{
if (!m_products.empty() || !m_requires.empty())
{
auto message = ResourceManager::GetString(IDS_E_LEGACY);
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
}
if ((m_property.length() || m_find.length()) && m_format.empty())
{
m_format = L"value";
}
if (hasSelection && !m_path.empty())
{
auto message = ResourceManager::GetString(IDS_E_PATHINCOMPATIBLE);
throw win32_error(ERROR_INVALID_PARAMETER, message);
}
}