Add change config file and run config file
This commit is contained in:
parent
77a2ee9989
commit
51188e9f8e
9 changed files with 273 additions and 22 deletions
52
src/clippy/config.cpp
Normal file
52
src/clippy/config.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#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));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue