Files
Torch/src/main.cpp
T

93 lines
3.1 KiB
C++
Raw Normal View History

2023-08-17 00:40:00 -06:00
#include <iostream>
#include "CLI11.hpp"
#include "Companion.h"
2023-09-24 15:59:09 -06:00
#ifdef STANDALONE
2023-08-17 00:40:00 -06:00
Companion* Companion::Instance;
int main(int argc, char *argv[]) {
2023-11-15 15:11:15 -06:00
CLI::App app{"Torch - [T]orch is [O]ur [R]esource [C]onversion [H]elper\n\
* It extracts from a baserom and generates code or an otr.\n\
* It can also generate an otr from a folder of assets.\n"
};
std::string mode;
std::string filename;
std::string target;
std::string folder;
bool otrMode = false;
bool debug = false;
2023-08-17 00:40:00 -06:00
2023-11-15 15:11:15 -06:00
app.require_subcommand();
2023-11-15 15:11:15 -06:00
/* Generate an OTR */
2024-01-31 11:58:51 -06:00
const auto otr = app.add_subcommand("otr", "OTR - Generates an otr\n");
2023-11-15 15:11:15 -06:00
otr->add_option("<baserom.z64>", filename, "")->required()->check(CLI::ExistingFile);
otr->add_flag("-v,--verbose", debug, "Verbose Debug Mode");
2024-01-31 11:58:51 -06:00
otr->parse_complete_callback([&] {
const auto instance = Companion::Instance = new Companion(filename, true, debug);
instance->Init(ExportType::Binary);
2023-11-15 15:11:15 -06:00
});
/* Generate C code */
2024-01-31 11:58:51 -06:00
const auto code = app.add_subcommand("code", "Code - Generates C code\n");
2023-11-15 15:11:15 -06:00
code->add_option("<baserom.z64>", filename, "")->required()->check(CLI::ExistingFile);
code->add_flag("-v,--verbose", debug, "Verbose Debug Mode; adds offsets to C code");
2024-01-31 11:58:51 -06:00
2023-11-15 15:11:15 -06:00
code->parse_complete_callback([&]() {
2024-01-31 11:58:51 -06:00
const auto instance = Companion::Instance = new Companion(filename, false, debug);
2023-11-15 15:11:15 -06:00
instance->Init(ExportType::Code);
});
2023-08-17 00:40:00 -06:00
2024-01-31 11:58:51 -06:00
/* Generate a binary */
const auto binary = app.add_subcommand("binary", "Binary - Generates a binary\n");
binary->add_option("<baserom.z64>", filename, "")->required()->check(CLI::ExistingFile);
binary->parse_complete_callback([&] {
const auto instance = Companion::Instance = new Companion(filename, false, debug);
instance->Init(ExportType::Binary);
});
/* Generate headers */
const auto header = app.add_subcommand("header", "Header - Generates headers only\n");
header->add_option("<baserom.z64>", filename, "")->required()->check(CLI::ExistingFile);
header->add_flag("-o,--otr", otrMode, "OTR Mode");
header->parse_complete_callback([&] {
const auto instance = Companion::Instance = new Companion(filename, otrMode, debug);
instance->Init(ExportType::Header);
});
/* Pack an otr from a folder */
const auto pack = app.add_subcommand("pack", "Pack - Packs an otr from a folder\n");
pack->add_option("<folder>", folder, "Generate OTR from a directory of assets")->required()->check(CLI::ExistingDirectory);
pack->add_option("<target>", target, "OTR output destination")->required();
pack->parse_complete_callback([&] {
if (!folder.empty()) {
Companion::Pack(folder, target);
} else {
std::cout << "The folder is empty" << std::endl;
}
});
2023-08-17 00:40:00 -06:00
try {
app.parse(argc, argv);
} catch (const CLI::ParseError &e) {
2023-11-15 15:11:15 -06:00
std::cout << app.help() << std::endl;
2023-08-17 00:40:00 -06:00
return app.exit(e);
}
2023-11-15 15:11:15 -06:00
// No arguments --> display help.
if (argc == 1) {
std::cout << app.help() << std::endl;
}
2023-08-17 00:40:00 -06:00
return 0;
2023-09-24 15:59:09 -06:00
}
#endif