Skip to content

Commit

Permalink
added project local and started working towards integrating init and …
Browse files Browse the repository at this point in the history
…post scripts into new template system
  • Loading branch information
DeaSTL committed Feb 3, 2024
1 parent d9c3de6 commit 4a92c53
Show file tree
Hide file tree
Showing 22 changed files with 377 additions and 233 deletions.
28 changes: 13 additions & 15 deletions include/Frate/Command/Actions/Add.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once
#include "Frate/CommandHandler.hpp"
#include <Frate/Command/Package.hpp>
#include <Frate/Interface.hpp>

namespace Frate::Command::Add {
Expand All @@ -9,16 +7,16 @@ namespace Frate::Command::Add {
std::vector<Handler> handlers(std::shared_ptr<Interface> inter);
} // namespace Frate::Command::Add

namespace Frate::Command {
class AddHandler : public CommandHandler {
public:
AddHandler(std::shared_ptr<Interface> inter) : CommandHandler(inter) {
this->addSubcommand(std::make_unique<AddPackageHandler>(inter));
this->addOption({"h", "help", cxxopts::value<bool>()->default_value("false")});
}

void registerOptions() override;
void run() override;
void checkInput() override;
};
} // namespace Frate::Command
// namespace Frate::Command {
// class AddHandler : public CommandHandler {
// public:
// AddHandler(std::shared_ptr<Interface> inter) : CommandHandler(inter) {
// this->addSubcommand(std::make_unique<AddPackageHandler>(inter));
// this->addOption({"h", "help", cxxopts::value<bool>()->default_value("false")});
// }
//
// void registerOptions() override;
// void run() override;
// void checkInput() override;
// };
// } // namespace Frate::Command
43 changes: 21 additions & 22 deletions include/Frate/Command/Package.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "Frate/CommandHandler.hpp"
#include "Frate/Dependency.hpp"
#include "cxxopts.hpp"
#include <Frate/Interface.hpp>
Expand Down Expand Up @@ -59,24 +58,24 @@ namespace Frate::Command::Packages {

} // namespace Frate::Command::Packages

namespace Frate::Command {
class AddPackageHandler : public CommandHandler {
public:
AddPackageHandler(std::shared_ptr<Interface> inter)
: CommandHandler(inter) {
// clang-format off
this->addOptions({
{"l,latest", "latest", cxxopts::value<bool>()->default_value("false")},
{"n,name", "name", cxxopts::value<std::string>()},
});
// clang-format on
}

~AddPackageHandler() override = default;

void run() override;
void registerOptions() override;
void checkInput() override;
};

} // namespace Frate::Command
// namespace Frate::Command {
// class AddPackageHandler : public CommandHandler {
// public:
// AddPackageHandler(std::shared_ptr<Interface> inter)
// : CommandHandler(inter) {
// // clang-format off
// this->addOptions({
// {"l,latest", "latest", cxxopts::value<bool>()->default_value("false")},
// {"n,name", "name", cxxopts::value<std::string>()},
// });
// // clang-format on
// }
//
// ~AddPackageHandler() override = default;
//
// void run() override;
// void registerOptions() override;
// void checkInput() override;
// };
//
// } // namespace Frate::Command
161 changes: 80 additions & 81 deletions include/Frate/CommandHandler.hpp
Original file line number Diff line number Diff line change
@@ -1,91 +1,90 @@
#pragma once
#include "Frate/Command/Exceptions.hpp"
#include <cxxopts.hpp>
#include <memory>
#include <string>
#include <vector>


namespace Frate::Command {
class Interface;

class CommandHandler {
private:
std::vector<std::string> aliases;
std::vector<cxxopts::Option> options;
std::vector<std::unique_ptr<CommandHandler>> subcommands;
std::vector<std::string> positional_args{};
bool implemented{true};
bool requires_project{true};
bool unlimited_args{false};
std::string docs;
std::shared_ptr<Interface> inter;

public:
CommandHandler(std::shared_ptr<Interface> inter) : inter(inter) {}

virtual ~CommandHandler() = default;

virtual void run() = 0;
virtual void registerOptions() = 0;
virtual void checkInput() = 0;

// Checkers
bool isImplemented() { return implemented; }

bool requiresProject() { return requires_project; }

bool hasUnlimitedArgs() { return unlimited_args; }

// Getters
std::vector<std::string> &getAliases() { return aliases; }

std::vector<cxxopts::Option> &getOptions() { return options; }

std::vector<std::unique_ptr<CommandHandler>> &getSubcommands() {
return subcommands;
}

std::vector<std::string> &getPosArgs() { return positional_args; }

std::string &getDocs() { return docs; }

std::shared_ptr<Interface> &getInterface() { return inter; }

// Setters

void setAliases(std::vector<std::string> &aliases) {
this->aliases = aliases;
}

void
setSubcommands(std::vector<std::unique_ptr<CommandHandler>> subcommands) {
this->subcommands = std::move(subcommands);
}

void setPosArgs(std::vector<std::string> &positional_args) {
this->positional_args = positional_args;
}

void setDocs(std::string &docs) { this->docs = docs; }

void setInterface(std::shared_ptr<Interface> &inter) {
this->inter = inter;
}

// Adders

void addSubcommand(std::unique_ptr<CommandHandler> subcommand) {
subcommands.push_back(std::move(subcommand));
}

void addOption(cxxopts::Option option) { options.push_back(option); }

void addOptions(std::initializer_list<cxxopts::Option> options) {
for (auto &option : options) {
this->options.push_back(option);
}
}
};
// class Interface;
//
// class CommandHandler {
// private:
// std::vector<std::string> aliases;
// std::vector<cxxopts::Option> options;
// std::vector<std::unique_ptr<CommandHandler>> subcommands;
// std::vector<std::string> positional_args{};
// bool implemented{true};
// bool requires_project{true};
// bool unlimited_args{false};
// std::string docs;
// std::shared_ptr<Interface> inter;
//
// public:
// CommandHandler(std::shared_ptr<Interface> inter) : inter(inter) {}
//
// virtual ~CommandHandler() = default;
//
// virtual void run() = 0;
// virtual void registerOptions() = 0;
// virtual void checkInput() = 0;
//
// // Checkers
// bool isImplemented() { return implemented; }
//
// bool requiresProject() { return requires_project; }
//
// bool hasUnlimitedArgs() { return unlimited_args; }
//
// // Getters
// std::vector<std::string> &getAliases() { return aliases; }
//
// std::vector<cxxopts::Option> &getOptions() { return options; }
//
// std::vector<std::unique_ptr<CommandHandler>> &getSubcommands() {
// return subcommands;
// }
//
// std::vector<std::string> &getPosArgs() { return positional_args; }
//
// std::string &getDocs() { return docs; }
//
// std::shared_ptr<Interface> &getInterface() { return inter; }
//
// // Setters
//
// void setAliases(std::vector<std::string> &aliases) {
// this->aliases = aliases;
// }
//
// void
// setSubcommands(std::vector<std::unique_ptr<CommandHandler>> subcommands) {
// this->subcommands = std::move(subcommands);
// }
//
// void setPosArgs(std::vector<std::string> &positional_args) {
// this->positional_args = positional_args;
// }
//
// void setDocs(std::string &docs) { this->docs = docs; }
//
// void setInterface(std::shared_ptr<Interface> &inter) {
// this->inter = inter;
// }
//
// // Adders
//
// void addSubcommand(std::unique_ptr<CommandHandler> subcommand) {
// subcommands.push_back(std::move(subcommand));
// }
//
// void addOption(cxxopts::Option option) { options.push_back(option); }
//
// void addOptions(std::initializer_list<cxxopts::Option> options) {
// for (auto &option : options) {
// this->options.push_back(option);
// }
// }
// };

} // namespace Frate::Command
1 change: 1 addition & 0 deletions include/Frate/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Frate::Command {
std::vector<Handler> commands{};
std::shared_ptr<Config::ConfigManager> config;
std::shared_ptr<Project::TemplateManager> templates;
std::shared_ptr<Project::Local> local;
char **argv;
int argc;
bool confirm_all{false};
Expand Down
7 changes: 5 additions & 2 deletions include/Frate/Lua/TemplateEnvironment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Frate::Lua {
std::unordered_map<std::string, std::string> init_scripts;
std::unordered_map<std::string, std::string> post_scripts;
std::shared_ptr<Project::Config> pro;
std::shared_ptr<Project::Local> local;

void register_user_types();
void register_frate_api();
Expand All @@ -43,8 +44,8 @@ namespace Frate::Lua {
* @param pro: The project config
* @throws LuaException: If there is an error while registering the project
*/
TemplateEnvironment(std::shared_ptr<Project::Config> pro)
: pro(pro) {
TemplateEnvironment(std::shared_ptr<Project::Config> pro, std::shared_ptr<Project::Local> local)
: pro(pro), local(local) {

lua = std::make_shared<sol::state>();

Expand All @@ -67,12 +68,14 @@ namespace Frate::Lua {

try {
Utils::verbose << "Registering user types" << std::endl;

register_user_types();

} catch (std::exception &e) {
Utils::error << e.what() << std::endl;
throw TemplateEnvironmentException("Error registering user types");
}

};

~TemplateEnvironment() = default;
Expand Down
2 changes: 1 addition & 1 deletion include/Frate/Package.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ namespace Frate::Command {
bool addCallback(sol::state &lua);
friend void from_json(const json &json_obj, Package &package);
friend void to_json(json &json_obj, const Package &package);
Package(){};
Package()= default;
};
} // namespace Frate::Command
15 changes: 10 additions & 5 deletions include/Frate/Project/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
#include <Frate/Package.hpp>
#include <Frate/RemoteServer.hpp>
#include <filesystem>
#include <Frate/Project/Local.hpp>
#include <nlohmann/json.hpp>
#include <string>
#include <unordered_map>
#include <vector>

namespace Frate::Project {

class Config {
class Config : public std::enable_shared_from_this<Config> {

public:
Config() = default;
Expand All @@ -23,9 +24,9 @@ namespace Frate::Project {
TemplateMeta current_template;
std::vector<std::filesystem::path> template_files;
std::vector<std::filesystem::path> script_files;
std::string name;
std::string description;
std::string type{""};
std::string name{"default"};
std::string description{"this is an application"};
std::string type{"default-executable"};
std::filesystem::path path;
std::string git{"null"};
std::string homepage{"null"};
Expand All @@ -37,11 +38,15 @@ namespace Frate::Project {
std::string license{""};
std::string default_mode{"Release"};

//Moving to cache
//Moving to local
[[deprecated("Use Local::build_command")]]
std::string build_command{"cmake --build ."};
[[deprecated("Use Local::test_command")]]
std::string test_command{"ctest"};
[[deprecated("Use Local::run_command")]]
std::string run_command{"./bin/"};


std::vector<Mode> modes{Mode("Release", {"-O2"}), Mode("Debug", {"-g"}),
Mode("Test", {"-g"})};
std::vector<std::string> authors{};
Expand Down
Loading

0 comments on commit 4a92c53

Please sign in to comment.