From d7dcb2695ca2c69b45314cfc261c395e935d355b Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 25 Oct 2024 18:44:01 +0200 Subject: IMP: Add a new contract method for those who implements IManifestBuilder. Signed-off-by: Amlal --- cli/CliApp.cc | 91 -------------------------------------------------- cli/ManifestBuilder.cc | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 91 deletions(-) delete mode 100644 cli/CliApp.cc create mode 100644 cli/ManifestBuilder.cc (limited to 'cli') diff --git a/cli/CliApp.cc b/cli/CliApp.cc deleted file mode 100644 index f8fd999..0000000 --- a/cli/CliApp.cc +++ /dev/null @@ -1,91 +0,0 @@ -// ============================================================= // -// btb -// Copyright ZKA Web Services. -// ============================================================= // - -#include -#include -#include -#include -#include -#include -#include - -static int cJobIndex = 0; -static bool cFailed = false; - -int main(int argc, char** argv) -{ - cJobIndex = argc - 1; - - for (size_t index = 1; index < argc; ++index) - { - std::string index_path = argv[index]; - - if (index_path == "/Ver" || - index_path == "/Version") - { - std::cout << "Usage: btb \n"; - std::cout << "Check for issues at: www.el-mahrouss-logic.com/btb/issues\n"; - - std::cout << "Brought to you by Amlal El Mahrouss.\n"; - std::cout << "© ZKA Web Services, all rights reserved.\n"; - - return 0; - } - else if (index_path == "/?" || - index_path == "/Help") - { - std::cout << "btb: Build a JSON file: btb .json\n"; - std::cout << "btb: Build a TOML file: btb .toml\n"; - - return 0; - } - - std::thread job_build_thread([](std::string index_path) -> void { - IManifestBuilder* builder = nullptr; - - const auto cJsonExt = ".json"; - - if (index_path.ends_with(cJsonExt)) - { - builder = new JSONManifestBuilder(); - } - else - { - cFailed = true; - return; - } - - std::cout << "btb: building: " << index_path << std::endl; - - if (builder && !builder->Build(index_path.size(), index_path.c_str())) - { - cFailed = true; - } - else if (!builder) - { - cFailed = true; - } - - delete builder; - - --cJobIndex; - }, - index_path); - - job_build_thread.detach(); - } - - // wait for completion of all jobs. - while (cJobIndex) - { - if (cFailed) - { - std::cout << "btb: build failed: " << errno << "." << std::endl; - return EXIT_FAILURE; - } - } - - return cFailed ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/cli/ManifestBuilder.cc b/cli/ManifestBuilder.cc new file mode 100644 index 0000000..2c9c4ad --- /dev/null +++ b/cli/ManifestBuilder.cc @@ -0,0 +1,87 @@ +// ============================================================= // +// btb +// Copyright ZKA Web Services. +// ============================================================= // + +#include +#include + +static int kJobCount = 0; +static bool kFailed = false; + +int main(int argc, char** argv) +{ + if (argc <= 1) + return -1; + + kJobCount = argc - 1; + + for (size_t index = 1; index < argc; ++index) + { + std::string index_path = argv[index]; + + if (index_path == "-v" || + index_path == "--version") + { + std::cout << "Usage: btb \n"; + std::cout << "Check for issues at: www.el-mahrouss-logic.com/btb/issues\n"; + + std::cout << "Brought to you by Amlal El Mahrouss.\n"; + std::cout << "© ZKA Web Services Co, all rights reserved.\n"; + + return 0; + } + else if (index_path == "-h" || + index_path == "--help") + { + std::cout << "btb: Build a JSON file: btb .json\n"; + + return 0; + } + + std::thread job_build_thread([](std::string index_path) -> void { + IManifestBuilder* builder = nullptr; + + const auto kJsonExtension = ".json"; + + if (index_path.ends_with(kJsonExtension)) + { + builder = new JSONManifestBuilder(); + } + else + { + kFailed = true; + return; + } + + std::cout << "btb: building: " << index_path << std::endl; + + if (builder && !builder->buildTarget(index_path.size(), index_path.c_str())) + { + kFailed = true; + } + else if (!builder) + { + kFailed = true; + } + + delete builder; + + --kJobCount; + }, index_path); + + job_build_thread.detach(); + } + + // wait for completion of all jobs. + while (kJobCount) + { + if (kFailed) + { + std::cout << "btb: build failed: " << errno << "." << std::endl; + return EXIT_FAILURE; + } + } + + return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; +} -- cgit v1.2.3