X-Git-Url: https://git.dlugolecki.net.pl/?p=command.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=ac7a62670e9c757993c4a75d16b8ac7816ada5c0;hp=5ad96a22520a2e9f5c1547e8e184d2f3f3a3e674;hb=eaf888960119de8ce2190df5ffed7325f540cb8d;hpb=ae6743a2a2c69b7a927f64ff1d3abf38a5e7d4bc diff --git a/src/main.cpp b/src/main.cpp index 5ad96a2..ac7a626 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "option.h" #include "argument.h" @@ -22,19 +23,47 @@ void void_function(void) { std::cout << "Void function " << std::endl; } +class ExampleClass { +public: + void _argument(bool a) { + argument_function(a); + } + void _option(std::string a) { + option_function(a); + } + void _void(void) { + void_function(); + } +}; + int main(int argc, char *argv[]) { + Class c; + try { Command command(argc, argv, { new Grouped({ - new Required(new MultiValue("-", new Argument("Input values", argument_function))), - new MultiValue(",", new Option("f", "Optional file", option_function)) + new Required( + new MultiValue("-", + new Argument("Input values", std::bind(&ExampleClass::_argument, &c, std::placeholders::_1)) + ) + ), + new MultiValue(",", + new Option("f", "Optional file", std::bind(&ExampleClass::_option, &c, std::placeholders::_1)) + ) }), - new Option("h", "Help", void_function) + new Option("h", "Help", std::bind(&ExampleClass::_void, &c)), + + // just a pure method calling + new Option("v", "version", void_function) }); + + /* ExampleClass is initialized. + * You can run your main program now + */ } catch(const std::exception & e) { std::cout << e.what() << std::endl; } return 0; -} \ No newline at end of file +}