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"
7#include "absl/strings/str_join.h"
8#include "util/log.h"
9
10namespace yaze {
11namespace cli {
12namespace agent {
13namespace tools {
14
15namespace fs = std::filesystem;
16
18 return parser.RequireArgs({"query"});
19}
20
22 resources::OutputFormatter& formatter) {
23 if (!project_) {
24 return absl::FailedPreconditionError("Project context not available.");
25 }
26
27 std::string query_type = parser.GetString("query").value();
28
29 if (query_type == "info") {
30 return GetProjectInfo(formatter);
31 } else if (query_type == "files") {
32 std::string path = parser.GetString("path").value_or(project_->code_folder);
33 return GetFileStructure(path, formatter);
34 } else if (query_type == "symbols") {
35 if (!asar_wrapper_) {
36 return absl::FailedPreconditionError("Asar wrapper not available for symbols query.");
37 }
38 return GetSymbolTable(formatter);
39 } else {
40 return absl::InvalidArgumentError(
41 absl::StrCat("Unknown query type: ", query_type));
42 }
43}
44
46 formatter.AddField("name", project_->name);
47 formatter.AddField("description", project_->metadata.description);
48 formatter.AddField("filepath", project_->filepath);
49 formatter.AddField("rom_filename", project_->rom_filename);
50 formatter.AddField("code_folder", project_->code_folder);
51 formatter.AddField("symbols_filename", project_->symbols_filename);
52 formatter.AddField("build_script", project_->build_script);
53 formatter.AddField("git_repository", project_->git_repository);
54 formatter.AddField("last_build_hash", project_->last_build_hash);
55 return absl::OkStatus();
56}
57
58absl::Status ProjectGraphTool::GetFileStructure(const std::string& path,
59 resources::OutputFormatter& formatter) const {
60 fs::path abs_path = project_->GetAbsolutePath(path);
61 if (!fs::exists(abs_path)) {
62 return absl::NotFoundError(absl::StrCat("Path not found: ", path));
63 }
64
65 formatter.BeginArray("files");
66 for (const auto& entry : fs::directory_iterator(abs_path)) {
67 formatter.BeginObject();
68 formatter.AddField("name", entry.path().filename().string());
69 formatter.AddField("type", entry.is_directory() ? "directory" : "file");
70 formatter.AddField("path", project_->GetRelativePath(entry.path().string()));
71 formatter.EndObject();
72 }
73 formatter.EndArray();
74 return absl::OkStatus();
75}
76
78 const auto& symbols = asar_wrapper_->GetSymbolTable();
79 if (symbols.empty()) {
80 return absl::NotFound("No symbols loaded. Load symbols via the Assemble menu or ensure the build script generates them.");
81 }
82
83 formatter.BeginArray("symbols");
84 for (const auto& [name, symbol] : symbols) {
85 formatter.BeginObject();
86 formatter.AddField("name", symbol.name);
87 formatter.AddField("address", absl::StrFormat("$%06X", symbol.address));
88 formatter.EndObject();
89 }
90 formatter.EndArray();
91 return absl::OkStatus();
92}
93
94} // namespace tools
95} // namespace agent
96} // namespace cli
97} // 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:123
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:125
std::string code_folder
Definition project.h:97
std::string symbols_filename
Definition project.h:101