Remove mkIntFlag

This commit is contained in:
Eelco Dolstra 2021-01-08 10:44:55 +01:00
parent 920e6a6920
commit 48a9be2aab
2 changed files with 24 additions and 12 deletions

View file

@ -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. */
@ -161,15 +174,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)

View file

@ -20,6 +20,7 @@ struct CmdVerify : StorePathsCommand
{
mkFlag(0, "no-contents", "do not verify the contents of each store path", &noContents);
mkFlag(0, "no-trust", "do not verify whether each store path is trusted", &noTrust);
addFlag({
.longName = "substituter",
.shortName = 's',
@ -27,7 +28,14 @@ struct CmdVerify : StorePathsCommand
.labels = {"store-uri"},
.handler = {[&](std::string s) { substituterUris.push_back(s); }}
});
mkIntFlag('n', "sigs-needed", "require that each path has at least N valid signatures", &sigsNeeded);
addFlag({
.longName = "sigs-needed",
.shortName = 'n',
.description = "require that each path has at least N valid signatures",
.labels = {"n"},
.handler = {&sigsNeeded}
});
}
std::string description() override