summaryrefslogtreecommitdiffhomepage
path: root/cli/AppMain.cxx
blob: 3eee3d4f122fdaa6d5ecdfc27350ad7b5d467b5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <Macros.hxx>
#include <JSONManifestBuilder.hxx>
#include <TOMLManifestBuilder.hxx>
#include <cstdio>
#include <cstddef>
#include <string>
#include <iostream>
#include <thread>

int	 cJobIndex = 0;
bool cFailed   = false;

static IManifestBuilder* cBuilder = nullptr;

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 <file>\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 Technologies, all rights reserved.\n";

			return 0;
		}
		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";

			return 0;
		}

		std::thread job([](std::string index_path) -> void {
			if (index_path.ends_with(".json"))
			{
			    delete cBuilder;
				cBuilder = nullptr;

				if (!cBuilder)
					cBuilder = new JSONManifestBuilder();
			}
			else if (index_path.ends_with(".toml"))
			{
			    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_path);

		job.detach();
	}

	// wait for completion of all jobs.
	while (cJobIndex)
	{
	    if (cFailed)
		{
		    std::cout << "btb: Build failed." << std::endl;
		    return EXIT_FAILURE;
		}
	}

	delete cBuilder;

	return cFailed ? EXIT_FAILURE : EXIT_SUCCESS;
}