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
88 virtual std::string GetUsage() const = 0;
89
90 protected:
97 virtual absl::Status ValidateArgs(const ArgumentParser& parser) = 0;
98
105 virtual absl::Status Execute(Rom* rom, const ArgumentParser& parser,
106 OutputFormatter& formatter) = 0;
107
108
114 virtual bool RequiresLabels() const { return false; }
115
119 virtual std::string GetDefaultFormat() const { return "json"; }
120
124 virtual std::string GetOutputTitle() const { return "Result"; }
125};
126
147#define DEFINE_COMMAND_HANDLER(name, usage_str, validate_body, execute_body) \
148 class name##CommandHandler : public CommandHandler { \
149 protected: \
150 std::string GetUsage() const override { return usage_str; } \
151 absl::Status ValidateArgs(const ArgumentParser& parser) override \
152 validate_body \
153 absl::Status Execute(Rom* rom, const ArgumentParser& parser, \
154 OutputFormatter& formatter) override \
155 execute_body \
156 };
157
158} // namespace resources
159} // namespace cli
160} // namespace yaze
161
162#endif // YAZE_SRC_CLI_SERVICE_RESOURCES_COMMAND_HANDLER_H_
163
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:74
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.
Definition controller.cc:20