yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
filesystem_tool.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_SERVICE_AGENT_TOOLS_FILESYSTEM_TOOL_H_
2#define YAZE_SRC_CLI_SERVICE_AGENT_TOOLS_FILESYSTEM_TOOL_H_
3
4#include <filesystem>
5#include <string>
6
7#include "absl/status/status.h"
8#include "absl/status/statusor.h"
10
11namespace yaze {
12namespace cli {
13namespace agent {
14namespace tools {
15
25 protected:
26 bool RequiresRom() const override { return false; }
27
36 absl::StatusOr<std::filesystem::path> ValidatePath(const std::string& path_str) const;
37
44 std::filesystem::path GetProjectRoot() const;
45
49 bool IsPathInProject(const std::filesystem::path& path) const;
50
54 std::string FormatFileSize(uintmax_t size_bytes) const;
55
59 std::string FormatTimestamp(const std::filesystem::file_time_type& time) const;
60};
61
70 public:
71 std::string GetName() const override { return "filesystem-list"; }
72
73 std::string GetDescription() const {
74 return "List files and directories in a given path";
75 }
76
77 std::string GetUsage() const override {
78 return "filesystem-list --path <directory> [--recursive] [--format <json|text>]";
79 }
80
81 protected:
82 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
83
84 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
85 resources::OutputFormatter& formatter) override;
86
87 bool RequiresLabels() const override { return false; }
88};
89
98 public:
99 std::string GetName() const override { return "filesystem-read"; }
100
101 std::string GetDescription() const {
102 return "Read the contents of a file";
103 }
104
105 std::string GetUsage() const override {
106 return "filesystem-read --path <file> [--lines <count>] [--offset <start>] [--format <json|text>]";
107 }
108
109 protected:
110 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
111
112 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
113 resources::OutputFormatter& formatter) override;
114
115 bool RequiresLabels() const override { return false; }
116
117 private:
121 bool IsTextFile(const std::filesystem::path& path) const;
122};
123
132 public:
133 std::string GetName() const override { return "filesystem-exists"; }
134
135 std::string GetDescription() const {
136 return "Check if a file or directory exists";
137 }
138
139 std::string GetUsage() const override {
140 return "filesystem-exists --path <file|directory> [--format <json|text>]";
141 }
142
143 protected:
144 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
145
146 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
147 resources::OutputFormatter& formatter) override;
148
149 bool RequiresLabels() const override { return false; }
150};
151
161 public:
162 std::string GetName() const override { return "filesystem-info"; }
163
164 std::string GetDescription() const {
165 return "Get detailed information about a file or directory";
166 }
167
168 std::string GetUsage() const override {
169 return "filesystem-info --path <file|directory> [--format <json|text>]";
170 }
171
172 protected:
173 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
174
175 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
176 resources::OutputFormatter& formatter) override;
177
178 bool RequiresLabels() const override { return false; }
179
180 private:
184 std::string GetPermissionString(const std::filesystem::path& path) const;
185};
186
187} // namespace tools
188} // namespace agent
189} // namespace cli
190} // namespace yaze
191
192#endif // YAZE_SRC_CLI_SERVICE_AGENT_TOOLS_FILESYSTEM_TOOL_H_
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
Check if a file or directory exists.
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
std::string GetName() const override
Get the command name.
absl::Status ValidateArgs(const resources::ArgumentParser &parser) override
Validate command arguments.
bool RequiresLabels() const override
Check if the command requires ROM labels.
std::string GetUsage() const override
Get the command usage string.
Get detailed information about a file or directory.
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
bool RequiresLabels() const override
Check if the command requires ROM labels.
std::string GetUsage() const override
Get the command usage string.
absl::Status ValidateArgs(const resources::ArgumentParser &parser) override
Validate command arguments.
std::string GetName() const override
Get the command name.
std::string GetPermissionString(const std::filesystem::path &path) const
Get permission string (Unix-style: rwxrwxrwx)
List files and directories in a given path.
std::string GetName() const override
Get the command name.
std::string GetUsage() const override
Get the command usage string.
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
bool RequiresLabels() const override
Check if the command requires ROM labels.
absl::Status ValidateArgs(const resources::ArgumentParser &parser) override
Validate command arguments.
std::string GetUsage() const override
Get the command usage string.
std::string GetName() const override
Get the command name.
absl::Status ValidateArgs(const resources::ArgumentParser &parser) override
Validate command arguments.
bool RequiresLabels() const override
Check if the command requires ROM labels.
bool IsTextFile(const std::filesystem::path &path) const
Check if a file is likely text (not binary)
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
Base class for filesystem operations.
std::string FormatTimestamp(const std::filesystem::file_time_type &time) const
Format timestamp for readable output.
std::filesystem::path GetProjectRoot() const
Get the project root directory.
bool RequiresRom() const override
Check if the command requires a loaded ROM.
std::string FormatFileSize(uintmax_t size_bytes) const
Format file size for human-readable output.
absl::StatusOr< std::filesystem::path > ValidatePath(const std::string &path_str) const
Validate and normalize a path for safe access.
bool IsPathInProject(const std::filesystem::path &path) const
Check if a path is within the project directory.
Utility for parsing common CLI argument patterns.
Base class for CLI command handlers.
Utility for consistent output formatting across commands.