improved CLI
This commit is contained in:
parent
d3f6c09ac4
commit
fbc13a9897
5 changed files with 112 additions and 66 deletions
43
main.cpp
43
main.cpp
|
|
@ -1,3 +1,4 @@
|
|||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <print>
|
||||
|
|
@ -5,22 +6,32 @@
|
|||
import Crafter.Build;
|
||||
using namespace Crafter::Build;
|
||||
int main(int argc, char* argv[]) {
|
||||
if(argc == 1){
|
||||
std::println("No configuration provided, use --help for help");
|
||||
} else if(argc == 2) {
|
||||
if(std::string(argv[1]) == "--help"){
|
||||
std::println("<configuration> to build this configuration with the defualt project filename \"project.json\"\n<configuration> <project> to build this configuration with the specified project filename\nhelp displays this help message");
|
||||
} else {
|
||||
Project project = Project::LoadFromJSON("./project.json");
|
||||
project.Build(argv[1]);
|
||||
if(argc == 1) {
|
||||
std::println("No arguments provided, use --help for help");
|
||||
}
|
||||
std::string filename = "project.json";
|
||||
std::string configuration;
|
||||
std::string outputDir;
|
||||
for (std::uint_fast32_t i = 1; i < argc; i++) {
|
||||
std::string arg = std::string(argv[i]);
|
||||
if(arg == "--help"){
|
||||
std::println("--help\tDisplays this help message.\n-c The name of the configuration to build.\n-p\nThe name of the project file.\n-o Overrides the output folder.\n");
|
||||
return 0;
|
||||
} else if(arg == "-c"){
|
||||
configuration = argv[++i];
|
||||
} else if(arg == "-o"){
|
||||
outputDir = argv[++i];
|
||||
} else if(arg == "-p"){
|
||||
filename = argv[++i];
|
||||
} else{
|
||||
std::println("Unkown argument: {}", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else if(argc == 3) {
|
||||
Project project = Project::LoadFromJSON(argv[2]);
|
||||
project.Build(argv[1]);
|
||||
return 0;
|
||||
} else {
|
||||
std::println("Too many arguments provided");
|
||||
return 1;
|
||||
}
|
||||
Project project = Project::LoadFromJSON(filename);
|
||||
if(outputDir.empty()){
|
||||
project.Build(configuration);
|
||||
} else{
|
||||
project.Build(configuration, outputDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue