73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
#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>
|
|
|
|
namespace clippy::targets {
|
|
class Target {
|
|
public:
|
|
virtual void Execute() = 0;
|
|
};
|
|
|
|
class EmptyTarget : public Target {
|
|
public:
|
|
void Execute() override {}
|
|
};
|
|
|
|
class OpenProjectConfig : public Target {
|
|
public:
|
|
OpenProjectConfig(Config config) : config_(config) {}
|
|
|
|
void Execute() override { config_.Edit(); }
|
|
|
|
private:
|
|
Config config_;
|
|
};
|
|
|
|
class CreateProjectConfig : public Target {
|
|
public:
|
|
CreateProjectConfig(ProjectList& projects) : projects_(projects) {}
|
|
|
|
void Execute() override {
|
|
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
|