Add UI layout XML automation

This commit is contained in:
2026-06-01 00:21:23 +02:00
parent dfdb7a4468
commit 20b5dba41e
13 changed files with 245 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
#include "document/document.h"
#include "foundation/parse.h"
#include "foundation/result.h"
#include "ui_core/layout_xml.h"
#include <cstdint>
#include <fstream>
@@ -23,6 +24,10 @@ struct InspectImageArgs {
std::string path;
};
struct ParseLayoutArgs {
std::string path;
};
void print_error(std::string_view command, std::string_view message)
{
std::cout << "{\"ok\":false,\"command\":\"" << command
@@ -35,6 +40,7 @@ void print_help()
<< "pano_cli commands:\n"
<< " create-document --width N --height N [--layers N]\n"
<< " inspect-image --path FILE\n"
<< " parse-layout --path FILE\n"
<< " --help\n";
}
@@ -160,6 +166,60 @@ int inspect_image(int argc, char** argv)
return 0;
}
pp::foundation::Status parse_layout_args(int argc, char** argv, ParseLayoutArgs& args)
{
for (int i = 2; i < argc; ++i) {
const std::string_view key(argv[i]);
if (key == "--path") {
if (i + 1 >= argc) {
return pp::foundation::Status::invalid_argument("missing value for option");
}
args.path = argv[++i];
} else {
return pp::foundation::Status::invalid_argument("unknown option");
}
}
if (args.path.empty()) {
return pp::foundation::Status::invalid_argument("path must not be empty");
}
return pp::foundation::Status::success();
}
int parse_layout(int argc, char** argv)
{
ParseLayoutArgs args;
const auto status = parse_layout_args(argc, argv, args);
if (!status.ok()) {
print_error("parse-layout", status.message);
return 2;
}
std::ifstream stream(args.path, std::ios::binary);
if (!stream) {
print_error("parse-layout", "layout file could not be opened");
return 2;
}
const std::string xml {
std::istreambuf_iterator<char>(stream),
std::istreambuf_iterator<char>()
};
const auto summary = pp::ui::parse_layout_xml(xml);
if (!summary) {
print_error("parse-layout", summary.status().message);
return 2;
}
std::cout << "{\"ok\":true,\"command\":\"parse-layout\""
<< ",\"nodes\":" << summary.value().node_count
<< ",\"lengthAttributes\":" << summary.value().length_attribute_count
<< "}\n";
return 0;
}
}
int main(int argc, char** argv)
@@ -183,6 +243,10 @@ int main(int argc, char** argv)
return inspect_image(argc, argv);
}
if (command == "parse-layout") {
return parse_layout(argc, argv);
}
print_error(command, "unknown command");
return 2;
}