Commit c90f5415 authored by maitesin's avatar maitesin
Browse files

Refactored a piece of code repeted three time. Created a function to replace...

Refactored a piece of code repeted three time. Created a function to replace this duplication of code.
parent 09988d6c
...@@ -54,29 +54,16 @@ bool Mhwd::performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONT ...@@ -54,29 +54,16 @@ bool Mhwd::performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONT
// Print conflicts // Print conflicts
if (!transaction.conflictedConfigs_.empty()) if (!transaction.conflictedConfigs_.empty())
{ {
std::string conflicts;
for (auto&& conflictedConfig : transaction.conflictedConfigs_)
{
conflicts += " " + conflictedConfig->name_;
}
consoleWriter_.printError("config '" + config->name_ + "' conflicts with config(s):" + consoleWriter_.printError("config '" + config->name_ + "' conflicts with config(s):" +
conflicts); gatherConfigContent(transaction.conflictedConfigs_));
return false; return false;
} }
// Print dependencies // Print dependencies
else if (!transaction.dependencyConfigs_.empty()) else if (!transaction.dependencyConfigs_.empty())
{ {
std::string dependencies; consoleWriter_.printStatus("Dependencies to install:" +
gatherConfigContent(transaction.dependencyConfigs_) +
for (auto&& dependencyConfig : transaction.dependencyConfigs_)
{
dependencies += " " + dependencyConfig->name_;
}
consoleWriter_.printStatus("Dependencies to install:" + dependencies +
"\nProceed with installation? [Y/n]"); "\nProceed with installation? [Y/n]");
std::string input; std::string input;
std::getline(std::cin, input); std::getline(std::cin, input);
...@@ -88,15 +75,8 @@ bool Mhwd::performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONT ...@@ -88,15 +75,8 @@ bool Mhwd::performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONT
// Print requirements // Print requirements
if (!transaction.configsRequirements_.empty()) if (!transaction.configsRequirements_.empty())
{ {
std::string requirements;
for (auto&& requirement : transaction.configsRequirements_)
{
requirements += " " + requirement->name_;
}
consoleWriter_.printError("config '" + config->name_ + "' is required by config(s):" + consoleWriter_.printError("config '" + config->name_ + "' is required by config(s):" +
requirements); gatherConfigContent(transaction.configsRequirements_));
return false; return false;
} }
} }
...@@ -1279,3 +1259,13 @@ int Mhwd::launch(int argc, char *argv[]) ...@@ -1279,3 +1259,13 @@ int Mhwd::launch(int argc, char *argv[])
} }
return 0; return 0;
} }
std::string Mhwd::gatherConfigContent(const std::vector<std::shared_ptr<Config>> & configuration) const
{
std::string config;
for (auto&& c : configuration)
{
config += " " + c->name_;
}
return config;
}
\ No newline at end of file
...@@ -100,6 +100,7 @@ private: ...@@ -100,6 +100,7 @@ private:
void tryToParseCmdLineOptions(int argc, char* argv[], bool& autoConfigureNonFreeDriver, void tryToParseCmdLineOptions(int argc, char* argv[], bool& autoConfigureNonFreeDriver,
std::string& operationType, std::string& autoConfigureClassID); std::string& operationType, std::string& autoConfigureClassID);
bool optionsDontInterfereWithEachOther() const; bool optionsDontInterfereWithEachOther() const;
std::string gatherConfigContent(const std::vector<std::shared_ptr<Config>> & config) const;
}; };
#endif /* MHWD_HPP_ */ #endif /* MHWD_HPP_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment