init project
This commit is contained in:
commit
821ea7eed0
16 changed files with 950 additions and 0 deletions
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