argparse version 1.0.0

Vladimir Panteleev thecybershadow.lists at gmail.com
Fri Jun 10 14:20:15 UTC 2022


On Friday, 10 June 2022 at 14:14:27 UTC, Andrey Zherikov wrote:
> On Friday, 10 June 2022 at 09:20:24 UTC, Vladimir Panteleev 
> wrote:
>> Congratulations on the release. Though there's a good number 
>> of libraries for this task in D already, this solution looks 
>> very complete.
>
> I looked at them when I started this project and they didn't 
> provide complete set of features I was looking for. That was 
> the main reason to start this work.

I invoke https://xkcd.com/927/ ! :)

>> I was wondering if you ran into any strong reasons for 
>> describing the arguments as a struct, rather than, well, 
>> function arguments. I have had good success so far with the 
>> latter, which has the benefit of being succinct:
>>
>> https://github.com/CyberShadow/btdu/blob/116d190079ca77d61383eb738defa4318d5a1e5f/source/btdu/main.d#L59
>
> This is an interesting approach. I think they are equivalent 
> for simple cases but how would you model subcommands with 
> common arguments for all of them?

Glad you asked! I use an approach similar to the one here, with 
commands in a struct. The common arguments are parsed before 
invoking the command.

https://github.com/CyberShadow/steamkeyactivator/blob/144d322ecee65f4f536e5fd4141837e51d61a27a/activator.d#L142

When only some commands need to share some arguments, you can put 
them in a tuple.

https://github.com/CyberShadow/Digger/blob/7c7dd167aea2214d594bab932ea4e41e5f0a357a/digger.d#L34



More information about the Digitalmars-d-announce mailing list