Skip to content

Commit

Permalink
fixed path error
Browse files Browse the repository at this point in the history
  • Loading branch information
ExtremelyRyan committed Oct 22, 2023
1 parent ef73560 commit 4d9dee1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Command/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef struct Context {
} Context;

bool loadPackageToml(std::shared_ptr<Context> ctx);
bool init(std::shared_ptr<Context>, std::vector<std::string> args);
bool init(std::shared_ptr<Context>, std::vector<std::string> &args);
bool run(std::shared_ptr<Context>);
bool ftp(std::shared_ptr<Context>);
bool addFlag(std::shared_ptr<Context>, std::string);
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CommandGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Command {
bool loadPackageToml(std::shared_ptr<Context> 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"));
Expand Down Expand Up @@ -56,7 +56,7 @@ bool writePackageToml(std::shared_ptr<Context> ctx) {
}},
};
std::ofstream file;
file.open("./config.toml");
file.open("./build/config.toml");
file << table;
file << '\n';
file.close();
Expand Down
42 changes: 22 additions & 20 deletions src/Command/CommandInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ bool createToml(std::shared_ptr<Context> 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 <iostream>\n"
"int main(){\n"
Expand Down Expand Up @@ -162,41 +162,43 @@ bool createCProject(std::shared_ptr<Context> ctx) {
return false;
}

bool defaultTomlCpp(std::shared_ptr<Context> ctx) {
ctx->project_name = "cppProject";
bool defaultTomlCpp(std::shared_ptr<Context> 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<Context> ctx, std::vector<std::string> args)
bool init(std::shared_ptr<Context> ctx, std::vector<std::string> &args)
{

if (std::find(args.begin(), args.end(), "-y") != args.end())
{
{
defaultTomlCpp(ctx);
loadPackageToml(ctx);
createCMakelists(ctx);
Expand Down
39 changes: 18 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
#include <memory>
#include <string>

/// @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)
Expand All @@ -24,16 +22,17 @@ int main(int argc, char **argv)
return 1;
}

std::string command = argv[1];
std::string command = argv[1];
std::vector<std::string> 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<Command::Context> ctx = std::make_shared<Command::Context>();

/// table reflects what enum cmd_options contains to switch on user input.
static std::map<std::string, cmd_options> const table = {
{"i", cmd_options::i},
{"init", cmd_options::init},
Expand All @@ -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;
}

0 comments on commit 4d9dee1

Please sign in to comment.