yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
command_handler.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_SERVICE_RESOURCES_COMMAND_HANDLER_H_
2#define YAZE_SRC_CLI_SERVICE_RESOURCES_COMMAND_HANDLER_H_
3
4#include <filesystem>
5#include <map>
6#include <optional>
7#include <string>
8#include <vector>
9
10#include "absl/status/status.h"
12#include "core/asar_wrapper.h" // For AsarWrapper
13#include "core/project.h" // For YazeProject
14#include "rom/rom.h"
15
16namespace yaze {
17namespace cli {
18namespace resources {
19
20// Immutable ROM path identity captured for one CommandHandler::Run invocation.
21// The source path remains the caller's ROM when sandbox mode swaps the active
22// path to a command-local copy.
24 std::optional<std::filesystem::path> source_rom_path;
25 std::optional<std::filesystem::path> active_rom_path;
26 bool sandbox_enabled = false;
27};
28
58 public:
59 virtual ~CommandHandler() = default;
60
62 std::string name;
63 std::string description;
64 std::string todo_reference;
65 };
66
67 struct Descriptor {
68 std::string display_name;
69 std::string summary;
70 std::string todo_reference;
71 std::vector<DescriptorEntry> entries;
72 };
73
84 absl::Status Run(const std::vector<std::string>& args, Rom* rom_context,
85 std::string* captured_output = nullptr);
86
93 virtual std::string GetName() const = 0;
94
98 virtual Descriptor Describe() const;
99
103 virtual std::string GetUsage() const = 0;
104
110 virtual bool RequiresRom() const { return true; }
111
117 virtual bool RequiresLabels() const { return false; }
118
124 project_ = project;
125 }
126
131 virtual void SetAsarWrapper(core::AsarWrapper* asar_wrapper) {
132 asar_wrapper_ = asar_wrapper;
133 }
134
139 virtual void SetRomContext(Rom* rom) { rom_ = rom; }
140
145 const std::map<std::string, core::AsarSymbol>* table) {
147 }
148
153 symbol_provider_ = provider;
154 }
155
156 protected:
160 virtual absl::Status ValidateArgs(const ArgumentParser& parser) = 0;
161
168 virtual absl::Status Execute(Rom* rom, const ArgumentParser& parser,
169 OutputFormatter& formatter) = 0;
170
178 virtual absl::Status ExecuteWithContext(
179 Rom* rom, const ArgumentParser& parser, OutputFormatter& formatter,
180 const CommandInvocationContext& invocation_context) {
181 return Execute(rom, parser, formatter);
182 }
183
187 virtual std::string GetDefaultFormat() const { return "json"; }
188
192 virtual std::string GetOutputTitle() const { return "Result"; }
193
194 Rom* rom_ = nullptr;
198 const std::map<std::string, core::AsarSymbol>* assembly_symbol_table_ =
199 nullptr;
200};
201
222#define DEFINE_COMMAND_HANDLER(name, usage_str, validate_body, execute_body) \
223 class name##CommandHandler : public CommandHandler { \
224 public: \
225 std::string GetName() const override { return #name; } \
226 std::string GetUsage() const override { return usage_str; } \
227 \
228 protected: \
229 absl::Status ValidateArgs(const ArgumentParser& parser) override \
230 validate_body absl::Status \
231 Execute(Rom* rom, const ArgumentParser& parser, \
232 OutputFormatter& formatter) override execute_body \
233 };
234
235} // namespace resources
236} // namespace cli
237} // namespace yaze
238
239#endif // YAZE_SRC_CLI_SERVICE_RESOURCES_COMMAND_HANDLER_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Utility for parsing common CLI argument patterns.
Base class for CLI command handlers.
const std::map< std::string, core::AsarSymbol > * assembly_symbol_table_
virtual bool RequiresLabels() const
Check if the command requires ROM labels.
virtual std::string GetUsage() const =0
Get the command usage string.
virtual std::string GetName() const =0
Get the command name.
virtual void SetRomContext(Rom *rom)
Set the ROM context for tools that need ROM access. Default implementation stores the ROM pointer for...
virtual absl::Status Execute(Rom *rom, const ArgumentParser &parser, OutputFormatter &formatter)=0
Execute the command business logic.
virtual void SetSymbolProvider(emu::debug::SymbolProvider *provider)
Set the SymbolProvider context.
absl::Status Run(const std::vector< std::string > &args, Rom *rom_context, std::string *captured_output=nullptr)
Execute the command.
virtual std::string GetOutputTitle() const
Get the output title for formatting.
virtual void SetAsarWrapper(core::AsarWrapper *asar_wrapper)
Set the AsarWrapper context. Default implementation does nothing, override if tool needs Asar access.
emu::debug::SymbolProvider * symbol_provider_
virtual std::string GetDefaultFormat() const
Get the default output format ("json" or "text")
virtual bool RequiresRom() const
Check if the command requires a loaded ROM.
virtual void SetProjectContext(project::YazeProject *project)
Set the YazeProject context. Default implementation does nothing, override if tool needs project info...
virtual void SetAssemblySymbolTable(const std::map< std::string, core::AsarSymbol > *table)
Optional Asar symbol table for assembly-aware tools.
virtual Descriptor Describe() const
Provide metadata for TUI/help summaries.
virtual absl::Status ExecuteWithContext(Rom *rom, const ArgumentParser &parser, OutputFormatter &formatter, const CommandInvocationContext &invocation_context)
Execute with immutable, invocation-scoped ROM path identity.
virtual absl::Status ValidateArgs(const ArgumentParser &parser)=0
Validate command arguments.
Utility for consistent output formatting across commands.
Modern C++ wrapper for Asar 65816 assembler integration.
Provider for symbol (label) resolution in disassembly.
std::optional< std::filesystem::path > active_rom_path
std::optional< std::filesystem::path > source_rom_path
Modern project structure with comprehensive settings consolidation.
Definition project.h:172