X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fmain.cpp;h=33ee3fcdc93809b6af658333176ca3fa7ee81be2;hb=09cda1dcc2bd92ead969a828cc93a5600b5cdddc;hp=6365c7f47b952533297f89c73b7c18dd2722bfc1;hpb=a3443a3c5f76999888e7930910ce161ae3459c73;p=command.git diff --git a/src/main.cpp b/src/main.cpp index 6365c7f..33ee3fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,69 @@ #include #include +#include #include "option.h" #include "argument.h" +#include "required.h" +#include "multiValue.h" +#include "grouped.h" #include "command.h" -void some_function(std::string) { - std::cout << "Some function" << std::endl; +using namespace command; + +void argument_function(bool a) { + std::cout << "Argument: " << a << std::endl; +} + +void option_function(std::string a) { + std::cout << "Help function " << a << std::endl; +} + +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 command(argc, argv, { - new command::Argument("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }), - new command::Argument("File path", some_function), - new command::Option("h", "Help", some_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 +}