summaryrefslogtreecommitdiffhomepage
path: root/cli/CommandLine.cc
blob: 6b54b25ad23ad31e194c82a742c1cb6c26055883 (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

// ============================================================= //
// btb
// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
// ============================================================= //

#include <JSONManifestBuilder.h>
#include <Includes.h>

static bool kFailed	  = false;
static bool kDryRun = false;

int main(int argc, char** argv)
{
	if (argc <= 1)
		return 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 <file>\n";
			std::cout << "Bugs, Issues?, check out: https://github.com/ne-gh/btb/issues\n";

			std::cout << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n";
			std::cout << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n";

			return EXIT_SUCCESS;
		}
		else if (index_path == "--dry-run")
		{
			kDryRun = true;
			continue;
		}
		else if (index_path == "-h" ||
				 index_path == "--help")
		{
			std::cout << "btb: Build a JSON file: btb <json_path>.json\n";
			return EXIT_SUCCESS;
		}

		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(), kDryRun))
			{
				kFailed = true;
			}
			else if (!builder)
			{
				kFailed = true;
			}

			delete builder;
			builder = nullptr;
		}, index_path);

		job_build_thread.join();
	}

	return kFailed ? EXIT_FAILURE : EXIT_SUCCESS;
}