fix Issue 13317 - std.getopt: endOfOptions broken when it doesn't look like an option

This commit is contained in:
Nils Boßung 2014-08-18 01:14:40 +02:00
parent 9c10c24220
commit c40fd397c6

View file

@ -582,6 +582,12 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
for (size_t i = 1; i < args.length;)
{
auto a = args[i];
if (endOfOptions.length && a == endOfOptions)
{
// Consume the "--"
args = args.remove(i);
break;
}
if (!a.length || a[0] != optionChar)
{
// not an option
@ -589,12 +595,6 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
++i;
continue;
}
if (endOfOptions.length && a == endOfOptions)
{
// Consume the "--"
args = args.remove(i);
break;
}
if (a == "--help" || a == "-h")
{
rslt.helpWanted = true;
@ -1304,6 +1304,19 @@ unittest
assert(args == ["program", "nonoption", "--option"]);
}
// Issue 13317 - std.getopt: endOfOptions broken when it doesn't look like an option
unittest
{
auto endOfOptionsBackup = endOfOptions;
scope(exit) endOfOptions = endOfOptionsBackup;
endOfOptions = "endofoptions";
string[] args = ["program", "endofoptions", "--option"];
bool b = false;
getopt(args, "option", &b);
assert(!b);
assert(args == ["program", "--option"]);
}
/** This function prints the passed $(D Option) and text in an aligned manner.
The passed text will be printed first, followed by a newline. Than the short