Fix compilation of main
[command.git] / src / main.cpp
1 #include <iostream>
2 #include <string>
3 #include <functional>
4
5 #include "option.h"
6 #include "argument.h"
7 #include "required.h"
8 #include "multiValue.h"
9 #include "grouped.h"
10 #include "command.h"
11
12 using namespace command;
13
14 void argument_function(bool a) {
15     std::cout << "Argument: " << a << std::endl;
16 }
17
18 void option_function(std::string a) {
19     std::cout << "Help function " << a << std::endl;
20 }
21
22 void void_function(void) {
23     std::cout << "Void function " << std::endl;
24 }
25
26 class ExampleClass {
27 public:
28     void _argument(bool a) {
29         argument_function(a);
30     }
31     void _option(std::string a) {
32         option_function(a);
33     }
34     void _void(void) {
35         void_function();
36     }
37 };
38
39 int main(int argc, char *argv[]) {
40     ExampleClass c;
41
42     try {
43         Command command(argc, argv, {
44             new Grouped({
45                 new Required(
46                     new MultiValue("-",
47                         new Argument<bool>("Input values", std::bind(&ExampleClass::_argument, &c, std::placeholders::_1))
48                     )
49                 ),
50                 new MultiValue(",",
51                     new Option<std::string>("f", "Optional file", std::bind(&ExampleClass::_option, &c, std::placeholders::_1))
52                 )
53             }),
54             new Option<void>("h", "Help", std::bind(&ExampleClass::_void, &c)),
55
56             // just a pure method calling
57             new Option<void>("v", "version", void_function)
58         });
59
60         /* ExampleClass is initialized.
61          * You can run your main program now
62          */
63     }
64     catch(const std::exception & e) {
65         std::cout << e.what() << std::endl;
66     }
67
68     return 0;
69 }