rename handle to Run for cli commands
This commit is contained in:
@@ -3,18 +3,16 @@
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
|
||||
absl::Status Compress::handle(const std::vector<std::string>& arg_vec) {
|
||||
absl::Status Compress::Run(const std::vector<std::string>& arg_vec) {
|
||||
std::cout << "Compress selected with argument: " << arg_vec[0] << std::endl;
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status Decompress::handle(const std::vector<std::string>& arg_vec) {
|
||||
ColorModifier underline(ColorCode::FG_UNDERLINE);
|
||||
ColorModifier reset(ColorCode::FG_RESET);
|
||||
absl::Status Decompress::Run(const std::vector<std::string>& arg_vec) {
|
||||
std::cout << "Please specify the tilesheets you want to export\n";
|
||||
std::cout << "You can input an individual sheet, a range X-Y, or comma "
|
||||
"separate values.\n\n";
|
||||
std::cout << underline << "Tilesheets\n" << reset;
|
||||
std::cout << "Tilesheets\n";
|
||||
std::cout << "0-112 -> compressed 3bpp bgr \n";
|
||||
std::cout << "113-114 -> compressed 2bpp\n";
|
||||
std::cout << "115-126 -> uncompressed 3bpp sprites\n";
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
#include "cli/z3ed.h"
|
||||
|
||||
#include "asar-dll-bindings/c/asar.h"
|
||||
|
||||
#include "cli/z3ed.h"
|
||||
#include "util/bps.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
|
||||
absl::Status ApplyPatch::handle(const std::vector<std::string>& arg_vec) {
|
||||
absl::Status ApplyPatch::Run(const std::vector<std::string>& arg_vec) {
|
||||
std::string rom_filename = arg_vec[1];
|
||||
std::string patch_filename = arg_vec[2];
|
||||
RETURN_IF_ERROR(rom_.LoadFromFile(rom_filename))
|
||||
@@ -28,7 +26,7 @@ absl::Status ApplyPatch::handle(const std::vector<std::string>& arg_vec) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status AsarPatch::handle(const std::vector<std::string>& arg_vec) {
|
||||
absl::Status AsarPatch::Run(const std::vector<std::string>& arg_vec) {
|
||||
std::string patch_filename = arg_vec[1];
|
||||
std::string rom_filename = arg_vec[2];
|
||||
RETURN_IF_ERROR(rom_.LoadFromFile(rom_filename))
|
||||
@@ -47,7 +45,7 @@ absl::Status AsarPatch::handle(const std::vector<std::string>& arg_vec) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status CreatePatch::handle(const std::vector<std::string>& arg_vec) {
|
||||
absl::Status CreatePatch::Run(const std::vector<std::string>& arg_vec) {
|
||||
std::vector<uint8_t> source;
|
||||
std::vector<uint8_t> target;
|
||||
std::vector<uint8_t> patch;
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "util/macro.h"
|
||||
#include "app/rom.h"
|
||||
#include "cli/z3ed.h"
|
||||
#include "util/macro.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
|
||||
absl::Status Tile16Transfer::handle(const std::vector<std::string>& arg_vec) {
|
||||
absl::Status Tile16Transfer::Run(const std::vector<std::string>& arg_vec) {
|
||||
// Load the source rom
|
||||
RETURN_IF_ERROR(rom_.LoadFromFile(arg_vec[0]))
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
#include "app/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
/**
|
||||
* @namespace yaze::cli
|
||||
* @brief Namespace for the command line interface.
|
||||
*/
|
||||
namespace cli {
|
||||
|
||||
const std::vector<std::string> kMainMenuEntries = {
|
||||
"Load ROM",
|
||||
"Apply BPS Patch",
|
||||
|
||||
@@ -26,45 +26,9 @@ DEFINE_FLAG(std::string, dest_rom, "", "The destination ROM file.");
|
||||
DEFINE_FLAG(std::string, tile32_id_list, "",
|
||||
"The list of tile32 IDs to transfer.");
|
||||
|
||||
namespace yaze {
|
||||
/**
|
||||
* @namespace yaze::cli
|
||||
* @brief Namespace for the command line interface.
|
||||
*/
|
||||
namespace cli {
|
||||
namespace {
|
||||
|
||||
int RunCommandHandler(int argc, char *argv[]) {
|
||||
std::vector<std::string> arguments;
|
||||
for (int i = 2; i < argc; i++) { // Skip the arg mode (argv[1])
|
||||
std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
|
||||
arguments.emplace_back(argv[i]);
|
||||
}
|
||||
|
||||
Commands commands;
|
||||
std::string mode = argv[1];
|
||||
if (commands.handlers.find(mode) != commands.handlers.end()) {
|
||||
PRINT_IF_ERROR(commands.handlers[mode]->handle(arguments))
|
||||
} else {
|
||||
std::cerr << "Invalid mode specified: " << mode << std::endl;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace cli
|
||||
} // namespace yaze
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
yaze::util::FlagParser flag_parser(yaze::util::global_flag_registry());
|
||||
RETURN_IF_EXCEPTION(flag_parser.Parse(argc, argv));
|
||||
|
||||
for (const auto &flag : yaze::util::global_flag_registry()->AllFlags()) {
|
||||
// Cast the IFlag to a Flag and use Get
|
||||
auto flags = dynamic_cast<yaze::util::Flag<std::string> *>(flag);
|
||||
std::cout << "Flag: " << flag->name() << " = " << flags->Get() << std::endl;
|
||||
}
|
||||
|
||||
yaze::cli::ShowMain();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -16,77 +16,49 @@
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
|
||||
enum ColorCode {
|
||||
FG_RED = 31,
|
||||
FG_GREEN = 32,
|
||||
FG_YELLOW = 33,
|
||||
FG_BLUE = 36,
|
||||
FG_MAGENTA = 35,
|
||||
FG_DEFAULT = 39,
|
||||
FG_RESET = 0,
|
||||
FG_UNDERLINE = 4,
|
||||
BG_RED = 41,
|
||||
BG_GREEN = 42,
|
||||
BG_BLUE = 44,
|
||||
BG_DEFAULT = 49
|
||||
};
|
||||
class ColorModifier {
|
||||
ColorCode code;
|
||||
|
||||
public:
|
||||
explicit ColorModifier(ColorCode pCode) : code(pCode) {}
|
||||
friend std::ostream& operator<<(std::ostream& os, const ColorModifier& mod) {
|
||||
return os << "\033[" << mod.code << "m";
|
||||
}
|
||||
};
|
||||
|
||||
class CommandHandler {
|
||||
public:
|
||||
CommandHandler() = default;
|
||||
virtual ~CommandHandler() = default;
|
||||
virtual absl::Status handle(const std::vector<std::string>& arg_vec) = 0;
|
||||
virtual absl::Status Run(const std::vector<std::string>& arg_vec) = 0;
|
||||
|
||||
Rom rom_;
|
||||
};
|
||||
|
||||
class ApplyPatch : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override;
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override;
|
||||
};
|
||||
|
||||
class AsarPatch : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override;
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override;
|
||||
};
|
||||
|
||||
class CreatePatch : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override;
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override;
|
||||
};
|
||||
|
||||
class Tile16Transfer : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override;
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override;
|
||||
};
|
||||
|
||||
class Open : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override {
|
||||
ColorModifier green(ColorCode::FG_GREEN);
|
||||
ColorModifier blue(ColorCode::FG_BLUE);
|
||||
ColorModifier reset(ColorCode::FG_RESET);
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override {
|
||||
auto const& arg = arg_vec[0];
|
||||
RETURN_IF_ERROR(rom_.LoadFromFile(arg))
|
||||
std::cout << "Title: " << green << rom_.title() << std::endl;
|
||||
std::cout << reset << "Size: " << blue << "0x" << std::hex << rom_.size()
|
||||
<< reset << std::endl;
|
||||
std::cout << "Title: " << rom_.title() << std::endl;
|
||||
std::cout << "Size: 0x" << std::hex << rom_.size() << std::endl;
|
||||
return absl::OkStatus();
|
||||
}
|
||||
};
|
||||
|
||||
class Backup : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override {
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override {
|
||||
RETURN_IF_ERROR(rom_.LoadFromFile(arg_vec[0]))
|
||||
if (arg_vec.size() == 2) {
|
||||
// Optional filename added
|
||||
@@ -100,12 +72,12 @@ class Backup : public CommandHandler {
|
||||
|
||||
class Compress : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override;
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override;
|
||||
};
|
||||
|
||||
class Decompress : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override;
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,7 +88,7 @@ class Decompress : public CommandHandler {
|
||||
*/
|
||||
class SnesToPcCommand : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override {
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override {
|
||||
auto arg = arg_vec[0];
|
||||
std::stringstream ss(arg.data());
|
||||
uint32_t snes_address;
|
||||
@@ -135,16 +107,14 @@ class SnesToPcCommand : public CommandHandler {
|
||||
*/
|
||||
class PcToSnesCommand : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override {
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override {
|
||||
auto arg = arg_vec[0];
|
||||
std::stringstream ss(arg.data());
|
||||
uint32_t pc_address;
|
||||
ss >> std::hex >> pc_address;
|
||||
uint32_t snes_address = PcToSnes(pc_address);
|
||||
ColorModifier blue(ColorCode::FG_BLUE);
|
||||
std::cout << "SNES LoROM Address: ";
|
||||
std::cout << blue << "$" << std::uppercase << std::hex << snes_address
|
||||
<< "\n";
|
||||
std::cout << "$" << std::uppercase << std::hex << snes_address << "\n";
|
||||
return absl::OkStatus();
|
||||
}
|
||||
};
|
||||
@@ -157,7 +127,7 @@ class PcToSnesCommand : public CommandHandler {
|
||||
*/
|
||||
class ReadFromRom : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override {
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override {
|
||||
RETURN_IF_ERROR(rom_.LoadFromFile(arg_vec[0]))
|
||||
|
||||
std::stringstream ss(arg_vec[1].data());
|
||||
@@ -195,7 +165,7 @@ class ReadFromRom : public CommandHandler {
|
||||
*/
|
||||
class Expand : public CommandHandler {
|
||||
public:
|
||||
absl::Status handle(const std::vector<std::string>& arg_vec) override {
|
||||
absl::Status Run(const std::vector<std::string>& arg_vec) override {
|
||||
RETURN_IF_ERROR(rom_.LoadFromFile(arg_vec[0]))
|
||||
|
||||
std::stringstream ss(arg_vec[1].data());
|
||||
@@ -211,26 +181,6 @@ class Expand : public CommandHandler {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Command handler for the CLI.
|
||||
*/
|
||||
struct Commands {
|
||||
std::unordered_map<std::string, std::shared_ptr<CommandHandler>> handlers = {
|
||||
{"-a", std::make_shared<ApplyPatch>()},
|
||||
{"-asar", std::make_shared<AsarPatch>()},
|
||||
{"-c", std::make_shared<CreatePatch>()},
|
||||
{"-o", std::make_shared<Open>()},
|
||||
{"-b", std::make_shared<Backup>()},
|
||||
{"-x", std::make_shared<Expand>()},
|
||||
{"-i", std::make_shared<Compress>()}, // Import
|
||||
{"-e", std::make_shared<Decompress>()}, // Export
|
||||
{"-s", std::make_shared<SnesToPcCommand>()},
|
||||
{"-p", std::make_shared<PcToSnesCommand>()},
|
||||
{"-t", std::make_shared<Tile16Transfer>()},
|
||||
{"-r", std::make_shared<ReadFromRom>()} // Read from Rom
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace cli
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
Reference in New Issue
Block a user