rewrite
This commit is contained in:
parent
23fa8b98b0
commit
0eed272765
35 changed files with 1634 additions and 1507 deletions
105
implementations/main.cpp
Normal file
105
implementations/main.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
Crafter.Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
import Crafter.Build;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
namespace fs = std::filesystem;
|
||||
int main(int argc, char* argv[]) {
|
||||
if(std::string(argv[1]) == "--help") {
|
||||
std::println("--help\tDisplays this help message.\n-c The name of the configuration to build.\n-p The path to the project file. defualts to project.json\n-o Overrides the output folder.\n-r Runs the executable after building.");
|
||||
return 0;
|
||||
}
|
||||
if(argc < 2 && std::string(argv[1]) == "build") {
|
||||
std::println("Too little arguments provided, use --help for help");
|
||||
return 0;
|
||||
}
|
||||
fs::path filepath = "project.json";
|
||||
std::string configuration;
|
||||
std::string outputDir;
|
||||
std::string command = std::string(argv[1]);
|
||||
std::string argument;
|
||||
if(argc > 2) {
|
||||
argument = std::string(argv[2]);
|
||||
}
|
||||
|
||||
bool run = false;
|
||||
for (std::uint_fast32_t i = 3; i < argc; i++) {
|
||||
std::string arg = std::string(argv[i]);
|
||||
if(arg == "-r"){
|
||||
run = true;
|
||||
} else if(arg == "-o"){
|
||||
outputDir = argv[++i];
|
||||
} else if(arg == "-p"){
|
||||
filepath = fs::path(argv[++i]);
|
||||
} else{
|
||||
std::println("Unkown argument: {}", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
fs::path projectPath;
|
||||
if(filepath.is_relative()){
|
||||
projectPath = fs::current_path()/filepath;
|
||||
}else{
|
||||
projectPath = filepath;
|
||||
}
|
||||
|
||||
Project project = Project::LoadFromJSON(projectPath);
|
||||
|
||||
if(command == "build") {
|
||||
if(outputDir.empty()){
|
||||
project.Build(argument);
|
||||
} else{
|
||||
project.Build(argument, fs::path(outputDir));
|
||||
}
|
||||
if(run){
|
||||
for(Configuration& config : project.configurations) {
|
||||
if(config.name == configuration) {
|
||||
if(config.debug) {
|
||||
system(std::format("cd {} && ./{}", (projectPath/fs::path(config.outputDir)).generic_string(), project.name).c_str());
|
||||
} else {
|
||||
system(std::format("cd {} && lldb -o run {}", (projectPath/fs::path(config.outputDir)).generic_string(), project.name).c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(command == "test") {
|
||||
if(argument.empty()) {
|
||||
std::vector<TestResult> results = project.RunTests();
|
||||
for(const TestResult& result : results) {
|
||||
if(result.message.empty()) {
|
||||
std::cout << std::format("✅ {}", result.name) << std::endl;
|
||||
} else {
|
||||
std::cout << std::format("❌ {}\t{}", result.name, result.message) << std::endl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TestResult result = project.RunTest(argument);
|
||||
if(result.message.empty()) {
|
||||
std::cout << std::format("✅ {}", result.name) << std::endl;
|
||||
} else {
|
||||
std::cout << std::format("❌ {}\t{}", result.name, result.message) << std::endl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::println("Unkown command: {}", command);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue