Add try-catch block in example in order to fix memory leaks. Added specialized except...
[command.git] / src / main.cpp
1 #include <iostream>
2 #include <string>
3
4 #include "option.h"
5 #include "argument.h"
6 #include "required.h"
7 #include "command.h"
8
9 using namespace command;
10
11 void argument_function(bool a) {
12     std::cout << "Argument: " << a << std::endl;
13 }
14
15 void option_function(std::string a) {
16     std::cout << "Help function " << a << std::endl;
17 }
18
19 void void_function(void) {
20     std::cout << "Void function " << std::endl;
21 }
22
23 int main(int argc, char *argv[]) {
24     try {
25         Command command(argc, argv, {
26 //             new Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
27             new Required(new Argument<bool>("File path", argument_function)),
28             new Option<std::string>("f", "Optional file", option_function),
29             new Option<void>("h", "Help", void_function)
30         });
31
32     }
33     catch(const std::exception & e) {
34         std::cout << e.what() << std::endl;
35     }
36
37     return 0;
38 }