New library: argparse, for parsing CLI arguments
Steven Schveighoffer
schveiguy at gmail.com
Tue Oct 19 14:57:56 UTC 2021
On 10/19/21 10:36 AM, Andrey Zherikov wrote:
> On Tuesday, 19 October 2021 at 14:06:21 UTC, Steven Schveighoffer wrote:
>> Just nitpicks. Like allowing `@NamedArgument` without parentheses. Or
>> using `@NamedArgument("b", "banana", "ban")` instead of
>> `@NamedArgument(["b", "banana", "ban"])`
>
> I did array because I think it makes sense to have
> `@NamedArgument(names, help_text)` as a shortcut for
> `@(NamedArgument(names).HelpText(help_text))` for CLI.
Just going to put this here, instead of a PR, but if you change your
parameter type to:
```d
NamedArgument(string[] names...);
```
Now, these all work:
```d
NamedArgument("banana")
NamedArgument("b", "banana", "ban")
NamedArgument(["b", "banana", "ban"])
```
If you want to support an array + extra string, then you can add:
```d
NamedArgument(string[] names, string helptext);
```
And it shouldn't conflict with the first overload.
Though, I like the explicit HelpText better (that's what I'd use, even
if the convenient overload is there). UDAs that don't spell out what
they are for are harder to review.
-Steve
More information about the Digitalmars-d-announce
mailing list