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 <map>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
10#include "core/asar_wrapper.h" // For AsarWrapper
11#include "core/project.h" // For YazeProject
12#include "rom/rom.h"
13
14namespace yaze {
15namespace cli {
16namespace resources {
17
47 public:
48 virtual ~CommandHandler() = default;
49
51 std::string name;
52 std::string description;
53 std::string todo_reference;
54 };
55
56 struct Descriptor {
57 std::string display_name;
58 std::string summary;
59 std::string todo_reference;
60 std::vector<DescriptorEntry> entries;
61 };
62
73 absl::Status Run(const std::vector<std::string>& args, Rom* rom_context,
74 std::string* captured_output = nullptr);
75
82 virtual std::string GetName() const = 0;
83
87 virtual Descriptor Describe() const;
88
92 virtual std::string GetUsage() const = 0;
93
99 virtual bool RequiresRom() const { return true; }
100
106 virtual bool RequiresLabels() const { return false; }
107
113 project_ = project;
114 }
115
120 virtual void SetAsarWrapper(core::AsarWrapper* asar_wrapper) {
121 asar_wrapper_ = asar_wrapper;
122 }
123
128 virtual void SetRomContext(Rom* rom) { rom_ = rom; }
129
134 const std::map<std::string, core::AsarSymbol>* table) {
136 }
137
142 symbol_provider_ = provider;
143 }
144
145 protected:
149 virtual absl::Status ValidateArgs(const ArgumentParser& parser) = 0;
150
157 virtual absl::Status Execute(Rom* rom, const ArgumentParser& parser,
158 OutputFormatter& formatter) = 0;
159
163 virtual std::string GetDefaultFormat() const { return "json"; }
164
168 virtual std::string GetOutputTitle() const { return "Result"; }
169
170 Rom* rom_ = nullptr;
174 const std::map<std::string, core::AsarSymbol>* assembly_symbol_table_ =
175 nullptr;
176};
177
198#define DEFINE_COMMAND_HANDLER(name, usage_str, validate_body, execute_body) \
199 class name##CommandHandler : public CommandHandler { \
200 public: \
201 std::string GetName() const override { return #name; } \
202 std::string GetUsage() const override { return usage_str; } \
203 \
204 protected: \
205 absl::Status ValidateArgs(const ArgumentParser& parser) override \
206 validate_body absl::Status \
207 Execute(Rom* rom, const ArgumentParser& parser, \
208 OutputFormatter& formatter) override execute_body \
209 };
210
211} // namespace resources
212} // namespace cli
213} // namespace yaze
214
215#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 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.
Modern project structure with comprehensive settings consolidation.
Definition project.h:164