1
0

feat: move all print work into main file in BMapInspector

This commit is contained in:
2026-01-31 23:38:26 +08:00
parent c664eaba0e
commit def46d1b8f
6 changed files with 111 additions and 67 deletions

View File

@@ -13,9 +13,10 @@
using namespace yycc::patch::stream;
namespace strop = yycc::string::op;
namespace termcolor = yycc::carton::termcolor;
using termcolor::Color;
static void PrintSplash() {
std::cout << termcolor::colored(u8"" BMAPINSP_NAME, termcolor::Color::LightYellow)
std::cout << termcolor::colored(u8"" BMAPINSP_NAME, Color::LightYellow)
<< " (based on LibCmo " LIBCMO_VER_STR ") built at " __DATE__ " " __TIME__ << std::endl
<< u8"" BMAPINSP_DESC << std::endl;
}
@@ -27,44 +28,47 @@ static std::optional<BMapInspector::Cli::Args> AcceptArgs() {
} else {
using BMapInspector::Cli::Error;
std::u8string bad_words;
std::u8string err_words;
switch (request.error()) {
case Error::BadParse:
bad_words = u8"Can not parse given command line argument."; break;
case Error::NoFile:
bad_words = u8"You must specify a file for checking.";
err_words = u8"Can not parse given command line argument.";
break;
case Error::NoFile:
err_words = u8"You must specify a file for checking.";
break;
case Error::BadFile:
bad_words = u8"Your specified file is invalid.";
err_words = u8"Your specified file is invalid.";
break;
case Error::NoBallance:
bad_words = u8"You must specify Ballance root directory for finding resources.";
err_words = u8"You must specify Ballance root directory for finding resources.";
break;
case Error::BadBallance:
bad_words = u8"Your specified Ballance root directory is invalid.";
err_words = u8"Your specified Ballance root directory is invalid.";
break;
case Error::BadEncoding:
bad_words = u8"Your specified encoding name is invalid.";
err_words = u8"Your specified encoding name is invalid.";
break;
case Error::BadLevel:
bad_words = u8"Your specified report level filter name is invalid.";
err_words = u8"Your specified report level filter name is invalid.";
break;
default:
bad_words = u8"Unknown error.";
err_words = u8"Unknown error.";
break;
}
termcolor::cprintln(bad_words, termcolor::Color::Red);
termcolor::cprintln(u8"Please browse manual or use -h switch to see help first.", termcolor::Color::Red);
termcolor::cprintln(err_words, Color::Red);
termcolor::cprintln(u8"Please browse manual or use -h switch to see help first.", Color::Red);
return std::nullopt;
}
}
static void LoadVirtools() {}
static std::optional<BMapInspector::Ruleset::RuleContext> LoadVirtools(BMapInspector::Cli::Args& args) {
return std::nullopt;
}
static void CheckRules() {
static void CheckRules(BMapInspector::Ruleset::RuleContext& ctx) {
// Create reporter
BMapInspector::Reporter reporter;
BMapInspector::Reporter::Reporter reporter;
// Get rule collection
BMapInspector::Ruleset::RuleCollection rule_collection;
@@ -72,19 +76,45 @@ static void CheckRules() {
std::cout << strop::printf(u8"Total %" PRIuSIZET " rule(s) are loaded.", rule_collection.GetRuleCount()) << std::endl
<< u8"Check may take few minutes. Please do not close this console..." << std::endl;
// Check rules one by one
for (auto* rule : rule_collection.GetRules()) {
rule->Check(reporter, ctx);
}
// Show report conclusion
reporter.PrintConclusion();
auto digest = reporter.GetDigest();
termcolor::cprintln(strop::printf(u8"Total %" PRIuSIZET " error(s), %" PRIuSIZET " warning(s) and %" PRIuSIZET " info(s).",
digest.cnt_err,
digest.cnt_warn,
digest.cnt_info),
Color::LightYellow);
// Print report in detail
reporter.PrintReport();
using BMapInspector::Utils::ReportLevel;
for (const auto& report : reporter.GetReports()) {
switch (report.level) {
case ReportLevel::Error:
termcolor::cprintln(strop::printf(u8"[ERROR] [RULE: %s] %s", report.rule.c_str(), report.content.c_str()), Color::Red);
break;
case ReportLevel::Warning:
termcolor::cprintln(strop::printf(u8"[WARNING] [RULE: %s] %s", report.rule.c_str(), report.content.c_str()), Color::Yellow);
break;
case ReportLevel::Info:
termcolor::cprintln(strop::printf(u8"[INFO] [RULE: %s] %s", report.rule.c_str(), report.content.c_str()), Color::White);
break;
}
}
}
int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
auto args = AcceptArgs();
if (args.has_value()) {
PrintSplash();
std::cout << std::endl;
CheckRules();
auto ctx = LoadVirtools(args.value());
if (ctx.has_value()) {
CheckRules(ctx.value());
}
}
return 0;
}