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 <string>
5#include <vector>
6
7#include "absl/status/status.h"
8#include "rom/rom.h"
10#include "core/asar_wrapper.h" // For AsarWrapper
11#include "core/project.h" // For YazeProject
12
13namespace yaze {
14namespace cli {
15namespace resources {
16
46 public:
47 virtual ~CommandHandler() = default;
48
50 std::string name;
51 std::string description;
52 std::string todo_reference;
53 };
54
55 struct Descriptor {
56 std::string display_name;
57 std::string summary;
58 std::string todo_reference;
59 std::vector<DescriptorEntry> entries;
60 };
61
72 absl::Status Run(const std::vector<std::string>& args, Rom* rom_context,
73 std::string* captured_output = nullptr);
74
81 virtual std::string GetName() const = 0;
82
86 virtual Descriptor Describe() const;
87
91 virtual std::string GetUsage() const = 0;
92
98 virtual bool RequiresRom() const { return true; }
99
105 virtual bool RequiresLabels() const { return false; }
106
111 virtual void SetProjectContext(project::YazeProject* project) { project_ = project; }
112
117 virtual void SetAsarWrapper(core::AsarWrapper* asar_wrapper) { asar_wrapper_ = asar_wrapper; }
118
123 virtual void SetRomContext(Rom* rom) { rom_ = rom; }
124
125 protected:
132 virtual absl::Status ValidateArgs(const ArgumentParser& parser) = 0;
133
140 virtual absl::Status Execute(Rom* rom, const ArgumentParser& parser,
141 OutputFormatter& formatter) = 0;
142
146 virtual std::string GetDefaultFormat() const { return "json"; }
147
151 virtual std::string GetOutputTitle() const { return "Result"; }
152
153 Rom* rom_ = nullptr;
156};
157
178#define DEFINE_COMMAND_HANDLER(name, usage_str, validate_body, execute_body) \
179 class name##CommandHandler : public CommandHandler { \
180 public: \
181 std::string GetName() const override { return #name; } \
182 std::string GetUsage() const override { return usage_str; } \
183 protected: \
184 absl::Status ValidateArgs(const ArgumentParser& parser) override \
185 validate_body \
186 absl::Status Execute(Rom* rom, const ArgumentParser& parser, \
187 OutputFormatter& formatter) override \
188 execute_body \
189 };
190
191} // namespace resources
192} // namespace cli
193} // namespace yaze
194
195#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:24
Utility for parsing common CLI argument patterns.
Base class for CLI command handlers.
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.
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.
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 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.
Modern project structure with comprehensive settings consolidation.
Definition project.h:84