34 cmd.add_option(
"-C,--project-root", project_root_,
"Project root directory")
36 ->capture_default_str();
38 cmd.add_option(
"--filter", filter_,
"Filter mode: all, managed, or unmanaged")
40 ->check(CLI::IsMember({
"all",
"managed",
"unmanaged"}))
41 ->capture_default_str();
43 cmd.add_option(
"--prefix", prefix_,
"Only show tilesets starting with this prefix")->default_val(
"");
52 const std::filesystem::path project_path{project_root_};
53 if (!exists(project_path) || !is_directory(project_path)) {
66 if (!result.has_value()) {
71 const auto &tileset_names = result.value();
74 for (
const auto &
name : tileset_names) {
76 if (!prefix_.empty() && !
name.starts_with(prefix_)) {
81 if (filter_ ==
"managed") {
82 if (!is_managed_tileset(project_path,
name)) {
86 else if (filter_ ==
"unmanaged") {
87 if (is_managed_tileset(project_path,
name)) {
93 std::cout <<
name <<
"\n";
97 static constexpr auto command_name =
"list-tilesets";
98 static constexpr auto command_desc =
"List tilesets in the project.";
99 static constexpr auto command_group =
"UTILITIES";
101 std::string project_root_;
119 [[nodiscard]]
static bool
120 is_managed_tileset(
const std::filesystem::path &project_root,
const std::string &tileset_name)
124 if (tileset_name.empty() || tileset_name.find(
'/') != std::string::npos ||
125 tileset_name.find(
'\\') != std::string::npos || tileset_name.find(
"..") != std::string::npos) {
130 const auto manifest_path = project_root /
"porytiles" /
"tilesets" / tileset_name /
"tileset-manifest.json";
132 return exists(manifest_path);
Command is an abstract class that provides basic command functionality for the Porytiles CLI driver.
CLI::App & get_app() const
Lists tileset names in the project.
ListTilesetsCommand(CLI::App &parent_app)
Silent diagnostics implementation that suppresses all output.
TextFormatter implementation that strips all styling from text.