From: Mikko Rasa Date: Fri, 3 May 2013 09:40:20 +0000 (+0300) Subject: Restore the check that list options must take an argument X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6f0c4c39133e08c05ffb1f1d53141a7e80ba6351;p=libs%2Fcore.git Restore the check that list options must take an argument --- diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index e909712..fdeb2f8 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -21,6 +21,8 @@ GetOpt::OptionImpl &GetOpt::add_option(char s, const string &l, const Store &t, { if(l.empty()) throw invalid_argument("GetOpt::add_option"); + if(t.is_list() && a!=REQUIRED_ARG) + throw invalid_argument("GetOpt::add_option"); for(OptionList::iterator i=opts.begin(); i!=opts.end(); ) { diff --git a/source/core/getopt.h b/source/core/getopt.h index 911934a..70841cb 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -88,6 +88,7 @@ private: virtual Store *clone() const = 0; + virtual bool is_list() const = 0; virtual void store() = 0; virtual void store(const std::string &) = 0; }; @@ -133,6 +134,8 @@ private: virtual SimpleStore *clone() const { return new SimpleStore(data); } + virtual bool is_list() const { return false; } + virtual void store() { } virtual void store(const std::string &a) @@ -151,6 +154,8 @@ private: virtual ListStore *clone() const { return new ListStore(data); } + virtual bool is_list() const { return true; } + virtual void store() { } virtual void store(const std::string &a)