X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fmain.cpp;h=33ee3fcdc93809b6af658333176ca3fa7ee81be2;hb=e8acdc5555d6e3e726ba689eb0454b870deb5871;hp=5cf4e83d018373e5e665bafaee685ee2989e7bff;hpb=0d52a8d02278592356f94ac17b1ccc5fcea388a5;p=command.git diff --git a/src/main.cpp b/src/main.cpp index 5cf4e83..33ee3fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,12 @@ #include #include +#include #include "option.h" #include "argument.h" #include "required.h" +#include "multiValue.h" +#include "grouped.h" #include "command.h" using namespace command; @@ -20,13 +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[]) { - Command command(argc, argv, { -// new Argument("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }), - new Required(new Argument("File path", argument_function)), - new Option("f", "Optional file", option_function), - new Option("h", "Help", void_function) - }); + ExampleClass c; + + try { + Command command(argc, argv, { + new Grouped({ + 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", 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 +}