init project
This commit is contained in:
commit
821ea7eed0
16 changed files with 950 additions and 0 deletions
28
include/lua/loader.hpp
Normal file
28
include/lua/loader.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
#include <lua.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class LuaLoader {
|
||||
public:
|
||||
LuaLoader();
|
||||
|
||||
~LuaLoader();
|
||||
|
||||
void AddLuaPath(const std::string&);
|
||||
void AddCPath(const std::string&);
|
||||
void Call(const std::string& lua_module, const std::string& function);
|
||||
void LoadToGlobal(const std::string&);
|
||||
|
||||
std::vector<std::string> GetListScripts(const std::string&) const;
|
||||
|
||||
private:
|
||||
void Import(const std::string&, const std::string&, int);
|
||||
void LoadImpl(const std::string&);
|
||||
|
||||
void ForEachByStringArray(std::function<void(const std::string&)>);
|
||||
void ParseRequire();
|
||||
void ParseImport();
|
||||
|
||||
lua_State* L;
|
||||
};
|
32
include/projects/project.hpp
Normal file
32
include/projects/project.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class Project {
|
||||
public:
|
||||
Project(const std::string& path, const std::string& path_to_scripts, const std::string& name);
|
||||
Project(const Project&) = delete;
|
||||
Project(Project&&) = default;
|
||||
|
||||
const std::filesystem::path& GetPath() const;
|
||||
const std::filesystem::path& GetPathToScripts() const;
|
||||
const std::string& GetName() const;
|
||||
bool IsSubDirectory(const std::filesystem::path&) const;
|
||||
|
||||
void SetPath(const std::string& path);
|
||||
void SetPathToScripts(const std::string& path_to_scripts);
|
||||
void SetName(const std::string& name);
|
||||
|
||||
void PrintInfo() const;
|
||||
|
||||
private:
|
||||
std::filesystem::path path_;
|
||||
std::filesystem::path path_to_scripts_;
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
Project CreateProject();
|
||||
Project CreateProject(const std::string& name);
|
24
include/projects/project_list.hpp
Normal file
24
include/projects/project_list.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include "projects/project.hpp"
|
||||
|
||||
class ProjectList {
|
||||
public:
|
||||
ProjectList();
|
||||
|
||||
const std::deque<Project>& GetProjects();
|
||||
void AddProject(Project&&);
|
||||
|
||||
const Project& GetProject(
|
||||
const std::filesystem::path& path = std::filesystem::current_path()) const;
|
||||
void LoadFromYaml(const std::string& file_path);
|
||||
void SaveToYaml(const std::string& file_path) const;
|
||||
|
||||
private:
|
||||
std::deque<Project> projects_;
|
||||
};
|
54
include/utils/command_parser.hpp
Normal file
54
include/utils/command_parser.hpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
enum class PatternType { FixedWord, AnyWord, AnyWords };
|
||||
|
||||
struct Pattern {
|
||||
PatternType type;
|
||||
std::string fixed_word;
|
||||
};
|
||||
|
||||
using Callback = std::variant<std::function<void(const std::vector<std::string>&)>,
|
||||
std::function<bool(const std::vector<std::string>&)>>;
|
||||
|
||||
class Parser {
|
||||
public:
|
||||
void AddRule(const std::vector<Pattern>& pattern, const auto& callback,
|
||||
bool find_in_suggestion = true) {
|
||||
if constexpr (std::is_same_v<
|
||||
decltype(callback(std::declval<const std::vector<std::string>&>())), void>) {
|
||||
AddRuleImpl(pattern, std::function<void(const std::vector<std::string>&)>(callback),
|
||||
find_in_suggestion);
|
||||
} else {
|
||||
AddRuleImpl(pattern, std::function<bool(const std::vector<std::string>&)>(callback),
|
||||
find_in_suggestion);
|
||||
}
|
||||
}
|
||||
void Parse(int argc, char* argv[]) const;
|
||||
std::vector<std::string> GetPossibleAdditions(int argc, char* argv[]) const;
|
||||
std::vector<std::string> GetPossibleAdditions(const std::vector<std::string>&) const;
|
||||
|
||||
private:
|
||||
void AddRuleImpl(const std::vector<Pattern>& pattern, const Callback& callback,
|
||||
bool find_in_suggestion);
|
||||
bool Match(const std::vector<Pattern>& pattern, const std::vector<std::string>& args) const;
|
||||
|
||||
private:
|
||||
struct Rule {
|
||||
Rule(const std::vector<Pattern>& pattern, Callback callback, bool find_in_suggestion)
|
||||
: pattern(pattern), callback(callback), find_in_suggestion(find_in_suggestion) {}
|
||||
std::vector<Pattern> pattern;
|
||||
Callback callback;
|
||||
bool find_in_suggestion;
|
||||
};
|
||||
|
||||
std::vector<Rule> rules_;
|
||||
};
|
||||
|
||||
std::vector<Pattern> MakePattern(
|
||||
std::initializer_list<std::variant<const char*, PatternType>> elements);
|
6
include/utils/generate_project_directory.hpp
Normal file
6
include/utils/generate_project_directory.hpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
std::string generate_project_directory(const std::string& project_name);
|
17
include/utils/local.hpp
Normal file
17
include/utils/local.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
inline std::filesystem::path GetLocalPath() {
|
||||
const char* home_dir = getenv("HOME");
|
||||
if (home_dir == nullptr) {
|
||||
std::cerr << "Home directory was not declared" << std::endl;
|
||||
throw std::runtime_error("Was not found home directory");
|
||||
}
|
||||
std::filesystem::path result = std::filesystem::path(home_dir) / ".local/share/cl3";
|
||||
std::filesystem::create_directories(result);
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue