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:
34 absl::StatusOr<std::filesystem::path> ValidatePath(const std::string& path_str) const;
35
42 std::filesystem::path GetProjectRoot() const;
43
47 bool IsPathInProject(const std::filesystem::path& path) const;
48
52 std::string FormatFileSize(uintmax_t size_bytes) const;
53
57 std::string FormatTimestamp(const std::filesystem::file_time_type& time) const;
58};
59
68 public:
69 std::string GetName() const override { return "filesystem-list"; }
70
71 std::string GetDescription() const {
72 return "List files and directories in a given path";
73 }
74
75 std::string GetUsage() const override {
76 return "filesystem-list --path <directory> [--recursive] [--format <json|text>]";
77 }
78
79 protected:
80 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
81
82 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
83 resources::OutputFormatter& formatter) override;
84
85 bool RequiresLabels() const override { return false; }
86};
87
96 public:
97 std::string GetName() const override { return "filesystem-read"; }
98
99 std::string GetDescription() const {
100 return "Read the contents of a file";
101 }
102
103 std::string GetUsage() const override {
104 return "filesystem-read --path <file> [--lines <count>] [--offset <start>] [--format <json|text>]";
105 }
106
107 protected:
108 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
109
110 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
111 resources::OutputFormatter& formatter) override;
112
113 bool RequiresLabels() const override { return false; }
114
115 private:
119 bool IsTextFile(const std::filesystem::path& path) const;
120};
121
130 public:
131 std::string GetName() const override { return "filesystem-exists"; }
132
133 std::string GetDescription() const {
134 return "Check if a file or directory exists";
135 }
136
137 std::string GetUsage() const override {
138 return "filesystem-exists --path <file|directory> [--format <json|text>]";
139 }
140
141 protected:
142 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
143
144 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
145 resources::OutputFormatter& formatter) override;
146
147 bool RequiresLabels() const override { return false; }
148};
149
159 public:
160 std::string GetName() const override { return "filesystem-info"; }
161
162 std::string GetDescription() const {
163 return "Get detailed information about a file or directory";
164 }
165
166 std::string GetUsage() const override {
167 return "filesystem-info --path <file|directory> [--format <json|text>]";
168 }
169
170 protected:
171 absl::Status ValidateArgs(const resources::ArgumentParser& parser) override;
172
173 absl::Status Execute(Rom* rom, const resources::ArgumentParser& parser,
174 resources::OutputFormatter& formatter) override;
175
176 bool RequiresLabels() const override { return false; }
177
178 private:
182 std::string GetPermissionString(const std::filesystem::path& path) const;
183};
184
185} // namespace tools
186} // namespace agent
187} // namespace cli
188} // namespace yaze
189
190#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.
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.