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

@ -2,6 +2,7 @@
#include <clippy/target.hpp>
#include <utils/parametres.hpp>
#include <utils/config_path.hpp>
#include <iostream>
#include <memory>
@ -9,8 +10,11 @@
#include <filesystem>
void Clippy::Run(const std::vector<std::string>& args) {
auto result = TryExecuteClippyCommand(args);
if (result) {
if (auto result = TryExecuteClippyCommand(args); result) {
result->Execute();
return;
}
if (auto result = GetScriptTarget(args); result) {
result->Execute();
return;
}
@ -34,15 +38,34 @@ Clippy::TargetPtr Clippy::TryExecuteClippyCommand(
if (CheckPatternParametres(args, Parameter::Skip, "cfg",
Parameter::Anything)) {
projects_.LoadFrom("test");
auto p = projects_.GetCurrentProject();
LoadProjects();
auto p = projects_->GetCurrentProject();
if (p.has_value()) {
return std::make_unique<OpenProjectConfig>(p.value().configuration_file);
return std::make_unique<OpenProjectConfig>(p->GetConfig());
} else {
return std::make_unique<CreateProjectConfig>(projects_);
return std::make_unique<CreateProjectConfig>(projects_.value());
}
}
return nullptr;
}
Clippy::TargetPtr Clippy::GetScriptTarget(
const std::vector<std::string>& args) {
LoadProjects();
auto p = projects_->GetCurrentProject();
if (!p.has_value() || args.size() < 2) {
return nullptr;
}
auto cfg = p->GetConfig();
return cfg.GetTarget(args[1]);
}
void Clippy::LoadProjects() {
if (!projects_.has_value()) {
projects_.emplace(utils::GetProjectDirectory() / "projects");
}
}