getopt & single-letter options with parameters

SK sk at metrokings.com
Sat Aug 7 20:08:26 PDT 2010



On Aug 7, 2010, at 4:22 PM, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org 
 > wrote:

> On 08/07/2010 05:55 PM, Adrian Matoga wrote:
>> Hi,
>>
>> Is it by design that single-letter option needs to be glued to its
>> argument, like "-ofilename", or is it a bug in implementation?
>>
>> Source:
>>
>> import std.stdio;
>> import std.getopt;
>>
>> void main(string[] args)
>> {
>> string outputFile;
>> getopt(args,
>> config.passThrough,
>> "o|output-filename", &outputFile);
>> writeln(args);
>> writeln("'" ~ outputFile ~ "'");
>> }
>>
>>
>>
>> Results:
>> >test.exe -o somename
>> test.exe somename
>> ''
>>
>> >test.exe -osomename
>> test.exe
>> 'somename'
>>
>> Regards,
>> Adrian Matoga
>
> It's by design in order to avoid confusion with parameterless  
> options. Your example works with either of these invocations:
>
> ./prog -ofilename
> ./prog -o=filename
> ./prog --o=filename
>
> but not others.
>
>
> Andrei
>

The prevailing convention is to allow whitespace in this case.  Would  
you reconsider?

Sorry for the accidental null post earlier.

-steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100807/1750da22/attachment.html>


More information about the Digitalmars-d mailing list