util: split getopt error handling into utility function
This commit is contained in:
parent
d8e267d5ba
commit
7a9866a4e2
2 changed files with 13 additions and 14 deletions
17
util.d
17
util.d
|
@ -1,7 +1,6 @@
|
|||
module util;
|
||||
|
||||
import std.getopt : GetOptException;
|
||||
import std.stdio : File;
|
||||
import std.stdio : File;
|
||||
|
||||
public @safe:
|
||||
|
||||
|
@ -42,12 +41,20 @@ enforceDie(A...)(bool cond, string fmt, A a)
|
|||
die(format(fmt, a));
|
||||
}
|
||||
|
||||
string
|
||||
extractFlag(in GetOptException e)
|
||||
void
|
||||
handleOptError(in string msg)
|
||||
{
|
||||
import std.algorithm : startsWith;
|
||||
import std.regex : matchFirst;
|
||||
|
||||
return e.msg.matchFirst("-.")[0];
|
||||
string opt = msg.matchFirst("-.")[0];
|
||||
|
||||
enforceDie(!msg.startsWith("Unrecognized option"),
|
||||
"unknown option " ~ opt);
|
||||
enforceDie(!msg.startsWith("Missing value for argument"),
|
||||
"missing argument for option " ~ opt);
|
||||
|
||||
die(msg); /* catch-all */
|
||||
}
|
||||
|
||||
string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue