clippy-terminal/src/clippy/clippy.cpp

49 lines
1.3 KiB
C++
Raw Normal View History

2022-08-10 10:53:23 +03:00
#include <clippy/clippy.hpp>
2022-08-10 21:52:07 +03:00
#include <clippy/target.hpp>
2022-08-10 10:53:23 +03:00
2022-08-10 12:02:25 +03:00
#include <utils/parametres.hpp>
2022-08-10 10:53:23 +03:00
#include <iostream>
2022-08-10 21:52:07 +03:00
#include <memory>
2022-08-10 10:53:23 +03:00
#include <vector>
2022-08-10 21:52:07 +03:00
#include <filesystem>
2022-08-10 10:53:23 +03:00
void Clippy::Run(const std::vector<std::string>& args) {
2022-08-10 21:52:07 +03:00
auto result = TryExecuteClippyCommand(args);
if (result) {
result->Execute();
return;
}
2022-08-10 11:04:37 +03:00
}
2022-08-10 21:52:07 +03:00
Clippy::TargetPtr Clippy::TryExecuteClippyCommand(
const std::vector<std::string>& args) {
2022-08-10 12:02:25 +03:00
using namespace utils::parametres;
2022-08-10 21:52:07 +03:00
using namespace clippy::targets;
2022-08-10 12:02:25 +03:00
if (CheckPatternParametres(args, Parameter::Skip, "help",
Parameter::Anything)) {
2022-08-10 11:04:37 +03:00
std::cout << "Hello I'm clippy" << std::endl;
std::cout << "Parametres: { ";
for (size_t i = 0; i < args.size(); ++i) {
std::cout << args[i] << (i + 1 == args.size() ? "" : ",") << " ";
}
std::cout << "}" << std::endl;
2022-08-10 21:52:07 +03:00
return std::make_unique<EmptyTarget>();
}
if (CheckPatternParametres(args, Parameter::Skip, "cfg",
Parameter::Anything)) {
projects_.LoadFrom("test");
auto p = projects_.GetCurrentProject();
if (p.has_value()) {
return std::make_unique<OpenProjectConfig>(p.value().configuration_file);
} else {
return std::make_unique<CreateProjectConfig>(projects_);
}
2022-08-10 10:53:23 +03:00
}
2022-08-10 11:04:37 +03:00
2022-08-10 21:52:07 +03:00
return nullptr;
2022-08-10 10:53:23 +03:00
}