载入中...
搜索中...
未找到
Zip.cpp
浏览该文件的文档.
1#include "cmdline.h"
2#include "zip_writer.h"
3#include <filesystem>
4#include <CLI11.hpp>
5#include <rang.hpp>
6
7using namespace std::filesystem;
8using namespace std;
9
10namespace eve::cmd
11{
12
13struct ZipArgs : Handler {
14 void setup(CLI::App& app, std::shared_ptr<CLI::Formatter> formatter) override {
15 auto subcmd = app.add_subcommand("zip", "Zip the game to a .eve package");
16 subcmd->allow_extras();
17 }
18
19 int parse(CLI::App& app, Cmdline& cmd) override {
20 auto subcmd = app.get_subcommand("zip");
21 if (subcmd->parsed()) {
22 string name = cmd.get_remaining(subcmd, ".");
23 int res = cmd.Zip(name);
24 return res;
25 }
26 return -1; // not handle
27 }
28};
29
31
32
33int Cmdline::Zip(std::string path) {
34 std::error_code ec;
35 if (!is_directory(path, ec)) {
36 cerr << rang::fg::red << "Not a directory: " << rang::fg::reset << path << endl;
37 return 1;
38 }
39
40 std::string outName = path;
41 // Normalize trailing separators so the output name is the game folder name.
42 while (!outName.empty() && (outName.back() == '/' || outName.back() == '\\'))
43 outName.pop_back();
44 outName += ".eve";
45
46 if (!cmdline::createGameArchive(path, outName)) {
47 cerr << rang::fg::red << "Failed to write archive: " << rang::fg::reset << outName << endl;
48 return 2;
49 }
50
51 cout << rang::fg::green << "Packaged game -> " << rang::fg::reset << outName << endl;
52 return 0;
53}
54
55} // namespace eve
const char * name
Definition RockMesh.cpp:21
命令行模块(eve.cmd):run / build / package / test / zip / dev-server 等子命令入口。
Definition cmdline.h:30
static std::string get_remaining(CLI::App *sub, std::string default_path=".")
子命令剩余位置参数。
Definition cmdline.cpp:79
int Zip(std::string path)
把当前目录打成 .eve 压缩包。
Definition Zip.cpp:33
#define CMD_REG(name)
Definition cmdline.h:92
bool createGameArchive(const std::filesystem::path &gameDir, const std::filesystem::path &outArchive)
Definition zip_writer.h:181
One eve <subcommand> handler: CLI setup + argument parsing.
Definition cmdline.h:21
int parse(CLI::App &app, Cmdline &cmd) override
Parses arguments and runs the command; returns the exit code.
Definition Zip.cpp:19
void setup(CLI::App &app, std::shared_ptr< CLI::Formatter > formatter) override
Registers options on the CLI11 sub-app.
Definition Zip.cpp:14