From bba2a7fd86db452c2d9a1668ee649f6d4d51a581 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Fri, 19 Feb 2016 00:20:36 +0100 Subject: [PATCH] Extended example in README --- README | 31 ++++++++++++++++++++++++++++++- README.md | 31 ++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/README b/README index f6559de..b5cb7d5 100644 --- a/README +++ b/README @@ -30,21 +30,42 @@ As this is header-only library, you don't need any additional steps. example.cpp: #include + #include #include #include + #include using namespace command; + class MyClass { + std::string _value = "Default"; + public: + void setValue(std::string value) { + this->_value = value; + } + std::string getValue() { + return std::string("Value from MyClass: ") + this->_value; + } + }; + int main(int argc, char *argv[]) { + MyClass myClass; try { Command command(argc, argv, { - new Option("-h", "Help", [](void) { std::cout << "Help information\n"; }) + new Option("-h", "Help", [](void) { + std::cout << "Help information\n"; + }), + new Argument("Value for MyClass", + std::bind(&MyClass::setValue, &myClass, std::placeholders::_1) + ) }); } catch(const std::exception & e) { return 1; } + std::cout << myClass.getValue() << std::endl; + return 0; } @@ -53,6 +74,14 @@ Now program can be compiled & run using following commands: $ g++ -std=c++11 example.cpp $ ./a.out -h Help information + Value from MyClass: Default + + $ ./a.out someArg + Value from MyClass: someArg + + $ ./a.out someArg -h + Help information + Value from MyClass: someArg ### Possible classes to use: diff --git a/README.md b/README.md index f6559de..b5cb7d5 100644 --- a/README.md +++ b/README.md @@ -30,21 +30,42 @@ As this is header-only library, you don't need any additional steps. example.cpp: #include + #include #include #include + #include using namespace command; + class MyClass { + std::string _value = "Default"; + public: + void setValue(std::string value) { + this->_value = value; + } + std::string getValue() { + return std::string("Value from MyClass: ") + this->_value; + } + }; + int main(int argc, char *argv[]) { + MyClass myClass; try { Command command(argc, argv, { - new Option("-h", "Help", [](void) { std::cout << "Help information\n"; }) + new Option("-h", "Help", [](void) { + std::cout << "Help information\n"; + }), + new Argument("Value for MyClass", + std::bind(&MyClass::setValue, &myClass, std::placeholders::_1) + ) }); } catch(const std::exception & e) { return 1; } + std::cout << myClass.getValue() << std::endl; + return 0; } @@ -53,6 +74,14 @@ Now program can be compiled & run using following commands: $ g++ -std=c++11 example.cpp $ ./a.out -h Help information + Value from MyClass: Default + + $ ./a.out someArg + Value from MyClass: someArg + + $ ./a.out someArg -h + Help information + Value from MyClass: someArg ### Possible classes to use: -- 2.30.2