Files
IAEngine/CLI/Src/Imp/CPP/CLI.cpp
Isuru Samarathunga bf755a6d02 Android Project
2025-10-12 23:04:48 +05:30

164 lines
5.8 KiB
C++

// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <CLI.hpp>
#include <IACore/File.hpp>
#include <filesystem>
namespace ia::iae
{
#define REPORT_STATUS(...) printf(__CC_MAGENTA "%s" __CC_DEFAULT "\n", BuildString(__VA_ARGS__).c_str())
#define REPORT_ERROR(...) printf(__CC_RED "%s" __CC_DEFAULT "\n", BuildString(__VA_ARGS__).c_str())
#define REPORT_SUCCESS(...) printf(__CC_GREEN "%s" __CC_DEFAULT "\n", BuildString(__VA_ARGS__).c_str())
CLI::CLI() : ia::CLI("IAEngine CLI", IA_MAKE_VERSION(1, 0, 0), "Copyright (C) 2025 IASoft (PVT) LTD")
{
RegisterCommand({
.ID = "new",
.Shorthand = 'n',
.Help = "Creates a new game project",
.Parameters =
{
{
.ID = "name",
.Help = "Name of the project to be created",
.IsOptional = false,
.Type = ParameterValueType::STRING,
},
},
.Action = [&](IN Map<String, ParameterValue>&& params, IN Map<String, BOOL>&& switches)
{
try {
CreateNewProject(params["name"].StringValue);
} catch(CONST std::exception& e) {
IAE_LOG_ERROR("EXCEPTION: ", e.what());
return -4;
}
return 0;
},
});
RegisterCommand({
.ID = "run",
.Shorthand = 'r',
.Help = "Runs the game project",
.Action = [&](IN Map<String, ParameterValue>&& params, IN Map<String, BOOL>&& switches)
{
try {
} catch(CONST std::exception& e) {
IAE_LOG_ERROR("EXCEPTION: ", e.what());
return -4;
}
return 0;
},
});
RegisterCommand({
.ID = "debug",
.Shorthand = 'd',
.Help = "Debugs the game project",
.Action = [&](IN Map<String, ParameterValue>&& params, IN Map<String, BOOL>&& switches)
{
try {
} catch(CONST std::exception& e) {
IAE_LOG_ERROR("EXCEPTION: ", e.what());
return -4;
}
return 0;
},
});
RegisterCommand({
.ID = "clean",
.Shorthand = 'c',
.Help = "Cleans the game project",
.Action = [&](IN Map<String, ParameterValue>&& params, IN Map<String, BOOL>&& switches)
{
try {
} catch(CONST std::exception& e) {
IAE_LOG_ERROR("EXCEPTION: ", e.what());
return -4;
}
return 0;
},
});
RegisterCommand({
.ID = "build",
.Shorthand = 'b',
.Help = "Builds the game project",
.Action = [&](IN Map<String, ParameterValue>&& params, IN Map<String, BOOL>&& switches)
{
try {
} catch(CONST std::exception& e) {
IAE_LOG_ERROR("EXCEPTION: ", e.what());
return -4;
}
return 0;
},
});
RegisterCommand({
.ID = "rebuild",
.Shorthand = 'e',
.Help = "Rebuilds the game project",
.Action = [&](IN Map<String, ParameterValue>&& params, IN Map<String, BOOL>&& switches)
{
try {
} catch(CONST std::exception& e) {
IAE_LOG_ERROR("EXCEPTION: ", e.what());
return -4;
}
return 0;
},
});
RegisterCommand({
.ID = "package",
.Shorthand = 'p',
.Help = "Packages the game project",
.Parameters =
{
{
.ID = "target",
.Help = "Target platform. Possible values WIN64, ANDROID.",
.IsOptional = false,
.Type = ParameterValueType::STRING,
},
},
.Action = [&](IN Map<String, ParameterValue>&& params, IN Map<String, BOOL>&& switches)
{
try {
} catch(CONST std::exception& e) {
IAE_LOG_ERROR("EXCEPTION: ", e.what());
return -4;
}
return 0;
},
});
}
VOID CLI::CreateNewProject(IN CONST String& name)
{
if(std::filesystem::exists(name.c_str()))
{
REPORT_ERROR("Directory \"", name, "\" already exists. Aborting..");
return;
}
REPORT_STATUS("Creating Project ", name, "..");
std::filesystem::create_directories(name.c_str());
}
} // namespace ia::iae