Skip to content

Commit

Permalink
Make Group.Description mutate its argument again
Browse files Browse the repository at this point in the history
This makes it consistent with other UDA-building functions.

Note that `auto ref` is not required when a function does not modify its
argument. In fact, it is even harmful because it causes separate
template instantiations for `T` and `ref T`.
  • Loading branch information
SirNickolas committed Nov 27, 2023
1 parent 4ed3e86 commit 81e987f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions source/argparse/api/argument.d
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ unittest

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

auto AllowNoValue(alias valueToUse, T)(auto ref ArgumentUDA!T uda)
auto AllowNoValue(alias valueToUse, T)(ArgumentUDA!T uda)
{
return uda.ActionNoValue!(() => valueToUse);
}

auto RequireNoValue(alias valueToUse, T)(auto ref ArgumentUDA!T uda)
auto RequireNoValue(alias valueToUse, T)(ArgumentUDA!T uda)
{
auto desc = uda.AllowNoValue!valueToUse;
desc.info.minValuesCount = 0;
Expand Down Expand Up @@ -212,12 +212,12 @@ unittest
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Parsing customization

auto PreValidation(alias func, T)(auto ref ArgumentUDA!T uda)
auto PreValidation(alias func, T)(ArgumentUDA!T uda)
{
return ArgumentUDA!(uda.parsingFunc.changePreValidation!func)(uda.tupleof);
}

auto Parse(alias func, T)(auto ref ArgumentUDA!T uda)
auto Parse(alias func, T)(ArgumentUDA!T uda)
{
auto desc = ArgumentUDA!(uda.parsingFunc.changeParse!func)(uda.tupleof);

Expand All @@ -232,17 +232,17 @@ auto Parse(alias func, T)(auto ref ArgumentUDA!T uda)
return desc;
}

auto Validation(alias func, T)(auto ref ArgumentUDA!T uda)
auto Validation(alias func, T)(ArgumentUDA!T uda)
{
return ArgumentUDA!(uda.parsingFunc.changeValidation!func)(uda.tupleof);
}

auto Action(alias func, T)(auto ref ArgumentUDA!T uda)
auto Action(alias func, T)(ArgumentUDA!T uda)
{
return ArgumentUDA!(uda.parsingFunc.changeAction!func)(uda.tupleof);
}

auto ActionNoValue(alias func, T)(auto ref ArgumentUDA!T uda)
auto ActionNoValue(alias func, T)(ArgumentUDA!T uda)
{
auto desc = ArgumentUDA!(uda.parsingFunc.changeNoValueAction!func)(uda.tupleof);
desc.info.minValuesCount = 0;
Expand Down Expand Up @@ -333,7 +333,7 @@ private struct CounterParsingFunction
}
}

auto Counter(T)(auto ref ArgumentUDA!T uda)
auto Counter(T)(ArgumentUDA!T uda)
{
auto desc = ArgumentUDA!(CounterParsingFunction)(uda.tupleof);
desc.info.minValuesCount = 0;
Expand Down
4 changes: 2 additions & 2 deletions source/argparse/api/argumentgroup.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ auto ArgumentGroup(string name)
return Group(name);
}

auto Description(Group group, string text)
auto ref Description()(auto ref Group group, string text)
{
group.description = text;
return group;
}

auto Description(Group group, string delegate() text)
auto ref Description()(auto ref Group group, string delegate() text)
{
group.description = text;
return group;
Expand Down
16 changes: 8 additions & 8 deletions source/argparse/api/command.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ unittest
}


auto ref Usage(T : CommandInfo)(auto ref T cmd, string text)
auto ref Usage()(auto ref CommandInfo cmd, string text)
{
cmd.usage = text;
return cmd;
}

auto ref Usage(T : CommandInfo)(auto ref T cmd, string delegate() text)
auto ref Usage()(auto ref CommandInfo cmd, string delegate() text)
{
cmd.usage = text;
return cmd;
}

auto ref Description(T : CommandInfo)(auto ref T cmd, string text)
auto ref Description()(auto ref CommandInfo cmd, string text)
{
cmd.description = text;
return cmd;
}

auto ref Description(T : CommandInfo)(auto ref T cmd, string delegate() text)
auto ref Description()(auto ref CommandInfo cmd, string delegate() text)
{
cmd.description = text;
return cmd;
}

auto ref ShortDescription(T : CommandInfo)(auto ref T cmd, string text)
auto ref ShortDescription()(auto ref CommandInfo cmd, string text)
{
cmd.shortDescription = text;
return cmd;
}

auto ref ShortDescription(T : CommandInfo)(auto ref T cmd, string delegate() text)
auto ref ShortDescription()(auto ref CommandInfo cmd, string delegate() text)
{
cmd.shortDescription = text;
return cmd;
}

auto ref Epilog(T : CommandInfo)(auto ref T cmd, string text)
auto ref Epilog()(auto ref CommandInfo cmd, string text)
{
cmd.epilog = text;
return cmd;
}

auto ref Epilog(T : CommandInfo)(auto ref T cmd, string delegate() text)
auto ref Epilog()(auto ref CommandInfo cmd, string delegate() text)
{
cmd.epilog = text;
return cmd;
Expand Down
2 changes: 1 addition & 1 deletion source/argparse/api/restriction.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import std.conv: to;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Required group

auto ref Required(T : RestrictionGroup)(auto ref T group)
auto ref Required()(auto ref RestrictionGroup group)
{
group.required = true;
return group;
Expand Down

0 comments on commit 81e987f

Please sign in to comment.