fakir/src/main.cpp

80 lines
1.5 KiB
C++
Raw Normal View History

#include <iostream>
#include <getopt.h>
#include "commons.hpp"
#include "Module.hpp"
int main(int argc, char** argv)
{
2023-09-20 19:21:51 +00:00
bool debug_mode = false;
while (true)
{
static struct option options[] = {
{"help", no_argument, 0, 'h'},
2023-09-20 19:21:51 +00:00
{"debug", no_argument, 0, 'd'},
{0, 0, 0, 0}
};
int opt_index = 0;
int c = getopt_long(argc, argv, "h", options, &opt_index);
if (c == -1)
{
break;
}
switch (c)
{
case 'h': {
std::stringstream ss;
ss << std::setw(8) << std::left;
ss << "Usage: fakir <options> <sources>" << std::endl
<< std::endl;
ss << "[OPTIONS]" << std::endl;
ss << "-h, --help" << "\t" << "show this message." << std::endl;
std::cout << ss.str() << std::endl;
return 0;
} break;
2023-09-20 19:21:51 +00:00
case 'd': {
debug_mode = true;
} break;
default: break;
}
}
std::vector<std::filesystem::path> sources;
while (optind < argc)
{
sources.push_back(argv[optind]);
optind++;
}
if (sources.size())
{
fk::Module mod {sources[0]};
2023-09-20 19:21:51 +00:00
if (debug_mode)
{
mod.build();
}
else
{
try
{
mod.build();
}
catch(std::exception const& err)
{
std::cerr << err.what() << std::endl;
return -1;
}
}
}
return 0;
}