diff --git a/.clang-format b/.clang-format index 21d5e66..9bfedd8 100644 --- a/.clang-format +++ b/.clang-format @@ -6,29 +6,39 @@ BasedOnStyle : LLVM SeparateDefinitionBlocks: Always NamespaceIndentation: All -BinPackArguments: No -BinPackParameters: No - -# Aligns consecutive function parameters -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false - - -# Penalty for breaking a function call after a call parameter -PenaltyBreakBeforeFirstCallParameter: 19 - - - -# # Configure new lines around different constructs -# BraceWrapping: -# AfterClass: true # New line after the opening brace of a class -# AfterControlStatement: true # New line after the opening brace of a control statement (if, for, while, ...) -# AfterEnum: true # New line after the opening brace of an enum -# AfterFunction: true # New line after the opening brace of a function -# AfterNamespace: true # New line after the opening brace of a namespace -# AfterStruct: true # New line after the opening brace of a struct -# AfterUnion: true # New line after the opening brace of a union -# BeforeCatch: true # New line before the 'catch' in try-catch blocks -# BeforeElse: true # New line before 'else' in if-else blocks -# BeforeLambdaBody: true # New line before the body of a lambda function +# ColumnLimit: 0 +# AlignAfterOpenBracket: AlwaysBreak +# AllowAllParametersOfDeclarationOnNextLine: false +# BinPackArguments: false +# BinPackParameters: false +IndentWidth: 2 +#ContinuationIndentWidth: 2 + + +# BinPackArguments: No +# BinPackParameters: No +# +# # Aligns consecutive function parameters +# AlignAfterOpenBracket: true +# AlignConsecutiveAssignments: false +# AlignConsecutiveDeclarations: false +# +# +# # Penalty for breaking a function call after a call parameter + + + + +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: true + IndentBraces: false +BreakBeforeBraces: Custom diff --git a/include/Frate/Constants.hpp b/include/Frate/Constants.hpp index 4ae7d87..9bc3f3c 100644 --- a/include/Frate/Constants.hpp +++ b/include/Frate/Constants.hpp @@ -11,23 +11,22 @@ namespace Frate::Constants { const std::string BUILD_OS = "windows32"; #elif _WIN64 const std::string BUILD_OS = "windows64"; -#elif __APPLE__ - const std::string BUILD_OS = "macos"; +#elif __APPLE__ const std::string BUILD_OS = "macos"; #else const std::string BUILD_OS = "unknown"; #endif const std::string NAME = "frate"; const std::string DESCRIPTION = - "CLI utility for managing your project, a modern touch for C/C++"; + "CLI utility for managing your project, a modern touch for C/C++"; const std::string PROJECT_URL = "https://github.com/frate-dev/frate"; constexpr const std::string_view FRATE_PACKAGES = - "https://github.com/frate-packages/index/releases/latest/download/" - "index.json"; + "https://github.com/frate-packages/index/releases/latest/download/" + "index.json"; constexpr const std::string_view FRATE_TEMPLATES = - "https://github.com/frate-templates/templates/releases/latest/download/" - "index.json"; + "https://github.com/frate-templates/templates/releases/latest/download/" + "index.json"; const std::string TEMPLATE_PATH = "template/"; const std::string TEMPLATE_CALLBACKS_PATH = "frate-callbacks/"; @@ -37,11 +36,11 @@ namespace Frate::Constants { const std::string config_name = "config.json"; #ifdef _WIN64 const std::filesystem::path CONFIG_DIR = - std::filesystem::path(getenv("APPDATA")) / NAME; + std::filesystem::path(getenv("APPDATA")) / NAME; const std::filesystem::path CONFIG_PATH = CONFIG_DIR / config_name; #else const std::filesystem::path CONFIG_DIR = - std::filesystem::path(getenv("HOME")) / ".config" / NAME; + std::filesystem::path(getenv("HOME")) / ".config" / NAME; const std::filesystem::path CONFIG_PATH = CONFIG_DIR / config_name; #endif @@ -52,59 +51,45 @@ namespace Frate::Constants { #endif const std::string VERSION = - std::to_string(VMAJOR) + "." + std::to_string(VMINOR) + "." + - std::to_string(VPATCH) + std::to_string(VMAJOR) + "." + std::to_string(VMINOR) + "." + + std::to_string(VPATCH) #ifdef VBUILD - // If VBUILD is defined, append it to the version string - + "." + std::to_string(VBUILD) + // If VBUILD is defined, append it to the version string + + "." + std::to_string(VBUILD) #endif - ; + ; const std::vector SUPPORTED_CMAKE_VERSIONS = { - "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", - "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15", - "3.16", "3.17", "3.18", "3.19", "3.20", "3.21", "3.22", "3.23", - "3.24", "3.25", "3.26", "3.27", "3.28", + "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", + "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15", + "3.16", "3.17", "3.18", "3.19", "3.20", "3.21", "3.22", "3.23", + "3.24", "3.25", "3.26", "3.27", "3.28", }; const std::vector SUPPORTED_C_COMPILERS = { - "clang", - "gcc", - "icc", - "msvc", + "clang", + "gcc", + "icc", + "msvc", }; const std::vector SUPPORTED_CXX_COMPILERS = { - "clang++", - "g++", - "icpc", - "msvc", + "clang++", + "g++", + "icpc", + "msvc", }; const std::vector SUPPORTED_C_STANDARDS = { - "89", - "90", - "99", - "11", - "17", - "18", - "2x", + "89", "90", "99", "11", "17", "18", "2x", }; const std::vector SUPPORTED_CXX_STANDARDS = { - "98", - "03", - "11", - "1x", - "14", - "17", - "20", - "2x", - "23", + "98", "03", "11", "1x", "14", "17", "20", "2x", "23", }; const std::vector SUPPORTED_LANGUAGES = { - "c", - "cpp", + "c", + "cpp", }; } // namespace Frate::Constants diff --git a/include/Frate/Interface.hpp b/include/Frate/Interface.hpp index 1702469..950dab0 100644 --- a/include/Frate/Interface.hpp +++ b/include/Frate/Interface.hpp @@ -28,12 +28,12 @@ namespace Frate::Command { bool unlimited_args{false}; std::string docs; std::function)> callback{ - [](std::shared_ptr inter) -> bool { - (void)inter; - Utils::error << "This command has not been implemented yet" - << std::endl; - return false; - }}; + [](std::shared_ptr inter) -> bool { + (void)inter; + Utils::error << "This command has not been implemented yet" + << std::endl; + return false; + }}; bool run(std::shared_ptr inter); bool options(std::shared_ptr inter); }; @@ -45,12 +45,12 @@ namespace Frate::Command { std::vector positional_args{}; std::string docs; std::function)> callback{ - [](std::shared_ptr inter) -> bool { - (void)inter; - Utils::error << "This command has not been implemented yet" - << std::endl; - return false; - }}; + [](std::shared_ptr inter) -> bool { + (void)inter; + Utils::error << "This command has not been implemented yet" + << std::endl; + return false; + }}; bool implemented{true}; bool requires_project{true}; bool unlimited_args{false}; @@ -69,9 +69,7 @@ namespace Frate::Command { int argc; bool confirm_all{false}; bool parse(); - void getHelpString(std::string name, - std::vector &handlers, - bool is_subcommand = false); + void getHelpString(std::string name, std::vector &handlers, bool is_subcommand = false); void getHelpString(Handler &handler); bool InitHeader(); bool CreateCMakelists(); @@ -84,7 +82,5 @@ namespace Frate::Command { bool Main(std::shared_ptr inter); }; - bool runCommand(std::shared_ptr inter, - std::string command, - std::vector &handlers); + bool runCommand(std::shared_ptr inter, std::string command, std::vector &handlers); } // namespace Frate::Command diff --git a/include/Frate/Project.hpp b/include/Frate/Project.hpp index cbac40c..1dcba34 100644 --- a/include/Frate/Project.hpp +++ b/include/Frate/Project.hpp @@ -19,8 +19,10 @@ namespace Frate::Command { using nlohmann::json; class Project { + public: Project(); + bool loaded_json{false}; std::string name; std::string description; std::string type{""}; @@ -38,8 +40,8 @@ namespace Frate::Command { std::string build_command{"cmake --build ."}; std::string test_command{"ctest"}; std::string run_command{"./bin/"}; - std::vector modes{ - Mode("Release", {"-O2"}), Mode("Debug", {"-g"}), Mode("Test", {"-g"})}; + std::vector modes{Mode("Release", {"-O2"}), Mode("Debug", {"-g"}), + Mode("Test", {"-g"})}; std::vector authors{}; std::vector keywords{}; std::string src_dir{"src"}; diff --git a/include/Frate/System/Capabilities.hpp b/include/Frate/System/Capabilities.hpp index 986f931..8d4ae5f 100644 --- a/include/Frate/System/Capabilities.hpp +++ b/include/Frate/System/Capabilities.hpp @@ -3,76 +3,60 @@ namespace Frate::System { - class Capabilities { - /* - * Given the provided path, this will search for certain keywords that - * corrospond to a capabilities - */ - private: - void search_path(std::filesystem::path &path); - void get_make_capability(const std::filesystem::path &path, - std::string &name); - void get_cmake_capability(const std::filesystem::path &path, - std::string &name); - void get_git_capability(const std::filesystem::path &path, - std::string &name); - void get_zip_capability(const std::filesystem::path &path, - std::string &name); - void get_unzip_capability(const std::filesystem::path &path, - std::string &name); - void get_tar_capability(const std::filesystem::path &path, - std::string &name); - void get_archive_compress_capability(const std::filesystem::path &path, - std::string &name); - void get_archive_expand_capability(const std::filesystem::path &path, - std::string &name); - void get_sccache_capability(const std::filesystem::path &path, - std::string &name); - void get_ninja_capability(const std::filesystem::path &path, - std::string &name); - void get_rsync_capability(const std::filesystem::path &path, - std::string &name); - void get_ssh_capability(const std::filesystem::path &path, - std::string &name); - void get_python_capability(const std::filesystem::path &path, - std::string &name); - void get_python3_capability(const std::filesystem::path &path, - std::string &name); - void get_python2_capability(const std::filesystem::path &path, - std::string &name); - void get_compilers_capability(const std::filesystem::path &path, - std::string &name); - - public: - Capabilities(); - - Capability make; - Capability cmake; - Capability git; - Capability zip; - Capability unzip; - Capability tar; - Capability archive_compress; - Capability archive_expand; - Capability sccache; - Capability ninja; - Capability rsync; - Capability python; - Capability python3; - Capability python2; - Capability ssh; - - // compilers and installed versions - std::unordered_map compilers; - - friend void from_json(const nlohmann::json &json_obj, - Capabilities &capabilities); - friend void to_json(nlohmann::json &json_obj, - const Capabilities &capabilities); - - Capability getLatestCompiler(std::string compiler); - bool search(); - bool has(Capability capability); - }; + class Capabilities { + /* + * Given the provided path, this will search for certain keywords that + * corrospond to a capabilities + */ + private: + void search_path(std::filesystem::path &path); + void get_make_capability( + const std::filesystem::path &path, + std::string &name); + void get_cmake_capability(const std::filesystem::path &path, std::string &name); + void get_git_capability(const std::filesystem::path &path, std::string &name); + void get_zip_capability(const std::filesystem::path &path, std::string &name); + void get_unzip_capability(const std::filesystem::path &path, std::string &name); + void get_tar_capability(const std::filesystem::path &path, std::string &name); + void get_archive_compress_capability(const std::filesystem::path &path, std::string &name); + void get_archive_expand_capability(const std::filesystem::path &path, std::string &name); + void get_sccache_capability(const std::filesystem::path &path, std::string &name); + void get_ninja_capability(const std::filesystem::path &path, std::string &name); + void get_rsync_capability(const std::filesystem::path &path, std::string &name); + void get_ssh_capability(const std::filesystem::path &path, std::string &name); + void get_python_capability(const std::filesystem::path &path, std::string &name); + void get_python3_capability(const std::filesystem::path &path, std::string &name); + void get_python2_capability(const std::filesystem::path &path, std::string &name); + void get_compilers_capability(const std::filesystem::path &path, std::string &name); + + public: + Capabilities(); + + Capability make; + Capability cmake; + Capability git; + Capability zip; + Capability unzip; + Capability tar; + Capability archive_compress; + Capability archive_expand; + Capability sccache; + Capability ninja; + Capability rsync; + Capability python; + Capability python3; + Capability python2; + Capability ssh; + + // compilers and installed versions + std::unordered_map compilers; + + friend void from_json(const nlohmann::json &json_obj, Capabilities &capabilities); + friend void to_json(nlohmann::json &json_obj, const Capabilities &capabilities); + + Capability getLatestCompiler(std::string compiler); + bool search(); + bool has(Capability capability); + }; } // namespace Frate::System diff --git a/src/Command/Actions/Build.cpp b/src/Command/Actions/Build.cpp index 6854625..6a97122 100644 --- a/src/Command/Actions/Build.cpp +++ b/src/Command/Actions/Build.cpp @@ -7,13 +7,13 @@ namespace Frate::Command::Build { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command"}); - inter->options->add_options()( - "command", - "Command to run", - cxxopts::value()->default_value("help"))( - "m,mode", "mode to build in", cxxopts::value())( - "t,target", "Target to build", cxxopts::value())( - "j,jobs", "Number of jobs to run", cxxopts::value()); + // clang-format off + inter->options->add_options() + ("command","Command to run",cxxopts::value()->default_value("help")) + ("m,mode", "mode to build in", cxxopts::value()) + ("t,target", "Target to build", cxxopts::value()) + ("j,jobs", "Number of jobs to run", cxxopts::value()); + // clang-format on return inter->parse(); } @@ -49,7 +49,8 @@ namespace Frate::Command::Build { if (Utils::hSystem(workdir_cmd + ";" + full_build_cmd) != 0) { Utils::error << "Build failed" << std::endl; return false; - } else { + } + else { Utils::info << "Build success" << std::endl; return true; } diff --git a/src/Command/Actions/Clean.cpp b/src/Command/Actions/Clean.cpp index 8ada30f..ef7ed81 100644 --- a/src/Command/Actions/Clean.cpp +++ b/src/Command/Actions/Clean.cpp @@ -7,17 +7,14 @@ namespace Frate::Command::Clean { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command", "subcommand", "args"}); - inter->options->add_options()( - "command", - "Command to run", - cxxopts::value()->default_value("help"))( - "subcommand", "Subcommand to run", cxxopts::value())( - "h,help", "Print usage")("args", - "Arguments to pass to subcommand", - cxxopts::value>())( - "c,cache", - "Cleans build and cache", - cxxopts::value()->default_value("false")); + // clang-format off + inter->options->add_options() + ("command","Command to run",cxxopts::value()->default_value("help")) + ("subcommand", "Subcommand to run", cxxopts::value()) + ("h,help", "Print usage") + ("args","Arguments to pass to subcommand",cxxopts::value>()) + ("c,cache","Cleans build and cache",cxxopts::value()->default_value("false")); + // clang-format on return inter->parse(); } @@ -25,10 +22,8 @@ namespace Frate::Command::Clean { bool cleanCache(std::shared_ptr pro) { const std::vector files_to_delete = { - pro->path / "CMakeCache.txt", - pro->path / "install_manifest.txt", - pro->path / "cmake_install.cmake", - pro->path / "Makefile"}; + pro->path / "CMakeCache.txt", pro->path / "install_manifest.txt", + pro->path / "cmake_install.cmake", pro->path / "Makefile"}; const std::vector dirs_to_delete = { pro->path / "CMakeFiles/", pro->path / "_deps/"}; @@ -77,11 +72,13 @@ namespace Frate::Command::Clean { Utils::verbose << "Deleting" << p.path() << std::endl; if (p.is_directory()) { remove_all(p.path()); - } else { + } + else { std::filesystem::remove(p.path()); } } - } else { + } + else { Utils::error << "Could not find ./build" << std::endl; } diff --git a/src/Command/Actions/Remove.cpp b/src/Command/Actions/Remove.cpp index 06e57ee..1750781 100644 --- a/src/Command/Actions/Remove.cpp +++ b/src/Command/Actions/Remove.cpp @@ -13,17 +13,14 @@ namespace Frate::Command::Remove { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command", "subcommand", "args"}); - inter->options->allow_unrecognised_options().add_options()( - "command", - "Command to run", - cxxopts::value()->default_value("help"))( - "m,mode", - "make changes to compile mode", - cxxopts::value())( - "subcommand", "Subcommand to run", cxxopts::value())( - "h,help", "Print usage")("args", - "Arguments to pass to subcommand", - cxxopts::value>()); + // clang-format off + inter->options->allow_unrecognised_options().add_options() + ("command","Command to run",cxxopts::value()->default_value("help")) + ("m,mode","make changes to compile mode",cxxopts::value()) + ("subcommand", "Subcommand to run", cxxopts::value()) + ("h,help", "Print usage") + ("args","Arguments to pass to subcommand",cxxopts::value>()); + // clang-format on return inter->parse(); } @@ -78,8 +75,8 @@ namespace Frate::Command::Remove { if (inter->args->count("subcommand")) { subcommand = inter->args->operator[]("subcommand").as(); - - } else { + } + else { Utils::error << "No subcommand given" << std::endl; inter->getHelpString("remove", removeHandlers); diff --git a/src/Command/Actions/Search.cpp b/src/Command/Actions/Search.cpp index 5775989..4f73408 100644 --- a/src/Command/Actions/Search.cpp +++ b/src/Command/Actions/Search.cpp @@ -8,14 +8,13 @@ namespace Frate::Command::Search { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command", "subcommand", "query"}); - inter->options->add_options()( - "command", - "Command to run", - cxxopts::value()->default_value("help"))( - "subcommand", "Subcommand to run", cxxopts::value())( - "h,help", "Print usage")("query", - "Arguments to pass to the command", - cxxopts::value()); + // clang-format off + inter->options->add_options() + ("command","Command to run",cxxopts::value()->default_value("help")) + ("subcommand", "Subcommand to run", cxxopts::value()) + ("h,help", "Print usage") + ("query","Arguments to pass to the command",cxxopts::value()); + // clang-format on return inter->parse(); } diff --git a/src/Command/Actions/UvWatch.cpp b/src/Command/Actions/UvWatch.cpp index b85d47e..504f234 100644 --- a/src/Command/Actions/UvWatch.cpp +++ b/src/Command/Actions/UvWatch.cpp @@ -10,16 +10,12 @@ namespace Frate::Command::UvWatch { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command"}); - inter->options->add_options()( - "c,command", - "Command to run", - cxxopts::value()->default_value("help"))( - "e,execute", - "Execute command", - cxxopts::value()->default_value("false"))( - "r,remote", - "Build server to use", - cxxopts::value()->default_value("false")); + // clang-format off + inter->options->add_options() + ("c,command","Command to run",cxxopts::value()->default_value("help")) + ("e,execute","Execute command",cxxopts::value()->default_value("false")) + ("r,remote","Build server to use",cxxopts::value()->default_value("false")); + // clang-format on return inter->parse(); } @@ -52,10 +48,8 @@ namespace Frate::Command::UvWatch { this->callback = callback; }; - static void fs_event_callback(uv_fs_event_t *handle, - const char *filename, - int events, - int status) { + static void fs_event_callback(uv_fs_event_t *handle, const char *filename, + int events, int status) { (void)filename, (void)events; if (event_triggered) { // Ignoring subsequent events @@ -91,8 +85,8 @@ namespace Frate::Command::UvWatch { auto watcher = new uv_fs_event_t; watcher->data = this; uv_fs_event_init(loop, watcher); - uv_fs_event_start( - watcher, fs_event_callback, entry.path().c_str(), 0); + uv_fs_event_start(watcher, fs_event_callback, entry.path().c_str(), + 0); watchers.emplace_back(watcher); } } diff --git a/src/Command/Author/Author.cpp b/src/Command/Author/Author.cpp index bee06bd..95afb85 100644 --- a/src/Command/Author/Author.cpp +++ b/src/Command/Author/Author.cpp @@ -7,10 +7,12 @@ namespace Frate::Command::Author { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command", "subcommand", "authors"}); - inter->options->add_options()( - "command", "Command to run", cxxopts::value())( - "subcommand", "Subcommand to run", cxxopts::value())( - "authors", "Authors", cxxopts::value>()); + // clang-format off + inter->options->add_options() + ("command", "Command to run", cxxopts::value()) + ("subcommand", "Subcommand to run", cxxopts::value()) + ("authors", "Authors", cxxopts::value>()); + // clang-format on return inter->parse(); } @@ -34,7 +36,6 @@ namespace Frate::Command::Author { inter->pro->authors.emplace_back(author); Utils::info << "Added author " << author << std::endl; } - inter->pro->save(); return true; } @@ -54,7 +55,6 @@ namespace Frate::Command::Author { author), inter->pro->authors.end()); Utils::info << "Removed author " << author << std::endl; - inter->pro->save(); return true; } } diff --git a/src/Command/Helpers/Interface.cpp b/src/Command/Helpers/Interface.cpp index a5331b8..e706072 100644 --- a/src/Command/Helpers/Interface.cpp +++ b/src/Command/Helpers/Interface.cpp @@ -26,17 +26,14 @@ namespace Frate::Command { bool OptionsInit::Main(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command"}); - inter->options->allow_unrecognised_options().add_options()( - "command", - "Command to run", - cxxopts::value()->default_value("help"))( - "verbose", - "Verbose output", - cxxopts::value()->default_value("false"))( - "y,confirm-all", - "skip all y/n prompts", - cxxopts::value()->default_value("false"))("version", - "Print version"); + // clang-format off + inter->options->allow_unrecognised_options().add_options() + ("command", "Command to run",cxxopts::value()->default_value("help")) + ("verbose", "Verbose output",cxxopts::value()->default_value("false")) + ("y,confirm-all", "skip all y/n prompts",cxxopts::value()->default_value("false")) + ("version","Print version"); + // clang-format on + return inter->parse(); } @@ -196,7 +193,7 @@ namespace Frate::Command { } // Save the project if the command has the possibility of changing it - if (handler.requires_project) { + if (inter->pro->loaded_json) { inter->pro->save(); } inter->config.save(); @@ -226,15 +223,15 @@ namespace Frate::Command { if (unlimited_args) { std::cout << termcolor::bold << termcolor::green << " [" << positional << " ...]" << termcolor::reset; - } else { + } + else { std::cout << termcolor::bold << termcolor::green << " [" << positional << "]" << termcolor::reset; } } } - bool runCommand(std::shared_ptr inter, - std::string command, + bool runCommand(std::shared_ptr inter, std::string command, std::vector &handlers) { for (Handler handler : handlers) { for (std::string alias : handler.aliases) { @@ -251,10 +248,6 @@ namespace Frate::Command { inter->getHelpString(handler); return false; } - if (handler.requires_project) { - inter->pro->save(); - } - inter->config.save(); return true; } } @@ -283,7 +276,8 @@ namespace Frate::Command { if (is_subcommand) { if (index == handlers.size()) { std::cout << " └── "; - } else { + } + else { std::cout << " ├── "; } alias_str_len += 4; @@ -308,16 +302,18 @@ namespace Frate::Command { std::cout << " "; if (index != handlers.size()) { std::cout << "\n │"; - } else { + } + else { std::cout << "\n "; } std::cout << " " << termcolor::blue << handler.docs << termcolor::reset; - } else { + } + else { if (!handler.subcommands.empty()) { std::cout << termcolor::blue << " " << termcolor::reset; - - } else { + } + else { std::cout << " : " << termcolor::blue << handler.docs << termcolor::reset; } @@ -325,12 +321,13 @@ namespace Frate::Command { if (!handler.implemented) { std::cout << termcolor::red << " (Not implemented)" << termcolor::reset << std::endl; - } else { + } + else { std::cout << std::endl; } if (!handler.subcommands.empty()) { - getHelpString( - name + " " + handler.aliases[0], handler.subcommands, true); + getHelpString(name + " " + handler.aliases[0], handler.subcommands, + true); std::cout << std::endl; } } diff --git a/src/Command/Helpers/Project.cpp b/src/Command/Helpers/Project.cpp index b4693e5..6b6cbf0 100644 --- a/src/Command/Helpers/Project.cpp +++ b/src/Command/Helpers/Project.cpp @@ -14,6 +14,12 @@ namespace Frate::Command { bool Project::save() { std::ofstream file; std::string file_name = "frate-project.json"; + // Used as a safe guard to prevent overwriting the project file + if (!loaded_json) { + Utils::error << "Project not loaded" << std::endl; + return false; + } + if (!std::filesystem::exists(this->path)) { try { std::filesystem::create_directory(this->path); @@ -135,7 +141,8 @@ namespace Frate::Command { Utils::debug(e.what()); return false; } - + // Used to prevent overwriting the project file + loaded_json = true; return true; } } // namespace Frate::Command diff --git a/src/Command/Keywords/Keywords.cpp b/src/Command/Keywords/Keywords.cpp index 29ac68d..98ae23c 100644 --- a/src/Command/Keywords/Keywords.cpp +++ b/src/Command/Keywords/Keywords.cpp @@ -4,12 +4,12 @@ namespace Frate::Command::Keywords { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command", "subcommand", "keywords"}); - inter->options->add_options()( - "command", "The command to run", cxxopts::value())( - "subcommand", "The subcommand to run", cxxopts::value())( - "keywords", - "The keywords to search for", - cxxopts::value>()); + // clang-format off + inter->options->add_options() + ("command", "The command to run", cxxopts::value()) + ("subcommand", "The subcommand to run", cxxopts::value()) + ("keywords","The keywords to search for",cxxopts::value>()); + // clang-format on return inter->parse(); } } // namespace Frate::Command::Keywords diff --git a/src/Command/Library/Library.cpp b/src/Command/Library/Library.cpp index 574a734..d5e97d7 100644 --- a/src/Command/Library/Library.cpp +++ b/src/Command/Library/Library.cpp @@ -4,10 +4,12 @@ namespace Frate::Command::Library { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command", "subcommand", "lib"}); - inter->options->add_options()( - "command", "Command to run", cxxopts::value())( - "subcommand", "Subcommand to run", cxxopts::value())( - "lib", "lib", cxxopts::value>()); + // clang-format off + inter->options->add_options() + ("command", "Command to run", cxxopts::value()) + ("subcommand", "Subcommand to run", cxxopts::value()) + ("lib", "lib", cxxopts::value>()); + // clang-format on return inter->parse(); return true; } diff --git a/src/Command/Library/Remove.cpp b/src/Command/Library/Remove.cpp index f283c75..cbb7a23 100644 --- a/src/Command/Library/Remove.cpp +++ b/src/Command/Library/Remove.cpp @@ -13,6 +13,6 @@ namespace Frate::Command::Library { } return false; }); - return inter->pro->save(); + return true; } } // namespace Frate::Command::Library diff --git a/src/Command/Name/SetName.cpp b/src/Command/Name/SetName.cpp index 232e81a..b44f5d2 100644 --- a/src/Command/Name/SetName.cpp +++ b/src/Command/Name/SetName.cpp @@ -12,8 +12,6 @@ namespace Frate::Command::Name { inter->pro->name = inter->args->operator[]("name").as(); Utils::info << "Name set to " << inter->pro->name << ".\n"; - inter->pro->save(); - return true; } } // namespace Frate::Command::Name diff --git a/src/Command/Package/AddPackages.cpp b/src/Command/Package/AddPackages.cpp index df60474..646c4c9 100644 --- a/src/Command/Package/AddPackages.cpp +++ b/src/Command/Package/AddPackages.cpp @@ -10,8 +10,7 @@ namespace Frate::Command::Packages { using Utils::CLI::Prompt; - bool addPackageToMode(std::shared_ptr inter, - Dependency package, + bool addPackageToMode(std::shared_ptr inter, Dependency package, std::string selected_mode) { Utils::info << "Adding package to mode " << selected_mode << std::endl; for (Mode &mode : inter->pro->modes) { @@ -96,10 +95,6 @@ namespace Frate::Command::Packages { } std::cout << "Package: " << nlohmann::json(package) << std::endl; inter->pro->dependencies.emplace_back(package, version); - if (!inter->pro->save()) { - Utils::error << "Failed to save project" << std::endl; - return false; - }; return true; } @@ -112,7 +107,8 @@ namespace Frate::Command::Packages { if (!exact) { Utils::error << "No exact match found" << std::endl; chosen_package = promptSearchResults(package_name); - } else { + } + else { Utils::info << "Exact match found" << std::endl; chosen_package = exact_package; } @@ -125,7 +121,8 @@ namespace Frate::Command::Packages { if (!latest) { version = promptForVersion(chosen_package); // chosen_package.selected_version = version; - } else { + } + else { if (chosen_package.versions.empty()) { Utils::error << "No versions found" << std::endl; return false; @@ -140,8 +137,8 @@ namespace Frate::Command::Packages { } if (!mode.empty()) { - if (!addPackageToMode( - inter, Dependency(chosen_package, version), mode)) { + if (!addPackageToMode(inter, Dependency(chosen_package, version), + mode)) { Utils::error << "Failed to add package to mode" << std::endl; return false; } diff --git a/src/Command/Package/Package.cpp b/src/Command/Package/Package.cpp index 70221b3..07bf5fc 100644 --- a/src/Command/Package/Package.cpp +++ b/src/Command/Package/Package.cpp @@ -12,30 +12,21 @@ namespace Frate::Command::Packages { bool options(std::shared_ptr inter) { inter->InitHeader(); inter->options->parse_positional({"command", "subcommand", "args"}); - inter->options->add_options()( - "command", - "Command to run", - cxxopts::value()->default_value("help"))( - "subcommand", "Subcommand to run", cxxopts::value())( - "h,help", "Print usage")( - "m,mode", "make changes to compile mode", cxxopts::value()) + // clang-format off + inter->options->add_options() + ("command","Command to run",cxxopts::value()->default_value("help")) + ("subcommand", "Subcommand to run", cxxopts::value()) + ("h,help", "Print usage") + ("m,mode", "make changes to compile mode", cxxopts::value()) // TODO: make git version, and stuff like that work to make packages // more relaxed - ("g,git", "git repo to clone", cxxopts::value())( - "package-version", - "version for package", - cxxopts::value())("t,target_link", - "how to link to package", - cxxopts::value())( - "e,exact", - "Exact package", - cxxopts::value()->default_value("false"))( - "l,latest", - "Latest package", - cxxopts::value()->default_value("false"))( - "args", - "Arguments to pass to subcommand", - cxxopts::value>()); + ("g,git", "git repo to clone", cxxopts::value()) + ("package-version","version for package",cxxopts::value()) + ("t,target_link","how to link to package",cxxopts::value()) + ("e,exact","Exact package",cxxopts::value()->default_value("false")) + ("l,latest","Latest package",cxxopts::value()->default_value("false")) + ("args","Arguments to pass to subcommand",cxxopts::value>()); + // clang-format on inter->options->help(); return inter->parse(); } diff --git a/src/Generators/ProjectGenerator/DownloadTemplates.cpp b/src/Generators/ProjectGenerator/DownloadTemplates.cpp index b261889..6767e3e 100644 --- a/src/Generators/ProjectGenerator/DownloadTemplates.cpp +++ b/src/Generators/ProjectGenerator/DownloadTemplates.cpp @@ -3,7 +3,6 @@ #include namespace Frate::Generators::Project { - bool downloadTemplate(std::string git_url, path project_path) { // Delete old template before downloading new one if (std::filesystem::exists(project_path / "template")) { @@ -25,65 +24,10 @@ namespace Frate::Generators::Project { return false; } - // git_libgit2_init(); - // const git_error *template_clone_err; - // Utils::info << "Downloading template" << std::endl; - // git_repository* template_repo = NULL; - // git_repository* callbacks_repo = NULL; - // Utils::info << "Cloning " << git_url << " into " - // << (project_path / "template").c_str() << std::endl; - // - // - // int template_clone_status = git_clone(&template_repo, - // git_url.c_str(), (project_path / "template").c_str(), NULL); - // - // - // if(template_clone_status != 0){ - // template_clone_err = git_error_last(); - // Utils::error << "Clone status code: " << template_clone_status << - // std::endl; if(template_clone_err){ - // Utils::error << "Error while cloning repository error code: " << - // template_clone_err->klass << std::endl; - // }else{ - // Utils::error << "Error while cloning repository" << std::endl; - // } - // return false; - // } - // - // - // git_repository_free(template_repo); - // - // - // Utils::info << "Cloning " << callbacks_url << " into " - // << (project_path / "template/frate-callbacks").c_str() << - // std::endl; - // - // const git_error *callbacks_clone_err; - // int callbacks_clone_status= git_clone(&callbacks_repo, - // callbacks_url.c_str(), - // (project_path / "template/frate-callbacks").c_str(), NULL); - // - // - // if(callbacks_clone_status != 0){ - // callbacks_clone_err = git_error_last(); - // Utils::error << "Clone status code: " << callbacks_clone_status << - // std::endl; if(callbacks_clone_err){ - // Utils::error << "Error while cloning repository error code: " << - // callbacks_clone_err->klass << std::endl; - // }else{ - // Utils::error << "Error while cloning repository" << std::endl; - // } - // return false; - // } - // - // - // git_repository_free(callbacks_repo); - // - // git_libgit2_shutdown(); - - int status = - Utils::hSystem("git clone -b " + Constants::TEMPLATE_BRANCH + " " + - git_url + " " + (project_path / "template").string()); + // Clones main template repo + int status = Utils::hSystem("git clone --depth=1 -b " + + Constants::TEMPLATE_BRANCH + " " + git_url + + " " + (project_path / "template").string()); if (status != 0) { Utils::error << "Error while cloning template repo" << std::endl; return false; @@ -91,11 +35,16 @@ namespace Frate::Generators::Project { const std::string callbacks_url = "https://github.com/frate-templates/frate-callbacks.git"; + status = - Utils::hSystem("git clone -b " + Constants::TEMPLATE_BRANCH + " " + - std::string(callbacks_url) + " " + + Utils::hSystem("git clone --depth=1 -b " + Constants::TEMPLATE_BRANCH + + " " + std::string(callbacks_url) + " " + (project_path / "template/frate-callbacks").string()); + // Removes .git folders + std::filesystem::remove_all(project_path / "template/frate-callbacks/.git"); + std::filesystem::remove_all(project_path / "template/.git"); + if (status != 0) { Utils::error << "Error while cloning callback repository" << std::endl; return false; @@ -106,12 +55,6 @@ namespace Frate::Generators::Project { std::filesystem::remove_all(project_path / "template/frate-callbacks"); - try { - std::filesystem::remove(project_path / "template/.git"); - } catch (...) { - Utils::error << "could not find .git folder in template/" << std::endl; - } - return true; } } // namespace Frate::Generators::Project diff --git a/src/Generators/ProjectGenerator/ProjectGenerator.cpp b/src/Generators/ProjectGenerator/ProjectGenerator.cpp index eeb9364..af71f52 100644 --- a/src/Generators/ProjectGenerator/ProjectGenerator.cpp +++ b/src/Generators/ProjectGenerator/ProjectGenerator.cpp @@ -59,8 +59,7 @@ namespace Frate::Generators::Project { Utils::info << "Copying template to project" << std::endl; std::filesystem::copy( - pro->path / "template", - pro->path, + pro->path / "template", pro->path, std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing); Utils::info << "Loading template config" << std::endl; @@ -93,6 +92,9 @@ namespace Frate::Generators::Project { LuaAPI::postScripts(lua, pro); + // This ia bit of a hack, because create doesn't actually load a project so + // we have to emulate the loading process + pro->loaded_json = true; pro->save(); return true; diff --git a/src/Generators/ProjectGenerator/RenderTemplate.cpp b/src/Generators/ProjectGenerator/RenderTemplate.cpp index 8aba543..c433bf1 100644 --- a/src/Generators/ProjectGenerator/RenderTemplate.cpp +++ b/src/Generators/ProjectGenerator/RenderTemplate.cpp @@ -27,9 +27,9 @@ namespace Frate::Generators::Project { // Array to store all the paths to remove at the end of the function std::vector paths_to_remove = { - pro->path / "__init__", - pro->path / "__post__", - }; + pro->path / "__init__", pro->path / "__post__", + pro->path / "frate-callbacks", pro->path / "LICENSE", + pro->path / "cmake_includes"}; // Array of all the file extensions that we're going to ignore when copying // files @@ -40,8 +40,8 @@ namespace Frate::Generators::Project { std::unordered_map> related_source_exts = {}; - related_source_exts["cpp"] = { - ".cpp", ".cxx", ".cc", ".C", ".c++", ".hpp", ".hxx", ".hh"}; + related_source_exts["cpp"] = {".cpp", ".cxx", ".cc", ".C", + ".c++", ".hpp", ".hxx", ".hh"}; related_source_exts["c"] = {".c", ".h"}; // Removes all source files that are not related to the project language for (auto [key, source_files] : related_source_exts) { @@ -94,7 +94,8 @@ namespace Frate::Generators::Project { for (const path &p : paths_to_remove) { if (std::filesystem::is_directory(p)) { std::filesystem::remove_all(p); - } else { + } + else { std::filesystem::remove(p); } } diff --git a/src/System/Capabilities.cpp b/src/System/Capabilities.cpp index 42e591f..dc4032d 100644 --- a/src/System/Capabilities.cpp +++ b/src/System/Capabilities.cpp @@ -21,23 +21,45 @@ namespace Frate::System { filename = filename.substr(0, filename.find(".exe")); #endif + if (filename.find("gcc") != std::string::npos) { - Utils::info << "Found gcc: " + filename << std::endl; if (this->compilers[filename].installed) { continue; } this->get_compilers_capability(current_path.path(), filename); - Utils::info << "Found gcc: " + filename << " with version" + Utils::info << "Found compiler: " + filename << " with version" << this->compilers[filename].version << std::endl; + } + else if (filename.find("g++") != std::string::npos) { + + if (this->compilers[filename].installed) { + continue; + } + + this->get_compilers_capability(current_path.path(), filename); - } else if (filename == "cmake") { + Utils::info << "Found compiler: " + filename << " with version" + << this->compilers[filename].version << std::endl; + } + else if (filename.find("clang") != std::string::npos) { + if (this->compilers[filename].installed) { + continue; + } + + this->get_compilers_capability(current_path.path(), filename); + + Utils::info << "Found compiler: " + filename << " with version" + << this->compilers[filename].version << std::endl; + } + else if (filename == "cmake") { if (this->cmake.installed) { continue; } this->get_cmake_capability(current_path.path(), filename); + Utils::info << "Found cmake: " + filename << " with version" << this->cmake.version << std::endl; } diff --git a/src/System/FindCompilers.cpp b/src/System/FindCompilers.cpp index 609025a..8f2acec 100644 --- a/src/System/FindCompilers.cpp +++ b/src/System/FindCompilers.cpp @@ -1,34 +1,55 @@ #include "Frate/System/Capability.hpp" #include "Frate/Utils/General.hpp" +#include "Frate/Utils/Logging.hpp" #include #include namespace Frate::System { - std::string get_gcc_compiler_version(const std::filesystem::path &path) { - std::string gcc_version; - std::string gcc_version_cmd = path.string() + " --version"; - Utils::CmdOutput command = Frate::Utils::hSystemWithOutput(gcc_version_cmd); - if (command.return_code == 0) { - std::regex gcc_version_regex(R"(gcc \(GCC\) ([0-9]+\.[0-9]+\.[0-9]+))"); - std::smatch gcc_version_match; - if (std::regex_search( - command.std_out, gcc_version_match, gcc_version_regex)) { - gcc_version = gcc_version_match[1]; + std::string get_compiler_version(const std::filesystem::path &path) { + std::string gcc_version; + std::string gcc_version_cmd = path.string() + " --version"; + Utils::CmdOutput command = Frate::Utils::hSystemWithOutput(gcc_version_cmd); + if (command.return_code == 0) { + std::regex gcc_version_regex(R"(\(GCC\) ([0-9]+\.[0-9]+\.[0-9]+))"); + std::smatch gcc_version_match; + if (std::regex_search( + command.std_out, gcc_version_match, gcc_version_regex)) { + gcc_version = gcc_version_match[1]; + return gcc_version; + } + } + // If we get here we didn't find a version or command failed return gcc_version; - } } - // If we get here we didn't find a version or command failed - return gcc_version; - } - void Capabilities::get_compilers_capability(const std::filesystem::path &path, - std::string &name) { - std::string gcc_version = get_gcc_compiler_version(path); - if (!gcc_version.empty()) { - compilers[name] = Capability(); - compilers[name].version = gcc_version; - compilers[name].path = path; - compilers[name].installed = true; + void Capabilities::get_compilers_capability(const std::filesystem::path &path, std::string &name) { + Utils::info << "Found compiler: " + name << std::endl; + if (name.find("gcc") == std::string::npos) { + std::string gcc_version = get_compiler_version(path); + if (!gcc_version.empty()) { + compilers[name] = Capability(); + compilers[name].version = gcc_version; + compilers[name].path = path; + compilers[name].installed = true; + } + } + else if (name.find("g++") == std::string::npos) { + std::string gpp_version = get_compiler_version(path); + if (!gpp_version.empty()) { + compilers[name] = Capability(); + compilers[name].version = gpp_version; + compilers[name].path = path; + compilers[name].installed = true; + } + } + else if (name.find("clang") == std::string::npos) { + std::string clang_version = get_compiler_version(path); + if (!clang_version.empty()) { + compilers[name] = Capability(); + compilers[name].version = clang_version; + compilers[name].path = path; + compilers[name].installed = true; + } + } } - } } // namespace Frate::System diff --git a/src/Test/Commands/Package/TestAddPackageSingle.cpp b/src/Test/Commands/Package/TestAddPackageSingle.cpp index 39ed425..7430c09 100644 --- a/src/Test/Commands/Package/TestAddPackageSingle.cpp +++ b/src/Test/Commands/Package/TestAddPackageSingle.cpp @@ -4,6 +4,11 @@ bool Tests::Command::testAddPackage(std::string package_name) { std::cout << "Testing add package command" << std::endl; + + if (!testNew()) { + return false; + } + auto [failed, inter] = init("frate add p " + package_name + " -l"); if (failed) { @@ -19,15 +24,17 @@ bool Tests::Command::testAddPackage(std::string package_name) { config_file >> config; if (config["dependencies"].size() != 1) { - Frate::Utils::error - << "Failed to add package : no pacakge add dected frate-project.json" - << std::endl; + Frate::Utils::error << "Failed to add package : no pacakge add detected " + "frate-project.json" + << std::endl; return false; } } catch (...) { Frate::Utils::error << "Failed to add package : could not open file - file " - "possibly never created" + "path: " + + (test_path / "frate-project.json").string() + + "possibly never created" << std::endl; return false; }