summaryrefslogtreecommitdiff
path: root/src/main.cc
blob: 08cb89fa651745702c0d658db004a68416c1c5b2 (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
#include "cli.h"
#include "logger.h"
#include <getopt.h>
#include <iostream>

void err()
{
	std::cerr << "Usage:\n\trisc_vector [OPTIONS]\nOptions:\n\t--debug,\t-d: "
				 "turn on verbose output\n\t--no-python,\t-p: run without GUI\n"
			  << std::endl;
}

void parseArguments(int argc, char **argv, Logger &logger, bool &python)
{
	struct option long_options[] = {
		{"debug", no_argument, 0, 'd'},
		{"no-python", no_argument, 0, 'p'},
		{0, 0, 0, 0}};

	python = true;

	int opt;

	while ((opt = getopt_long(argc, argv, "d:p", long_options, NULL)) != -1) {
		switch (opt) {
		case 'd':
			logger.setLevel(DEBUG);
			logger.log(DEBUG, "DEBUG output enabled.");
			break;
		case 'p':
			logger.log(INFO, "Python will NOT be started!");
			python = false;
			break;
		default:
			err();
			exit(EXIT_FAILURE);
		}
	}
}

int main(int argc, char **argv)
{
	Logger logger("vector.log");
	Cli cli;
	logger.log(INFO, "Initializing...");

	bool python = true;
	parseArguments(argc, argv, logger, python);

	if (python) {
		// fork off python here
		;
		logger.log(INFO, "Python started.");
	}

	cli.run();
	return EXIT_SUCCESS;
}