36 cmd.add_option(
"-C,--project-root", project_root_,
"Project root directory")
38 ->capture_default_str();
40 cmd.add_option(
"--filter", filter_,
"Filter mode: all, managed, or unmanaged")
42 ->check(CLI::IsMember({
"all",
"managed",
"unmanaged"}))
43 ->capture_default_str();
45 cmd.add_option(
"--prefix", prefix_,
"Only show tilesets starting with this prefix")->default_val(
"");
53 const std::filesystem::path project_path{project_root_};
54 if (!exists(project_path) || !is_directory(project_path)) {
67 if (!result.has_value()) {
72 const auto &tileset_names = result.value();
75 for (
const auto &name : tileset_names) {
77 if (!prefix_.empty() && !name.starts_with(prefix_)) {
82 if (filter_ ==
"managed") {
83 if (!is_managed_tileset(project_path, name)) {
87 else if (filter_ ==
"unmanaged") {
88 if (is_managed_tileset(project_path, name)) {
94 std::cout << name <<
"\n";
99 static constexpr auto kCommandName =
"list-tilesets";
100 static constexpr auto kCommandDesc =
"List tilesets in the project.";
101 static constexpr auto kCommandGroup =
"UTILITIES";
103 std::string project_root_;
123 [[nodiscard]]
static bool
124 is_managed_tileset(
const std::filesystem::path &project_root,
const std::string &tileset_name)
128 if (tileset_name.empty() || tileset_name.find(
'/') != std::string::npos ||
129 tileset_name.find(
'\\') != std::string::npos || tileset_name.find(
"..") != std::string::npos) {
134 const auto manifest_path = project_root /
"porytiles" /
"tilesets" / tileset_name /
"tileset-manifest.json";
136 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.