yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
project_graph_tool.cc
Go to the documentation of this file.
2
3#include <filesystem>
4
5#include "absl/strings/str_cat.h"
6#include "absl/strings/str_format.h"
7#include "absl/strings/str_join.h"
9#include "util/log.h"
10
11namespace yaze {
12namespace cli {
13namespace agent {
14namespace tools {
15
16namespace fs = std::filesystem;
17
19 const resources::ArgumentParser& parser) {
20 return parser.RequireArgs({"query"});
21}
22
24 const resources::ArgumentParser& parser,
25 resources::OutputFormatter& formatter) {
26 if (!project_) {
27 return absl::FailedPreconditionError("Project context not available.");
28 }
29
30 std::string query_type = parser.GetString("query").value();
31
32 if (query_type == "info") {
33 return GetProjectInfo(formatter);
34 } else if (query_type == "files") {
35 std::string path = parser.GetString("path").value_or(project_->code_folder);
36 return GetFileStructure(path, formatter);
37 } else if (query_type == "symbols") {
38 if (!asar_wrapper_) {
39 return absl::FailedPreconditionError(
40 "Asar wrapper not available for symbols query.");
41 }
42 return GetSymbolTable(formatter);
43 } else {
44 return absl::InvalidArgumentError(
45 absl::StrCat("Unknown query type: ", query_type));
46 }
47}
48
50 resources::OutputFormatter& formatter) const {
51 formatter.AddField("name", project_->name);
52 formatter.AddField("description", project_->metadata.description);
53 formatter.AddField("filepath", project_->filepath);
54 formatter.AddField("rom_filename", project_->rom_filename);
55 formatter.AddField("code_folder", project_->code_folder);
56 formatter.AddField("symbols_filename", project_->symbols_filename);
57 formatter.AddField("build_script", project_->build_script);
58 formatter.AddField("git_repository", project_->git_repository);
59 formatter.AddField("last_build_hash", project_->last_build_hash);
60 return absl::OkStatus();
61}
62
64 const std::string& path, resources::OutputFormatter& formatter) const {
65 fs::path abs_path = project_->GetAbsolutePath(path);
66 if (!fs::exists(abs_path)) {
67 return absl::NotFoundError(absl::StrCat("Path not found: ", path));
68 }
69
70 formatter.BeginArray("files");
71 for (const auto& entry : fs::directory_iterator(abs_path)) {
72 formatter.BeginObject();
73 formatter.AddField("name", entry.path().filename().string());
74 formatter.AddField("type", entry.is_directory() ? "directory" : "file");
75 formatter.AddField("path",
76 project_->GetRelativePath(entry.path().string()));
77 formatter.EndObject();
78 }
79 formatter.EndArray();
80 return absl::OkStatus();
81}
82
84 resources::OutputFormatter& formatter) const {
85 const auto& symbols = asar_wrapper_->GetSymbolTable();
86 if (symbols.empty()) {
87 return absl::NotFound(
88 "No symbols loaded. Load symbols via the Assemble menu or ensure the "
89 "build script generates them.");
90 }
91
92 formatter.BeginArray("symbols");
93 for (const auto& [name, symbol] : symbols) {
94 formatter.BeginObject();
95 formatter.AddField("name", symbol.name);
96 formatter.AddField("address", absl::StrFormat("$%06X", symbol.address));
97 formatter.EndObject();
98 }
99 formatter.EndArray();
100 return absl::OkStatus();
101}
102
103} // namespace tools
104} // namespace agent
105} // namespace cli
106} // namespace yaze
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
absl::Status GetProjectInfo(resources::OutputFormatter &formatter) const
absl::Status ValidateArgs(const resources::ArgumentParser &parser) override
Validate command arguments.
absl::Status GetSymbolTable(resources::OutputFormatter &formatter) const
absl::Status GetFileStructure(const std::string &path, resources::OutputFormatter &formatter) const
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
Utility for parsing common CLI argument patterns.
std::optional< std::string > GetString(const std::string &name) const
Parse a named argument (e.g., –format=json or –format json)
absl::Status RequireArgs(const std::vector< std::string > &required) const
Validate that required arguments are present.
Utility for consistent output formatting across commands.
void BeginArray(const std::string &key)
Begin an array.
void BeginObject(const std::string &title="")
Start a JSON object or text section.
void EndObject()
End a JSON object or text section.
void AddField(const std::string &key, const std::string &value)
Add a key-value pair.
std::map< std::string, AsarSymbol > GetSymbolTable() const
ProjectMetadata metadata
Definition project.h:86
std::string git_repository
Definition project.h:124
std::string rom_filename
Definition project.h:92
std::string GetRelativePath(const std::string &absolute_path) const
Definition project.cc:835
std::string GetAbsolutePath(const std::string &relative_path) const
Definition project.cc:853
std::string last_build_hash
Definition project.h:126
std::string code_folder
Definition project.h:97
std::string symbols_filename
Definition project.h:101