From 6f0c4c39133e08c05ffb1f1d53141a7e80ba6351 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 3 May 2013 12:40:20 +0300 Subject: [PATCH] Restore the check that list options must take an argument --- source/core/getopt.cpp | 2 ++ source/core/getopt.h | 5 +++++ 2 files changed, 7 insertions(+) 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) -- 2.45.2