52 lines
1 KiB
C++
52 lines
1 KiB
C++
#include <clippy/config.hpp>
|
|
#include <clippy/target.hpp>
|
|
|
|
#include <fstream>
|
|
#include <algorithm>
|
|
|
|
std::string Strip(std::string s) {
|
|
while (!s.empty() && std::isspace(s.back())) {
|
|
s.pop_back();
|
|
}
|
|
std::reverse(s.begin(), s.end());
|
|
while (!s.empty() && std::isspace(s.back())) {
|
|
s.pop_back();
|
|
}
|
|
std::reverse(s.begin(), s.end());
|
|
|
|
return s;
|
|
}
|
|
|
|
std::unique_ptr<clippy::targets::Target> Config::GetTarget(
|
|
const std::string& target) {
|
|
std::ifstream in(path_);
|
|
|
|
std::string current;
|
|
std::vector<std::string> target_commands;
|
|
|
|
bool target_begin = false;
|
|
|
|
while (std::getline(in, current)) {
|
|
if (current == target + ":") {
|
|
target_begin = true;
|
|
continue;
|
|
}
|
|
if (current.empty()) {
|
|
continue;
|
|
}
|
|
if (!std::isspace(current[0]) && target_begin) {
|
|
break;
|
|
}
|
|
|
|
if (target_begin) {
|
|
target_commands.emplace_back(Strip(std::move(current)));
|
|
}
|
|
}
|
|
|
|
if (!target_begin) {
|
|
return nullptr;
|
|
}
|
|
|
|
return std::make_unique<clippy::targets::RunShellScript>(
|
|
std::move(target_commands));
|
|
}
|