Command line parsing

Vladimir Panteleev via Digitalmars-d digitalmars-d at puremagic.com
Sun May 15 16:36:27 PDT 2016


On Sunday, 15 May 2016 at 18:26:21 UTC, Andrei Alexandrescu wrote:
> On 5/14/16 4:40 PM, Jason White wrote:
>> On Saturday, 14 May 2016 at 04:34:06 UTC, Andrei Alexandrescu 
>> wrote:
>>> On 5/13/16 2:27 PM, Russel Winder via Digitalmars-d wrote:
>>>> On Thu, 2016-05-12 at 18:25 +0000, Jesse Phillips via 
>>>> Digitalmars-d
>>>> wrote:
>>>> […]
>>>>> unknown flags harder and displaying help challenging. So 
>>>>> I'd like
>>>>> to see getopt merge with another getopt
>>>>
>>>> getopt is a 1970s C solution to the problem of command line 
>>>> parsing.
>>>> Most programming languages have moved on from getopt and 
>>>> created
>>>> language-idiomatic solutions to the problem. Indeed there 
>>>> are other,
>>>> better solution in C now as well.
>>>
>>> What are those and how are they better? -- Andrei
>>
>> I wrote what I think is an idiomatic-D command line argument 
>> parser:
>>
>>      https://github.com/jasonwhite/darg
>>
>> You basically define a struct with your options as members. 
>> The help
>> string is then created at compile time(!). I find this much 
>> cleaner than
>> std.getopt and the usage/help is prettier.
>
> This is a terrific use of properties and it's a bit of a bummer 
> std.getopt predates them. Thanks for an inspirational package. 
> We should integrate some of these ideas in std.getopt and 
> beyond.
>
> One simple step up for your package would be to do away with 
> the enclosing struct - it can stay optional, but there's no 
> real need for it.

I'm not sure if you saw it, but funopt uses the same basic idea.

When writing ae.utils.funopt, I debated for a bit whether I 
should use a struct or a function signature as the base for 
specifying the arguments and their documentation. In the end I 
went with a function, because it covered all the most important 
cases, was simpler to use, and closer follows the analogy of 
invoking a process with some arguments vs. calling a function 
with some arguments.



More information about the Digitalmars-d mailing list