--- /dev/null
+#ifndef __COMMAND_EXCEPTION_OPTION_VALUE_NOT_SPECIFIED_H
+#define __COMMAND_EXCEPTION_OPTION_VALUE_NOT_SPECIFIED_H
+
+#include <stdexcept>
+#include <string>
+
+namespace command {
+
+/**
+ * Exception thrown when Option should have value, but no equal sign specifying
+ * it has been set
+ */
+class OptionValueNotSpecified : public std::invalid_argument {
+public:
+ /** \inheritdoc */
+ explicit OptionValueNotSpecified(const std::string& what_arg) :
+ std::invalid_argument(what_arg) { }
+
+ /** \inheritdoc */
+ explicit OptionValueNotSpecified(const char* what_arg) :
+ std::invalid_argument(what_arg) { }
+};
+
+}
+
+#endif /* __COMMAND_EXCEPTION_OPTION_VALUE_NOT_SPECIFIED_H */
#include "parameter.h"
#include "exception/missingOptionValue.h"
#include "exception/optionFailedConversion.h"
+#include "exception/optionValueNotSpecified.h"
namespace command {
/**
virtual bool understand(const std::string & argv) {
if (argv.find(name) == 0) {
- std::size_t pos = argv.find("=");
+ std::size_t pos = this->valuePosition(argv);
if (pos != name.size()) {
throw MissingOptionValue("Option: " + name + " requires value but no one has been provided");
/**
* \inheritdoc
*/
- virtual unsigned int valuePosition(const std::string & argv) {
- return argv.find("=");
+ virtual unsigned int valuePosition(const std::string & value) {
+ std::size_t pos = value.find("=");
+
+ if (pos == std::string::npos) {
+ throw OptionValueNotSpecified("Option: " + name + " requires value to be specified using equal sign");
+ }
+
+ return pos;
}
};
* \inheritdoc
*/
virtual unsigned int valuePosition(const std::string & ) {
- throw new std::invalid_argument(this->describe() + "is void Option, so it does not have value part");
+ throw new std::invalid_argument(this->describe() + " is void Option, so it does not have value part");
}
};
}