-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
39 lines (35 loc) · 1.35 KB
/
main.cc
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
#include "calendar.h"
#include <boost/program_options.hpp>
namespace opt = boost::program_options;
typedef unsigned short uns_short;
int main(int argc, char **argv) {
opt::options_description description("Options");
description.add_options()
("help,h", "Print help message")
("year,y", opt::value<uns_short>(), "Display calendar for given year")
("grid,g", "Display calendar in a 4x3 grid");
opt::variables_map variablesMap;
try {
opt::store(opt::parse_command_line(argc, argv, description), variablesMap);
opt::notify(variablesMap);
if (variablesMap.count("help")) {
std::cout << description << "\n";
return 0;
}
if (variablesMap.count("year")) {
auto year = variablesMap["year"].as<uns_short>();
if(year < 1400 || year > 10000)
throw opt::error("Year argument is out of valid range [1400, 10000].");
Calendar::Calendar calendar(year);
variablesMap.count("grid") ? calendar.displayInAGrid(std::cout) : calendar.display(std::cout);
return 1;
}
std::cout << description << "\n";
return 0;
}
catch (opt::error &error) {
std::cerr << "\nERROR: " << error.what() << "\n";
std::cerr << "\n" << description << "\n";
return -1;
}
}