From 31ae5119e64fade1e8415fcc51265e199a9a447f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sun, 26 Apr 2015 08:27:31 +0200 Subject: [PATCH] Fixed Option parameter. Added new example. --- include/command.h | 1 - include/option.h | 4 +++- src/main.cpp | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/command.h b/include/command.h index f53227e..9cf0a9f 100644 --- a/include/command.h +++ b/include/command.h @@ -27,7 +27,6 @@ namespace command { Command(unsigned int argc, char *argv[], std::initializer_list params) : args(params) { for(Parameter *param : params) { - std::cout << "Command foreach" << std::endl; param->handle(); } } diff --git a/include/option.h b/include/option.h index fe0fc85..fef4e31 100644 --- a/include/option.h +++ b/include/option.h @@ -15,7 +15,7 @@ namespace command { */ template class Option - : Argument { + : public Argument { public: // typedef typename Argument::FunctionType FunctionType; protected: @@ -38,6 +38,8 @@ namespace command { virtual ~Option() { } virtual void handle() { + std::cout << "Option::handle()" << std::endl; + this->call(std::string("O")); } }; } diff --git a/src/main.cpp b/src/main.cpp index 80aeb27..1cc8387 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,14 +5,15 @@ #include "argument.h" #include "command.h" +void some_function(std::string str) { + std::cout << "Some function" << std::endl; +} 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", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }), - new command::Argument("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }), - new command::Argument("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }), - 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) }); return 0; -- 2.30.2