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 (void)rom;
27 if (!project_) {
28 return absl::FailedPreconditionError("Project context not available.");
29 }
30
31 std::string query_type = parser.GetString("query").value();
32
33 if (query_type == "info") {
34 return GetProjectInfo(formatter);
35 } else if (query_type == "files") {
36 std::string path = parser.GetString("path").value_or(project_->code_folder);
37 return GetFileStructure(path, formatter);
38 } else if (query_type == "symbols") {
39 if (!asar_wrapper_) {
40 return absl::FailedPreconditionError(
41 "Asar wrapper not available for symbols query.");
42 }
43 return GetSymbolTable(formatter);
44 } else {
45 return absl::InvalidArgumentError(
46 absl::StrCat("Unknown query type: ", query_type));
47 }
48}
49
51 resources::OutputFormatter& formatter) const {
52 formatter.AddField("name", project_->name);
53 formatter.AddField("description", project_->metadata.description);
54 formatter.AddField("filepath", project_->filepath);
55 formatter.AddField("rom_filename", project_->rom_filename);
56 formatter.AddField("code_folder", project_->code_folder);
57 formatter.AddField("symbols_filename", project_->symbols_filename);
58 formatter.AddField("build_script", project_->build_script);
59 formatter.AddField("git_repository", project_->git_repository);
60 formatter.AddField("last_build_hash", project_->last_build_hash);
61 return absl::OkStatus();
62}
63
65 const std::string& path, resources::OutputFormatter& formatter) const {
66 fs::path abs_path = project_->GetAbsolutePath(path);
67 if (!fs::exists(abs_path)) {
68 return absl::NotFoundError(absl::StrCat("Path not found: ", path));
69 }
70
71 formatter.BeginArray("files");
72 for (const auto& entry : fs::directory_iterator(abs_path)) {
73 formatter.BeginObject();
74 formatter.AddField("name", entry.path().filename().string());
75 formatter.AddField("type", entry.is_directory() ? "directory" : "file");
76 formatter.AddField("path",
77 project_->GetRelativePath(entry.path().string()));
78 formatter.EndObject();
79 }
80 formatter.EndArray();
81 return absl::OkStatus();
82}
83
85 resources::OutputFormatter& formatter) const {
86 const auto& symbols = asar_wrapper_->GetSymbolTable();
87 if (symbols.empty()) {
88 return absl::NotFoundError(
89 "No symbols loaded. Load symbols via the Assemble menu or ensure the "
90 "build script generates them.");
91 }
92
93 formatter.BeginArray("symbols");
94 for (const auto& [name, symbol] : symbols) {
95 formatter.BeginObject();
96 formatter.AddField("name", symbol.name);
97 formatter.AddField("address", absl::StrFormat("$%06X", symbol.address));
98 formatter.EndObject();
99 }
100 formatter.EndArray();
101 return absl::OkStatus();
102}
103
104} // namespace tools
105} // namespace agent
106} // namespace cli
107} // 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:28
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:122
std::string git_repository
Definition project.h:171
std::string GetRelativePath(const std::string &absolute_path) const
Definition project.cc:1267
std::string GetAbsolutePath(const std::string &relative_path) const
Definition project.cc:1287
std::string last_build_hash
Definition project.h:173
std::string symbols_filename
Definition project.h:138