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 "app/rom.h"
10
11namespace yaze {
12namespace cli {
13namespace resources {
14
44 public:
45 virtual ~CommandHandler() = default;
46
48 std::string name;
49 std::string description;
50 std::string todo_reference;
51 };
52
53 struct Descriptor {
54 std::string display_name;
55 std::string summary;
56 std::string todo_reference;
57 std::vector<DescriptorEntry> entries;
58 };
59
70 absl::Status Run(const std::vector<std::string>& args, Rom* rom_context);
71
78 virtual std::string GetName() const = 0;
79
83 virtual Descriptor Describe() const;
84
85 protected:
92 virtual absl::Status ValidateArgs(const ArgumentParser& parser) = 0;
93
100 virtual absl::Status Execute(Rom* rom, const ArgumentParser& parser,
101 OutputFormatter& formatter) = 0;
102
106 virtual std::string GetUsage() const = 0;
107
113 virtual bool RequiresLabels() const { return false; }
114
118 virtual std::string GetDefaultFormat() const { return "json"; }
119
123 virtual std::string GetOutputTitle() const { return "Result"; }
124};
125
146#define DEFINE_COMMAND_HANDLER(name, usage_str, validate_body, execute_body) \
147 class name##CommandHandler : public CommandHandler { \
148 protected: \
149 std::string GetUsage() const override { return usage_str; } \
150 absl::Status ValidateArgs(const ArgumentParser& parser) override \
151 validate_body \
152 absl::Status Execute(Rom* rom, const ArgumentParser& parser, \
153 OutputFormatter& formatter) override \
154 execute_body \
155 };
156
157} // namespace resources
158} // namespace cli
159} // namespace yaze
160
161#endif // YAZE_SRC_CLI_SERVICE_RESOURCES_COMMAND_HANDLER_H_
162
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
Utility for parsing common CLI argument patterns.
Base class for CLI command handlers.
virtual bool RequiresLabels() const
Check if the command requires ROM labels.
absl::Status Run(const std::vector< std::string > &args, Rom *rom_context)
Execute the command.
virtual std::string GetUsage() const =0
Get the command usage string.
virtual std::string GetName() const =0
Get the command name.
virtual absl::Status Execute(Rom *rom, const ArgumentParser &parser, OutputFormatter &formatter)=0
Execute the command business logic.
virtual std::string GetOutputTitle() const
Get the output title for formatting.
virtual std::string GetDefaultFormat() const
Get the default output format ("json" or "text")
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.
Main namespace for the application.