-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
258 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <Frate/Interface.hpp> | ||
|
||
namespace Frate::Command::Templates{ | ||
bool options(std::shared_ptr<Interface> inter); | ||
bool run(std::shared_ptr<Interface> inter); | ||
std::vector<Handler> handlers(std::shared_ptr<Interface> inter); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "Frate/System/GitCommit.hpp" | ||
#include <nlohmann/json.hpp> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace Frate::Project { | ||
class InstalledTemplate { | ||
private: | ||
// This will be the latest commit hash, if getLatestCommit() is called more | ||
// than once, it will return the cached value | ||
System::GitCommit latest; | ||
|
||
public: | ||
InstalledTemplate() = default; | ||
std::string name; | ||
// Git url to template | ||
std::string git; | ||
// The latest commit hash | ||
std::vector<System::GitCommit> commits; | ||
|
||
// Returns the latest commit hash | ||
System::GitCommit &getLatestCommit(); | ||
friend void to_json(nlohmann::json &j, const InstalledTemplate &t); | ||
friend void from_json(const nlohmann::json &j, InstalledTemplate &t); | ||
friend std::ostream &operator<<(std::ostream &os_stream, | ||
const InstalledTemplate &temp); | ||
}; | ||
} // namespace Frate::Project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
#include <Frate/Interface.hpp> | ||
|
||
namespace Frate::Template{ | ||
bool newTemplate(std::shared_ptr<Command::Interface> inter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
#include "Frate/Dependency.hpp" | ||
#include <Frate/Mode.hpp> | ||
#include <Frate/ProjectPrompt.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace Frate::Command { | ||
// class Mode; | ||
// class Package; | ||
// class ProjectPrompt; | ||
class Project; | ||
using nlohmann::json; | ||
|
||
class Template { | ||
public: | ||
Template(); | ||
std::string name; | ||
std::string description; | ||
std::string version; | ||
std::string src_dir{"src"}; | ||
std::string include_dir{"include"}; | ||
std::string build_dir{"build"}; | ||
std::vector<Dependency> dependencies{}; | ||
std::string default_mode{"Release"}; | ||
std::vector<Mode> modes{}; | ||
std::vector<std::string> flags{}; | ||
std::vector<std::string> system_libs{}; | ||
std::vector<std::string> supported_toolchains{}; | ||
std::vector<std::string> supported_languages{}; | ||
std::vector<std::string> supported_language_versions{}; | ||
std::string min_cmake_version{"3.10"}; | ||
std::vector<std::string> supported_compilers{}; | ||
std::vector<std::string> keywords{}; | ||
std::unordered_map<std::string, ProjectPrompt> prompts{}; | ||
std::unordered_map<std::string, json> global{}; | ||
friend void from_json(const json &json_obj, Template &temp); | ||
friend void to_json(json &json_obj, const Template &temp); | ||
friend void to_project(Project &pro, const Template &temp); | ||
}; | ||
|
||
} // namespace Frate::Command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "Frate/Template/TemplateMeta.hpp" | ||
#include <Frate/Template/InstalledTemplate.hpp> | ||
#include <variant> | ||
#include <vector> | ||
|
||
namespace Frate { | ||
class TemplateManager { | ||
private: | ||
std::vector<Command::TemplateMeta> index; | ||
std::vector<Project::InstalledTemplate> installed; | ||
bool index_loaded = false; | ||
/* | ||
* Loads the index from the github repo | ||
*/ | ||
bool load_index(); | ||
/* | ||
* Checks if a template is installed | ||
* @param name the name of the template to check | ||
* @param hash the hash of the template if it is installed | ||
* @return true if the template is installed | ||
*/ | ||
Project::InstalledTemplate &find_template(const std::string &name); | ||
bool is_installed(const std::string &name, std::string &hash); | ||
|
||
bool template_to_installed_path(std::filesystem::path &tmp_path, | ||
std::filesystem::path &template_path, | ||
std::string &hash); | ||
|
||
public: | ||
TemplateManager() = default; | ||
~TemplateManager() = default; | ||
/* | ||
* Installs a template based on the index | ||
*/ | ||
Command::TemplateMeta install(const std::string &name, | ||
std::string hash = ""); | ||
/* | ||
* Uninstalls a template | ||
* @param name the name of the template to uninstall | ||
*/ | ||
bool uninstall(const std::string &name); | ||
/* | ||
* Updates to the latest version of the template | ||
* @param name the name of the template to update | ||
*/ | ||
bool update(const std::string &name); | ||
/* | ||
* Creates a tempalte in a tmp path and then returns the path that rendering | ||
* is supposed to happen in | ||
* @param override_path the path to override the template path with | ||
* @param name the name of the template to create | ||
* @param hash the hash of the template to create | ||
*/ | ||
std::filesystem::path | ||
makeTemplate(const std::filesystem::path &override_path, | ||
const std::string &name, std::string &hash); | ||
/* | ||
* Grabs the current installed templates from the config file | ||
* @return a vector of TemplateMeta objects | ||
*/ | ||
std::vector<Project::InstalledTemplate> &getInstalled(); | ||
/* | ||
* Grabs the current index from the the github repo, if called more than | ||
* once then it will pull the index from memory | ||
* @return a vector of TemplateMeta objects | ||
*/ | ||
std::vector<Command::TemplateMeta> &getIndex(); | ||
|
||
friend void from_json(const nlohmann::json &json_obj, | ||
TemplateManager &config); | ||
|
||
friend void to_json(nlohmann::json &json_obj, | ||
const TemplateManager &config); | ||
}; | ||
} // namespace Frate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
#include <nlohmann/json.hpp> | ||
#include <string> | ||
|
||
namespace Frate::Command { | ||
class TemplateMeta { | ||
public: | ||
TemplateMeta() = default; | ||
TemplateMeta(const nlohmann::json &json_obj); | ||
std::string name; | ||
std::string description; | ||
std::string hash; | ||
std::string git; | ||
friend void from_json(const nlohmann::json &json_obj, TemplateMeta &temp); | ||
friend void to_json(nlohmann::json &json_obj, const TemplateMeta &temp); | ||
friend std::ostream &operator<<(std::ostream &os_stream, | ||
const TemplateMeta &temp); | ||
}; | ||
} // namespace Frate::Command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <Frate/Command/Actions/Template.hpp> | ||
#include <Frate/Project/Config.hpp> | ||
|
||
namespace Frate::Command::Templates { | ||
bool options(std::shared_ptr<Interface> inter) { | ||
inter->InitHeader(); | ||
inter->options->parse_positional({"command", "subcommand"}); | ||
inter->options->allow_unrecognised_options().add_options()( | ||
"command", "Command to run", | ||
cxxopts::value<std::string>()->default_value("help"))( | ||
"subcommand", "Subcommand to run", | ||
cxxopts::value<std::string>())("h,help", "Print usage"); | ||
inter->options->help(); | ||
return inter->parse(); | ||
} | ||
|
||
std::vector<Handler> handlers(std::shared_ptr<Interface> inter) { | ||
(void)inter; | ||
return { | ||
Handler{ | ||
.aliases = {"new", "n"}, | ||
.flags = {}, | ||
.callback = | ||
[](std::shared_ptr<Interface> inter) { | ||
(void)inter; | ||
return true; | ||
} | ||
}, | ||
Handler{ | ||
.aliases = {"generate", "g"}, | ||
.flags = {}, | ||
.callback = | ||
[](std::shared_ptr<Interface> inter) { | ||
(void)inter; | ||
return true; | ||
} | ||
}, | ||
|
||
}; | ||
} | ||
|
||
bool run(std::shared_ptr<Interface> inter) { | ||
options(inter); | ||
std::vector<Handler> template_handlers = handlers(inter); | ||
std::string subcommand; | ||
if (inter->args->count("subcommand") > 0) { | ||
|
||
subcommand = inter->args->operator[]("subcommand").as<std::string>(); | ||
} | ||
else { | ||
Utils::error << "No subcommand given" << std::endl; | ||
|
||
inter->getHelpString("template", template_handlers); | ||
|
||
return false; | ||
} | ||
|
||
inter->pro->load(); | ||
|
||
return runCommand(inter, subcommand, template_handlers); | ||
|
||
return true; | ||
} | ||
} // namespace Frate::Command::Templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <Frate/Template/New.hpp> | ||
|
||
namespace Frate::Template{ | ||
bool newTemplate(std::shared_ptr<Command::Interface> inter) { | ||
(void)inter; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters