-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (42 loc) · 1.6 KB
/
main.cpp
File metadata and controls
50 lines (42 loc) · 1.6 KB
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
#include "src/bismuth.cpp"
int main(int argc, char *argv[]) {
vector<string> args(argv, argv + argc);
unordered_map<string, bool> flags = {
{ "-v", false }, { "--verbose", false },
{ "-r", false }, { "--repl", false },
{ "-q", false }, { "--quiet", false },
{ "-t", false }, { "--test", false }
};
string path = "./";
for (int i = 1; i < args.size(); i++) {
if (flags.count(args[i])) {
flags[args[i]] = true;
} else {
path = args[i];
}
}
bool repl = flags["-r"] || flags["--repl"];
bool quiet = flags["-q"] || flags["--quiet"];
Bismuth::Verbose = flags["-v"] || flags["--verbose"];
Bismuth::Testing = flags["-t"] || flags["--test"];
if (repl || ( args.size() <= 1 && !Bismuth::Exists(path) )) {
Bismuth::Repl();
} else {
if (Bismuth::Exists(path)) {
Bismuth::Runtime runtime = Bismuth::Runtime(path);
if (!quiet && !Bismuth::Verbose && !Bismuth::Testing && !runtime.result->is(Bismuth::Type::Void)) cout << runtime.result->describe() << endl;
} else if (std::filesystem::is_directory(path)) {
vector<string> paths;
for (const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator(path)) {
string child = entry.path().string();
if (Bismuth::Exists(child)) paths.push_back(child);
}
if (paths.size() > 1) cout << endl;
for (int i = 0; i < paths.size(); i++) Bismuth::Runtime runtime = Bismuth::Runtime(paths[i]);
if (paths.size() > 1) cout << endl;
} else {
cout << "Bismuth '" << path << "' not found" << endl;
}
}
return EXIT_SUCCESS;
}