From 4d9dee17e5b583aff840d8de30f960567ba6f2c8 Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 21 Oct 2023 23:01:37 -0700 Subject: [PATCH] fixed path error --- src/Command/Command.h | 2 +- src/Command/CommandGeneral.cpp | 4 ++-- src/Command/CommandInit.cpp | 42 ++++++++++++++++++---------------- src/main.cpp | 39 +++++++++++++++---------------- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Command/Command.h b/src/Command/Command.h index b4d9e6d..d1eb6cf 100644 --- a/src/Command/Command.h +++ b/src/Command/Command.h @@ -35,7 +35,7 @@ typedef struct Context { } Context; bool loadPackageToml(std::shared_ptr ctx); -bool init(std::shared_ptr, std::vector args); +bool init(std::shared_ptr, std::vector &args); bool run(std::shared_ptr); bool ftp(std::shared_ptr); bool addFlag(std::shared_ptr, std::string); diff --git a/src/Command/CommandGeneral.cpp b/src/Command/CommandGeneral.cpp index a7e447c..92c465b 100644 --- a/src/Command/CommandGeneral.cpp +++ b/src/Command/CommandGeneral.cpp @@ -6,7 +6,7 @@ namespace Command { bool loadPackageToml(std::shared_ptr ctx) { try { - auto data = toml::parse_file("./config.toml"); + auto data = toml::parse_file("./build/config.toml"); ctx->project_name = data["project"]["project_name"].value_or("no name"); for (auto &author : *data["project"]["authors"].as_array()) { ctx->authors.push_back(author.value_or("no author")); @@ -56,7 +56,7 @@ bool writePackageToml(std::shared_ptr ctx) { }}, }; std::ofstream file; - file.open("./config.toml"); + file.open("./build/config.toml"); file << table; file << '\n'; file.close(); diff --git a/src/Command/CommandInit.cpp b/src/Command/CommandInit.cpp index 87dbe17..9d7ce4d 100644 --- a/src/Command/CommandInit.cpp +++ b/src/Command/CommandInit.cpp @@ -122,9 +122,9 @@ bool createToml(std::shared_ptr ctx) { } bool createHelloWorldCpp() { - system("mkdir src"); + system("cd build;mkdir src"); std::ofstream file; - file.open("./src/main.cpp"); + file.open("./build/src/main.cpp"); file << "#include \n" "int main(){\n" @@ -162,41 +162,43 @@ bool createCProject(std::shared_ptr ctx) { return false; } -bool defaultTomlCpp(std::shared_ptr ctx) { - ctx->project_name = "cppProject"; +bool defaultTomlCpp(std::shared_ptr ctx) { + ctx->project_name = "TestProject"; + ctx->src_dir = "./src"; + ctx->build_dir = "./build"; toml::array authors = toml::array{}; toml::table table = toml::table{ {"project", - toml::table{ - {"cmake_version", ctx->cmake_version}, - {"include_dir", ctx->include_dir}, - {"project_version", ctx->project_version}, - {"compiler", ctx->compiler}, - {"project_name", ctx->project_name}, - {"authors", authors}, - {"src_dir", ctx->src_dir}, - {"build_dir", ctx->build_dir}, - {"lang", ctx->lang}, - {"lang_version", ctx->lang_version}, - }}, + toml::table{ + {"cmake_version", ctx->cmake_version}, + {"include_dir", ctx->include_dir}, + {"project_version", ctx->project_version}, + {"compiler", ctx->compiler}, + {"project_name", ctx->project_name}, + {"authors", authors}, + {"src_dir", ctx->src_dir}, + {"build_dir", ctx->build_dir}, + {"lang", ctx->lang}, + {"lang_version", ctx->lang_version}, + }}, }; std::cout << "📄New Toml File: \n"; std::cout << table << '\n'; std::ofstream file; - file.open("./config.toml"); + file.open("./build/config.toml"); file << table; file << '\n'; file.close(); - return true; + return false; } -bool init(std::shared_ptr ctx, std::vector args) +bool init(std::shared_ptr ctx, std::vector &args) { if (std::find(args.begin(), args.end(), "-y") != args.end()) - { + { defaultTomlCpp(ctx); loadPackageToml(ctx); createCMakelists(ctx); diff --git a/src/main.cpp b/src/main.cpp index d62e331..003280c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,15 +3,13 @@ #include #include +/// @brief command options from user input. _must_ match map enum cmd_options { - i = 0, - init = 1, - r = 2, - run = 3, - flags = 4, - help = 5 - + help = -1, + i, init = 0, + r, run = 2, + flags = 3, }; int main(int argc, char **argv) @@ -24,16 +22,17 @@ int main(int argc, char **argv) return 1; } - std::string command = argv[1]; + std::string command = argv[1]; std::vector args; for (int i = 2; i < argc; i++) { - args.push_back(argv[i]); + args.push_back(argv[i]); } - + // LUCAS MAKE SURE YOU INITIALIZE YOUR FUCKING STRUCT YOU TWAT std::shared_ptr ctx = std::make_shared(); + /// table reflects what enum cmd_options contains to switch on user input. static std::map const table = { {"i", cmd_options::i}, {"init", cmd_options::init}, @@ -43,36 +42,34 @@ int main(int argc, char **argv) {"help", cmd_options::help}, }; // default if they accidentily pass nothing - auto selection = cmd_options::help; - + auto selection = cmd_options::help; auto it = table.find(command); if (it != table.end()) { selection = it->second; } + switch (selection) { + case -1: // help + default: + Command::help(); + break; + case 0: // i / init - case 1: Command::init(ctx, args); break; - case 2: // r / run - case 3: + case 1: // r / run Command::loadPackageToml(ctx); Command::run(ctx); break; - case 4: // flags + case 2: // flags Command::loadPackageToml(ctx); Command::addFlag(ctx, argv[2]); break; - - case 5: // help - default: - Command::help(); - break; } return 0; }