improve cmd

This commit is contained in:
西风逍遥游 committed 2021-10-24 22:37:07 -07:00
1 parent 3445b18b1f
commit a51708bb65
9 files changed
+229 -77

No files matched your search

+1 -61
View File
@@ -31,65 +31,5 @@ public:
int main(int argc, char **argv)
{
string log_path, output_path, current_path, platform;
bool version = false, no_window = false, debug = false, release = false;
int res = 0;
CLI::App app{"EVEngine - A Modern Game Engine"};
app.add_flag("-v,--version", version, "Print version string");
auto formatter = std::make_shared<MyFormatter>();
auto run = app.add_subcommand("run", "Run game under current path");
run->allow_extras()->formatter(formatter);
run->add_flag("--no-window", no_window, "Run script only, no window mode");
run->add_flag("--debug", debug, "debug mode");
run->add_option("-l,--log", log_path, "log messages into a file");
auto build = app.add_subcommand("build", "Build the game under current path");
build->allow_extras()->formatter(formatter);
build->add_option("-p,--platform", platform, "Build platform (linux, macosx, win32, win32_uwp, ios, android)");
build->add_flag("-r,--release", release, "release build (default)");
build->add_flag("-d,--debug", debug, "debug build");
build->add_option("-l,--log", log_path, "log messages into a file");
auto create = app.add_subcommand("create", "Create a new game from template");
create->allow_extras();
try {
app.parse(argc, argv);
} catch (const CLI::ParseError &e) {
return app.exit(e);
}
Cmdline* cmd = Cmdline::create();
cmd->setArg0(argv[0]);
if (build->parsed()) {
if (debug && release) {
cerr << rang::fg::red << "Build type can not be both debug and release" << rang::fg::reset << endl;
exit(1);
}
if (!debug && !release) { release = true; }
current_path = get_remaining(run);
res = cmd->Build(current_path, output_path, platform);
}
if (create->parsed()) {
string name = get_remaining(create, "mygame");
res = cmd->Create(".", name);
cout << rang::fg::green << "Created " << name << " in current path" << rang::fg::reset << endl;
}
if (run->parsed() || argc == 1) {
current_path = get_remaining(run);
res = cmd->Run(current_path);
}
if (version) {
cout << EVENGINE_VERSION << endl;
}
return res;
return requireModInst(eve::cmd,Cmdline)->runArgs(argc, argv);
}