mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
fix Issue 13317 - std.getopt: endOfOptions broken when it doesn't look like an option
This commit is contained in:
parent
9c10c24220
commit
c40fd397c6
1 changed files with 19 additions and 6 deletions
25
std/getopt.d
25
std/getopt.d
|
@ -582,6 +582,12 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
|
||||||
for (size_t i = 1; i < args.length;)
|
for (size_t i = 1; i < args.length;)
|
||||||
{
|
{
|
||||||
auto a = args[i];
|
auto a = args[i];
|
||||||
|
if (endOfOptions.length && a == endOfOptions)
|
||||||
|
{
|
||||||
|
// Consume the "--"
|
||||||
|
args = args.remove(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!a.length || a[0] != optionChar)
|
if (!a.length || a[0] != optionChar)
|
||||||
{
|
{
|
||||||
// not an option
|
// not an option
|
||||||
|
@ -589,12 +595,6 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
|
||||||
++i;
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (endOfOptions.length && a == endOfOptions)
|
|
||||||
{
|
|
||||||
// Consume the "--"
|
|
||||||
args = args.remove(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (a == "--help" || a == "-h")
|
if (a == "--help" || a == "-h")
|
||||||
{
|
{
|
||||||
rslt.helpWanted = true;
|
rslt.helpWanted = true;
|
||||||
|
@ -1304,6 +1304,19 @@ unittest
|
||||||
assert(args == ["program", "nonoption", "--option"]);
|
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.
|
/** 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
|
The passed text will be printed first, followed by a newline. Than the short
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue