summaryrefslogtreecommitdiffhomepage
path: root/cli/AppMain.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'cli/AppMain.cxx')
-rw-r--r--cli/AppMain.cxx49
1 files changed, 33 insertions, 16 deletions
diff --git a/cli/AppMain.cxx b/cli/AppMain.cxx
index 66c7ade..3eee3d4 100644
--- a/cli/AppMain.cxx
+++ b/cli/AppMain.cxx
@@ -1,5 +1,6 @@
#include <Macros.hxx>
#include <JSONManifestBuilder.hxx>
+#include <TOMLManifestBuilder.hxx>
#include <cstdio>
#include <cstddef>
#include <string>
@@ -9,19 +10,18 @@
int cJobIndex = 0;
bool cFailed = false;
-static IManifestBuilder* cBuilder = new JSONManifestBuilder();
+static IManifestBuilder* cBuilder = nullptr;
int main(int argc, char** argv)
{
- LIKELY(cBuilder == nullptr);
cJobIndex = argc - 1;
for (size_t index = 1; index < argc; ++index)
{
- std::string index_json = argv[index];
+ std::string index_path = argv[index];
- if (index_json == "/Ver" ||
- index_json == "/Version")
+ if (index_path == "/Ver" ||
+ index_path == "/Version")
{
std::cout << "Usage: btb <file>\n";
std::cout << "Check for issues at: www.el-mahrouss-logic.com/btb/issues\n";
@@ -31,8 +31,8 @@ int main(int argc, char** argv)
return 0;
}
- else if (index_json == "/?" ||
- index_json == "/Help")
+ else if (index_path == "/?" ||
+ index_path == "/Help")
{
std::cout << "btb: Build a JSON file: btb <json_path>.json\n";
std::cout << "btb: Build a TOML file: btb <toml_path>.toml\n";
@@ -40,20 +40,33 @@ int main(int argc, char** argv)
return 0;
}
- std::thread job([](std::string index_json) -> void {
- std::cout << "btb: Building " << index_json << std::endl;
+ std::thread job([](std::string index_path) -> void {
+ if (index_path.ends_with(".json"))
+ {
+ delete cBuilder;
+ cBuilder = nullptr;
- if (!cBuilder->Build(index_json.size(), index_json.c_str()))
+ if (!cBuilder)
+ cBuilder = new JSONManifestBuilder();
+ }
+ else if (index_path.ends_with(".toml"))
{
- std::string format = "btb ";
- format += index_json;
+ delete cBuilder;
+ cBuilder = nullptr;
+
+ if (!cBuilder)
+ cBuilder = new TOMLManifestBuilder();
+ }
+ std::cout << "btb: Building: " << index_path << std::endl;
+
+ if (!cBuilder->Build(index_path.size(), index_path.c_str()))
+ {
cFailed = true;
}
--cJobIndex;
- },
- index_json);
+ }, index_path);
job.detach();
}
@@ -61,10 +74,14 @@ int main(int argc, char** argv)
// wait for completion of all jobs.
while (cJobIndex)
{
- BTB_UNUSED(0);
+ if (cFailed)
+ {
+ std::cout << "btb: Build failed." << std::endl;
+ return EXIT_FAILURE;
+ }
}
delete cBuilder;
- return cFailed ? 1 : 0;
+ return cFailed ? EXIT_FAILURE : EXIT_SUCCESS;
}