24 :
Command{parent_app, command_name, command_desc, command_group}
27 cmd.add_option(
"<tileset-name>", tileset_name_,
"Name of the tileset to resolve the schema for")->required();
29 "--allow-missing-tileset",
30 allow_missing_tileset_,
31 "Resolve the schema even when the tileset does not exist, to preview what a new tileset would get.");
42 auto *text_formatter = env.text_formatter;
46 const auto env_result = env.initialize(tileset_name_);
47 if (!env_result.has_value()) {
50 "Failed to dump attribute schema for tileset '{}'.",
FormatParam{tileset_name_, Style::bold}},
52 env.stderr_diag.fatal(env_fail_result);
53 throw CLI::RuntimeError{1};
59 if (!allow_missing_tileset_) {
61 if (!metadata_provider.exists(tileset_name_)) {
63 "Tileset '{}' does not exist. Pass '{}' to resolve its schema anyway.",
65 FormatParam{
"--allow-missing-tileset", Style::bold}}};
66 env.diag->fatal(not_found_err);
67 throw CLI::RuntimeError{1};
76 auto resolved_result = schema_resolver.
resolve(tileset_name_);
82 if (!resolved_result.has_value()) {
85 "Failed to dump attribute schema for tileset '{}'.",
FormatParam{tileset_name_, Style::bold}},
87 env.diag->fatal(resolve_fail_result);
88 throw CLI::RuntimeError{1};
92 std::ostream &out = std::cout;
93 const std::string section_title =
"Resolved Metatile Attribute Schema";
94 out << text_formatter->style(section_title, Style::bold) <<
"\n";
95 out << text_formatter->style(std::string(section_title.size(),
'='), Style::faint) <<
"\n\n";
98 << text_formatter->format(
99 "Attribute size: {} bytes ({})",
105 << text_formatter->format(
106 "Declaration size: {} bytes (const u{}, {})",
118 out <<
" " << text_formatter->style(
"Fields:", Style::faint) <<
"\n";
119 for (
const Field &field : resolved.schema.fields()) {
120 std::string provider_desc;
121 if (field.has_provider()) {
122 provider_desc = text_formatter->format(
124 FormatParam{field.provider_definition().header.string()},
127 std::string role_desc;
128 if (field.role().has_value()) {
132 << text_formatter->format(
133 "{} mask={} offset={} width={} default={}",
138 FormatParam{std::to_string(field.default_value())})
139 << provider_desc << role_desc <<
"\n";
143 << text_formatter->format(
145 FormatParam{
"(no field carries the layer_type role: layer types are disabled)", Style::faint})
151 static constexpr auto command_name =
"dump-attribute-schema";
152 static constexpr auto command_desc =
"Dump the resolved metatile attribute schema for a tileset.";
153 static constexpr auto command_group =
"UTILITIES";
154 std::string tileset_name_;
155 bool allow_missing_tileset_{
false};
Command is an abstract class that provides basic command functionality for the Porytiles CLI driver.
CLI::App & get_app() const
DumpAttributeSchemaCommand(CLI::App &parent_app)
std::filesystem::path project_root() const
void RegisterOpt(CLI::App &app) override
A result type that maintains a chainable sequence of errors for debugging and error reporting.
One named bit-field within a metatile attribute layout.
const Field * layer_type_field() const
Returns the field carrying the layer_type role, or nullptr when the layer type is disabled.
Bootstrap class so every tileset command can share common config and diagnostic setup.
void register_config_options(CLI::App &app, CliOptionStorage &storage)
Registers all config options with a CLI11 App.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
Storage struct for CLI option values.