The D Scripting Language
Tomek Sowiński
just at ask.me
Wed Nov 10 15:58:31 PST 2010
Andrei Alexandrescu napisał:
>> Speaking of getopt, when writing the 'grep' snippet I missed anonymous
>> options a lot:
>>
>> bool h, i; string expr; string[] files;
>> getopt(args, "h",&h, "i",&i,&expr,&files);
>>
>> They can be implemented with relatively little effort.
>
> Not getting the example. How would anonymous options work?
// Let's match assignments.
auto args = ["program.exe", ".*=.*;", "file1.d", "file2.d", "file3.d"];
bool h, i; string expr; string[] files;
getopt(args, "h",&h, "i",&i, &expr, &files);
assert(!h);
assert(!i);
assert(expr == ".*=.*;");
assert(files == ["file1.d", "file2.d", "file3.d"]);
assert(args == ["program.exe"]);
Staying conservative, anonymous options would only be allowed at the end of the
option list, because their order matters (unlike named options). Perhaps this can
be relaxed with time.
--
Tomek
More information about the Digitalmars-d
mailing list