diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index 839158b..952dfeb 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -980,7 +980,7 @@ void ArgumentParser::invokeCallbacks(const ArgumentVector &args) // invoke the callback for each occurance of the argument if(arg->m_callbackFunction) { for(const auto &occurance : arg->m_occurances) { - arg->m_callbackFunction(occurance.values); + arg->m_callbackFunction(occurance); } } // invoke the callbacks for sub arguments recursively @@ -1000,7 +1000,7 @@ void ArgumentParser::invokeCallbacks(const ArgumentVector &args) HelpArgument::HelpArgument(ArgumentParser &parser) : Argument("help", 'h', "shows this information") { - setCallback([&parser] (const std::vector &) { + setCallback([&parser] (const ArgumentOccurance &) { CMD_UTILS_START_CONSOLE; parser.printHelp(cout); }); diff --git a/application/argumentparser.h b/application/argumentparser.h index 532c89a..437c2c9 100644 --- a/application/argumentparser.h +++ b/application/argumentparser.h @@ -96,7 +96,7 @@ class LIB_EXPORT Argument friend class ArgumentParser; public: - typedef std::function &)> CallbackFunction; + typedef std::function CallbackFunction; Argument(const char *name, char abbreviation = '\0', const char *description = nullptr, const char *example = nullptr); ~Argument(); diff --git a/tests/argumentparsertests.cpp b/tests/argumentparsertests.cpp index e189085..61402f1 100644 --- a/tests/argumentparsertests.cpp +++ b/tests/argumentparsertests.cpp @@ -299,10 +299,12 @@ void ArgumentParserTests::testCallbacks() ArgumentParser parser; Argument callbackArg("with-callback", 't', "callback test"); callbackArg.setRequiredValueCount(2); - callbackArg.setCallback([] (const vector &values) { - CPPUNIT_ASSERT(values.size() == 2); - CPPUNIT_ASSERT(!strcmp(values[0], "val1")); - CPPUNIT_ASSERT(!strcmp(values[1], "val2")); + callbackArg.setCallback([] (const ArgumentOccurance &occurance) { + CPPUNIT_ASSERT_EQUAL(static_cast(0), occurance.index); + CPPUNIT_ASSERT(occurance.path.empty()); + CPPUNIT_ASSERT_EQUAL(static_cast(2), occurance.values.size()); + CPPUNIT_ASSERT(!strcmp(occurance.values[0], "val1")); + CPPUNIT_ASSERT(!strcmp(occurance.values[1], "val2")); throw 42; }); Argument noCallbackArg("no-callback", 'l', "callback test");