aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-01-08 10:44:55 +0100
committerEelco Dolstra <edolstra@gmail.com>2021-01-08 10:44:55 +0100
commit48a9be2aabf6620ceb00caf7c4c917e4e0a81446 (patch)
tree103da98df2372ade90a17cec96416682f8189326 /src/libutil
parent920e6a6920fa0ae82150bb2b0c210a03ccf5919b (diff)
Remove mkIntFlag
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/args.hh26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index 6ed541a32..3e84ac64a 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -68,8 +68,12 @@ protected:
, arity(ArityAny)
{ }
- template<class T>
- Handler(T * dest)
+ Handler(std::string * dest)
+ : fun([=](std::vector<std::string> ss) { *dest = ss[0]; })
+ , arity(1)
+ { }
+
+ Handler(std::optional<std::string> * dest)
: fun([=](std::vector<std::string> ss) { *dest = ss[0]; })
, arity(1)
{ }
@@ -79,6 +83,15 @@ protected:
: fun([=](std::vector<std::string> ss) { *dest = val; })
, arity(0)
{ }
+
+ template<class I>
+ Handler(I * dest)
+ : fun([=](std::vector<std::string> ss) {
+ if (!string2Int(ss[0], *dest))
+ throw UsageError("'%s' is not an integer", ss[0]);
+ })
+ , arity(1)
+ { }
};
/* Flags. */
@@ -162,15 +175,6 @@ public:
}
template<class I>
- void mkIntFlag(char shortName, const std::string & longName,
- const std::string & description, I * dest)
- {
- mkFlag<I>(shortName, longName, description, [=](I n) {
- *dest = n;
- });
- }
-
- template<class I>
void mkFlag(char shortName, const std::string & longName,
const std::string & description, std::function<void(I)> fun)
{