mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor parsing of remappings to remove duplication and improve readability
This commit is contained in:
+15
-14
@@ -338,11 +338,17 @@ bool CommandLineParser::parseInputPathsAndRemappings()
|
||||
m_options.input.ignoreMissingFiles = (m_args.count(g_strIgnoreMissingFiles) > 0);
|
||||
|
||||
if (m_args.count(g_strInputFile))
|
||||
for (string path: m_args[g_strInputFile].as<vector<string>>())
|
||||
for (string const& positionalArg: m_args[g_strInputFile].as<vector<string>>())
|
||||
{
|
||||
auto eq = find(path.begin(), path.end(), '=');
|
||||
if (eq != path.end())
|
||||
if (ImportRemapper::isRemapping(positionalArg))
|
||||
{
|
||||
optional<ImportRemapper::Remapping> remapping = ImportRemapper::parseRemapping(positionalArg);
|
||||
if (!remapping.has_value())
|
||||
{
|
||||
serr() << "Invalid remapping: \"" << positionalArg << "\"." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_options.input.mode == InputMode::StandardJson)
|
||||
{
|
||||
serr() << "Import remappings are not accepted on the command line in Standard JSON mode." << endl;
|
||||
@@ -350,21 +356,16 @@ bool CommandLineParser::parseInputPathsAndRemappings()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auto r = ImportRemapper::parseRemapping(path))
|
||||
m_options.input.remappings.emplace_back(std::move(*r));
|
||||
else
|
||||
{
|
||||
serr() << "Invalid remapping: \"" << path << "\"." << endl;
|
||||
return false;
|
||||
}
|
||||
boost::filesystem::path remappingDir = remapping->target;
|
||||
remappingDir.remove_filename();
|
||||
m_options.input.allowedDirectories.insert(remappingDir);
|
||||
|
||||
string remappingTarget(eq + 1, path.end());
|
||||
m_options.input.allowedDirectories.insert(boost::filesystem::path(remappingTarget).remove_filename());
|
||||
m_options.input.remappings.emplace_back(move(remapping.value()));
|
||||
}
|
||||
else if (path == "-")
|
||||
else if (positionalArg == "-")
|
||||
m_options.input.addStdin = true;
|
||||
else
|
||||
m_options.input.paths.insert(path);
|
||||
m_options.input.paths.insert(positionalArg);
|
||||
}
|
||||
|
||||
if (m_options.input.mode == InputMode::StandardJson)
|
||||
|
||||
Reference in New Issue
Block a user