Add change config file and run config file

This commit is contained in:
Timofey 2022-08-11 16:43:53 +03:00
parent 77a2ee9989
commit 51188e9f8e
9 changed files with 273 additions and 22 deletions

View file

@ -1,8 +1,14 @@
#pragma once
#include <clippy/project_list.hpp>
#include <clippy/config.hpp>
#include <utils/editor.hpp>
#include <utils/config_path.hpp>
#define SIGPIPE_ALWAYS_IGNORE
#include <cppshell/shell.hpp>
#undef SIGPIPE_ALWAYS_IGNORE
#include <iostream>
#include <functional>
@ -20,15 +26,12 @@ class EmptyTarget : public Target {
class OpenProjectConfig : public Target {
public:
OpenProjectConfig(std::string config_path) : config_path_(config_path) {}
OpenProjectConfig(Config config) : config_(config) {}
void Execute() override {
utils::OpenEditor(config_path_);
std::cout << "Open editor TODO" << std::endl;
}
void Execute() override { config_.Edit(); }
private:
std::string config_path_;
Config config_;
};
class CreateProjectConfig : public Target {
@ -36,10 +39,35 @@ class CreateProjectConfig : public Target {
CreateProjectConfig(ProjectList& projects) : projects_(projects) {}
void Execute() override {
std::cout << "Make new project config and open editor TODO" << std::endl;
auto scripts_path = utils::GetProjectDirectory() / "scripts";
std::filesystem::create_directories(scripts_path);
auto config = projects_.GetNewConfig(scripts_path);
config.Edit();
}
private:
ProjectList& projects_;
};
class RunShellScript : public Target {
public:
RunShellScript(std::vector<std::string> commands)
: commands_(std::move(commands)) {}
void Execute() override {
cppshell::Shell s;
for (auto& i : commands_) {
std::cout << "-> " << i << std::endl;
s.Execute(i);
if (int err = s.GetExitCodeLastCommand(); err != 0) {
std::cout << "ERROR" << std::endl;
}
}
}
private:
std::vector<std::string> commands_;
};
} // namespace clippy::targets